I’ve made a asp.net page that creates an Excel workbook. I have set the orientation scaling property of the page setup height and width of the workbook like so:
DocumentFormat.OpenXml.Spreadsheet.PageSetup pgOr = new DocumentFormat.OpenXml.Spreadsheet.PageSetup();
pgOr.Orientation = OrientationValues.Landscape;
pgOr.FitToHeight = 3;
pgOr.FitToWidth = 1;
newWorksheetPart.Worksheet.AppendChild(pgOr);
However, when you download the Excel document and open the PageSetup scaling has been set to 1 page wide and 3 pages tall which is what I want but the “Fit to” radio button isn’t selected so it’s not actually using these setting.
I figured there is some property I need to set to true along the way. Like a FitToPage or something the thing is that I don’t know which one. Anyone know?
NOTE: Please keep in mind that I am using DocumentFormat.OpenXml and not Microsoft.Office.Interop.Excel.
The OpenXML SDK provides a class called
PageSetupPropertieswhich provides a property calledFitToPage.Set this property to
truein order to get the radio button selected: