I have this code to set various print options:
private void ConfigureByCustomerForPrinting()
{
_xlSheet.PageSetup.PrintArea = "A1:" +
GetExcelTextColumnName(
_xlSheet.UsedRange.Columns.Count) +
_xlSheet.UsedRange.Rows.Count;
_xlSheet.PageSetup.Orientation = Excel.XlPageOrientation.xlLandscape;
_xlSheet.PageSetup.FitToPagesWide = 1;
_xlSheet.PageSetup.FitToPagesTall = 100;
_xlSheet.PageSetup.Zoom = false;
_xlSheet.PageSetup.LeftMargin = _xlApp.Application.InchesToPoints(0.5);
_xlSheet.PageSetup.RightMargin = _xlApp.Application.InchesToPoints(0.5);
_xlSheet.PageSetup.TopMargin = _xlApp.Application.InchesToPoints(0.5);
_xlSheet.PageSetup.BottomMargin = _xlApp.Application.InchesToPoints(0.5);
_xlSheet.PageSetup.HeaderMargin = _xlApp.Application.InchesToPoints(0.5);
_xlSheet.PageSetup.FooterMargin = _xlApp.Application.InchesToPoints(0.5);
}
When the sheet is generated, it respects the landscape orientation value but, as can be seen below:
...although width (wide) and height (tall) are set to 1 and 100, respectively, that is not the radio button selected. Instead, "Adjust to - % normal size" is set and selected. Why? I reckon this is probably fine, but the user wants it set to 1 and 100.
You need to set Zoom
property to false
before sets FitToPagesWide
and FitToPagesTall
:
_xlSheet.PageSetup.Zoom = false;
_xlSheet.PageSetup.FitToPagesWide = 1;
_xlSheet.PageSetup.FitToPagesTall = 100;
From MSDN:
If the Zoom property is True, the FitToPagesWide property is ignored.
If the Zoom property is True, the FitToPagesTall property is ignored.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.