We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Why are my Print options not sticking?

I've got this code to set margins for printing of the spreadsheet:

private void ConfigureForPrinting(int finalRow)
string lastColumn = GetExcelTextColumnName(pivotTableSheet.Cells.Columns.Count);
string printArea = String.Format("A1:{0}{1}", lastColumn, finalRow);
pivotTableSheet.PageSetup.PrintArea = printArea;
pivotTableSheet.PageSetup.Orientation = PageOrientationType.Landscape;

// I don't know if this does anything; I would like to set it to 54%...
pivotTableSheet.PageSetup.IsPercentScale = true;

pivotTableSheet.PageSetup.Zoom = 100;
pivotTableSheet.PageSetup.FitToPagesWide = 5;
pivotTableSheet.PageSetup.FitToPagesTall = 50;

// "...with 1/2" margins"
pivotTableSheet.PageSetup.LeftMargin = 0.5;
pivotTableSheet.PageSetup.RightMargin = 0.5;
pivotTableSheet.PageSetup.TopMargin = 0.5;
pivotTableSheet.PageSetup.BottomMargin = 0.5;
pivotTableSheet.PageSetup.HeaderMargin = 0.5;
pivotTableSheet.PageSetup.FooterMargin = 0.5;

// Repeat rows
string repeatableRowRange = "$6:$7";
pivotTableSheet.PageSetup.PrintTitleRows = repeatableRowRange;
string repeatableColRange = string.Format("$A:${0}", lastColumn);
pivotTableSheet.PageSetup.PrintTitleColumns = repeatableColRange;

Yet, when the spreadsheet is generated, those values are not used, as can be seen in the screenshot.

Why not? And what can I do to make the margins what they should be (0.5)?

Okay, setting HeaderMargin and FooterMargin to 0 worked; in the Print Preview, those margins were set to that (0).

However, setting the margins to to 0.5 resulted in them being set to 0.196

So, I thought maybe I could do some extrapolation, like so:

pivotTableSheet.PageSetup.LeftMargin = 0.5*2.55;
pivotTableSheet.PageSetup.RightMargin = 0.5 * 2.55;
pivotTableSheet.PageSetup.TopMargin = 0.5 * 2.55;
pivotTableSheet.PageSetup.BottomMargin = 0.5 * 2.55;
pivotTableSheet.PageSetup.HeaderMargin = 0;
pivotTableSheet.PageSetup.FooterMargin = 0;

...and it works; the "0.5*2.55" does equate to 0.5 - but why? Why is this crookedforwardness necessary?

Hi Clay,

Thank you for contacting Aspose support.

As per my understanding of the scenario, the issue seems to be caused due to the mismatch of the units. Please note, PageSetup.LeftMargin is in the unit of centimeters whereas the unit in Excel application’s Page Setup depends on the locale of the machine. As per the provided resolution, it appears that you have the Excel where unit is set to inches because 1 inch equals to 2.54 centimeters.

Thanks; I will change my constant from 2.55 to 2.54

Hi again,

Yes, it will be accurate to store the constant as 2.54. Please feel to contact us back in case you need any further assistance with Aspose APIs.