How do I create horizontal rule in Word with open XML SDK?
Open XML SDK 2.0, using C# 4.5
I'm looking for some kind of paragraph.append(new HorizontalRule()) command, but can't seem to find anything.
As suggested, the reflected code generator provides the answer:
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Wordprocessing;
...
Paragraph newParagraph = new Paragraph();
ParagraphProperties paraProperties = new ParagraphProperties();
ParagraphBorders paraBorders = new ParagraphBorders();
BottomBorder bottom = new BottomBorder() { Val = BorderValues.Single, Color = "auto", Size = (UInt32Value)12U, Space = (UInt32Value)1U };
paraBorders.Append(bottom);
paraProperties.Append(paraBorders);
newParagraph.Append(paraProperties);
The "Productivity Tools for Microsoft Office" (part of the Open XML SDK 2.0) come with a feature called "Reflected Code" to generate the .NET code out of an existing document which actually generates this exact document.
I suggest you format what you need in Word, use this tool and have a look at the .NET code how it's done.
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