I am trying to set the page margins on an excel spreadsheet that is being generated by open xml sdk. I am not opening an excel document that already exists, it is generated from scratch. I am using the PageMargins class but am not sure how to attach this instance to the worksheet. The SDK productivity tool gives this code:
PageMargins pageMargins1 = worksheet.GetFirstChild<PageMargins>();
pageMargins1.Left = 0.45D;
pageMargins1.Right = 0.45D;
pageMargins1.Top = 0.5D;
pageMargins1.Bottom = 0.5D;
The GetFirstChild() function returns null. I also tried to do
worksheet.Append(pageMargins1);
but no luck.
Also using the code from this example: How change excel 2007 document orientation to landscape by OpenXML sdk to set the page orientation does not work if creating the document from scratch. How do you add a PageSetup & PageMargin instance to the document?
Any one have knowledge of this SDK and knows how to use the margins or page setup class?