Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create horizontal rule in Word with open XML SDK? [closed]

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.

like image 716
BurnsBA Avatar asked Oct 24 '25 11:10

BurnsBA


2 Answers

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);
like image 71
BurnsBA Avatar answered Oct 26 '25 02:10

BurnsBA


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.

like image 38
Martin Buberl Avatar answered Oct 26 '25 02:10

Martin Buberl