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.
Thanks
The Open XML SDK provides tools for working with Office Word, Excel, and PowerPoint documents. It supports scenarios such as: - High-performance generation of word-processing documents, spreadsheets, and presentations. - Populating content in Word files from an XML data source.
The content of the paragraph is contained in one or more runs (<w:r>). Runs are non-block content; they define regions of text that do not necessarily begin on a new line. Like paragraphs, they are comprised of formatting/property definitions, followed by content.
No. You only need to have a reference to the library that provides all the OpenXML functionality. That library is not dependant on Office. OpenXML will only handle the new file formats, not the old DOC and DOT.
Go to your Solution Explorer > right click on references and then click Manage NuGet Packages . Then search in tab "Online" for DocumentFormat. OpenXml and install it. After you can use DocumentFormat.
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>
If you're using the OpenXml SDK, you can use
new Paragraph( new Run( new Break(){ Type = BreakValues.Page }));
EDIT:
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")));
The PageBreakBefore property accomplishes this. It will insert a page break before your paragraph if Word didn't insert one automatically.
if (myParagraph.ParagraphProperties== null) { myParagraph.ParagraphProperties = new ParagraphProperties(); } myParagraph.ParagraphProperties.PageBreakBefore = new PageBreakBefore();
I believe it looks something like this in Open XML:
<w:p> <w:pPr> ... <w:pageBreakBefore/> ... </w:pPr> ... </w:p>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With