Learn how to a build a cloud-first strategyRegister Now


OpenXML - Docx document left indent/margin

Posted on 2011-04-28
Medium Priority
Last Modified: 2012-05-11

I use OpenXML to generate a word document in SharePoint.

I need to set indentation of my word document, mainly the left and right margins are too wide so I want to shrink it down, but I can't seem to find the function for it. I could only set the left and right margin of a TABLE, but not the whole word document. It's so simple in Word because you can choose margins of Normal, Narrow, Wide, etc.
Attached is a sample of margins for a TABLE.
Is there one for the document?
TableCellMarginDefault margin = new TableCellMarginDefault(); 
margin.TopMargin = new TopMargin { Width = 0, Type = TableWidthUnitValues.Dxa };
margin.BottomMargin = new BottomMargin { Width = 0, Type = TableWidthUnitValues.Dxa };
margin.TableCellLeftMargin = new TableCellLeftMargin { Width = 50, Type = TableWidthValues.Dxa };
margin.TableCellRightMargin = new TableCellRightMargin { Width = 50, Type = TableWidthValues.Dxa };

Open in new window

Question by:SOS_Helpdesk
LVL 17

Accepted Solution

andrewssd3 earned 2000 total points
ID: 37091614
In the Word object model, you would set the margins for the whole document using the pagesetup object - this has the topmargin, bottommargin etc properties.

I think in OpenXML it's the PageMargin object you need - this snippet generated by the OpenXML SDK illustrates creating one and appending it to the Section:
           SectionProperties sectionProperties1 = new SectionProperties() { RsidR = "00FC093D", RsidSect = "00240B4C" };
            PageSize pageSize1 = new PageSize() { Width = (UInt32Value)16839U, Height = (UInt32Value)11907U, Orient = PageOrientationValues.Landscape, Code = (UInt16Value)9U };
            PageMargin pageMargin1 = new PageMargin() { Top = 406, Right = (UInt32Value)567U, Bottom = 426, Left = (UInt32Value)426U, Header = (UInt32Value)285U, Footer = (UInt32Value)708U, Gutter = (UInt32Value)0U };
            Columns columns1 = new Columns() { Space = "708" };
            DocGrid docGrid1 = new DocGrid() { LinePitch = 360 };


Open in new window


Author Closing Comment

ID: 37094110

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question