1

aspx ページから、OpenXml SDK を使用して Word 文書に段落を動的に追加します。この場合、段落内の改ページは許可されません。そのため、段落がページ 1 の途中から始まり、ページ 2 まで続く場合、実際にはページ 2 で開始する必要があります。ただし、同じページで終了する場合は問題ありません。

これを達成する方法は?段落内で改ページが許可されていないことをドキュメントに設定する方法はありますか? どんな入力でも大歓迎です。

4

1 に答える 1

2

一般に、open xml sdk を使用して要素がページ内のどこに表示されるかを判断することはできません。open xml にはページの概念がないためです。

ページは、開いている xml ドキュメントを使用するクライアント アプリケーションによって決定されます。ただし、段落の行をまとめるように指定することはできます。

<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:pPr>
    <w:keepLines />
  </w:pPr>
  <w:bookmarkStart w:name="_GoBack" w:id="0" />
  <w:r>
    <w:lastRenderedPageBreak />
    <w:t>Most controls offer a choice of using the look from the current theme or using     a format that you specify directly. To change the overall look of your document, choose new your document.</w:t>
  </w:r>
  <w:bookmarkEnd w:id="0" />
</w:p>

上記の例の段落プロパティのw:keepLinesは、段落がページ間で分割されないようにするための鍵です。以下は、上記の段落を生成するために必要な開いている xml です。

using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml;

namespace GeneratedCode
{
    public class GeneratedClass
    {
        // Creates an Paragraph instance and adds its children.
        public Paragraph GenerateParagraph()
        {
            Paragraph paragraph1 = new Paragraph();

            ParagraphProperties paragraphProperties1 = new ParagraphProperties();
            KeepLines keepLines1 = new KeepLines();

            paragraphProperties1.Append(keepLines1);
            BookmarkStart bookmarkStart1 = new BookmarkStart(){ Name = "_GoBack", Id = "0" };

            Run run1 = new Run();
            LastRenderedPageBreak lastRenderedPageBreak1 = new LastRenderedPageBreak();
            Text text1 = new Text();
            text1.Text = "Most controls offer a choice of using the look from the current theme or using.";

            run1.Append(lastRenderedPageBreak1);
            run1.Append(text1);
            BookmarkEnd bookmarkEnd1 = new BookmarkEnd(){ Id = "0" };

            paragraph1.Append(paragraphProperties1);
            paragraph1.Append(bookmarkStart1);
            paragraph1.Append(run1);
            paragraph1.Append(bookmarkEnd1);
            return paragraph1;
        }       
    }
}
于 2011-11-18T09:21:39.957 に答える