How to set Excel fields using EPPlus

I need to be able to automatically set the fields (printer settings) of an Excel workbook.
I found this file:

ExcelPrinterSettings.cs

There is a class with the following constructor:

ExcelPrinterSettings(XmlNamespaceManager ns, XmlNode topNode,ExcelWorksheet ws) 

but I don’t know what I need to pass for the first two parameters.
I already had the code that makes the worksheet, so I can pass this as the third parameter.

Thanks so much for any suggestions.

+6
source share
2 answers

I am using epplus with this code to set the printer options in the target excel file:

 ExcelWorksheet ew; ew.PrinterSettings.TopMargin = tartetTopMarginValueInCm / 2.54M; ew.PrinterSettings.RightMargin = targetRightMarginValueInCm / 2.54M; ... ew.PrinterSettings.HeaderMargin = targetHeaderMarginInCm / 2.54M; 

Remember to convert cm to inch (if you want to use cm because all epplus printer settings are in inches).

Screen with Page Setup in Excel and Printer Settings in Epplus:

Page setup in excel vs. epplus settings

+11
source

Same as above with small settings (works 100%)

 ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Demo"); ws.PrinterSettings.TopMargin =(decimal).5 / 2.54M; // narrow border ws.PrinterSettings.RightMargin = (decimal).5 / 2.54M; //narrow border 
+2
source

All Articles