使用OpenXml创建分页符 [英] Create page break using OpenXml
问题描述
我使用OpenXml创建具有简单文本和该文本下的一些表格的Word文档.如何强制带有此文本的段落始终显示在新页面上?也许这一段应该是标题,但我不确定如何做到这一点.
I use OpenXml to create Word document with simple text and some tables under this text. How can I force Paragraph with this text to show always on new page? Maybe this paragraph should be some Header but I'm not sure how to do this.
谢谢
推荐答案
您可以使用<w:br>
元素在Run元素内创建分页符.在原始的OpenXML中,它看起来像:
You can create a page break within a Run element using the <w:br>
element. In raw OpenXML, it would look something like:
<w:p>
<w:r>
<w:br w:type="page" />
</w:r>
</w:p>
如果您使用的是OpenXml SDK,则可以使用
If you're using the OpenXml SDK, you can use
new Paragraph(
new Run(
new Break(){ Type = BreakValues.Page }));
如果您只想指定段落是页面上的最后一个内容,则可以尝试使用<w:lastRenderedPageBreak />
标记.
If you just want to specify that a paragraph is the last thing on a page, you can try the <w:lastRenderedPageBreak />
tag.
new Paragraph(
new Run(
new LastRenderedPageBreak(),
new Text("Last text on the page")));
这篇关于使用OpenXml创建分页符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!