0

Gembox.Documentでテーブルをドキュメントに挿入し、改ページで分割されないようにすることはできますが、前のページに収まらない場合は次のページに移動できますか? サンプルとドキュメントを調べましたが、何も見つかりませんでした。

4

1 に答える 1

1

そのテーブルにある段落のKeepLinesTogetherプロパティKeepWithNextを設定する必要があります。trueたとえば、次のことを試してください。

Table table = ...

foreach (ParagraphFormat paragraphFormat in table
    .GetChildElements(true, ElementType.Paragraph)
    .Cast<Paragraph>()
    .Select(p => p.ParagraphFormat))
{
    paragraphFormat.KeepLinesTogether = true;
    paragraphFormat.KeepWithNext = true;
}

編集
上記はほとんどの場合に機能しますが、Table要素に要素がない空の要素がTableCellある場合に問題が発生する可能性がありParagraphます。

このためには、目的のフォーマットを設定できるように、Paragraphこれらの要素に空の要素を追加する必要があります (出典: Keep Table on same page ):TableCell

// Get all Paragraph formats in a Table element.
IEnumerable<ParagraphFormat> formats = table
    .GetChildElements(true, ElementType.TableCell)
    .Cast<TableCell>()
    .SelectMany(cell =>
    {
        if (cell.Blocks.Count == 0)
            cell.Blocks.Add(new Paragraph(cell.Document));
        return cell.GetChildElements(true, ElementType.Paragraph);
    })
    .Cast<Paragraph>()
    .Select(p => p.ParagraphFormat);

// Set KeepLinesTogether and KeepWithNext properties.
foreach (ParagraphFormat format in formats)
{
    format.KeepLinesTogether = true;
    format.KeepWithNext = true;
}
于 2015-11-10T08:38:44.623 に答える