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)?