为什么设置要打印的页面宽度和高度未应用?
Why does setting the width and height of pages to print not get applied?
我有这个代码来设置各种打印选项:
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);
}
生成 sheet 时,它尊重横向值,但是如下所示:
...虽然宽度(宽)和高度(高)分别设置为 1 和 100,但这不是选中的单选按钮。相反,设置并选择了 "Adjust to - % normal size"。为什么?我认为这可能没问题,但用户希望将其设置为 1 和 100。
您需要在设置 FitToPagesWide
和 FitToPagesTall
之前将 Zoom
属性 设置为 false
:
_xlSheet.PageSetup.Zoom = false;
_xlSheet.PageSetup.FitToPagesWide = 1;
_xlSheet.PageSetup.FitToPagesTall = 100;
来自 MSDN:
If the Zoom property is True, the FitToPagesWide property is ignored.
If the Zoom property is True, the FitToPagesTall property is ignored.
我有这个代码来设置各种打印选项:
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);
}
生成 sheet 时,它尊重横向值,但是如下所示:
...虽然宽度(宽)和高度(高)分别设置为 1 和 100,但这不是选中的单选按钮。相反,设置并选择了 "Adjust to - % normal size"。为什么?我认为这可能没问题,但用户希望将其设置为 1 和 100。
您需要在设置 FitToPagesWide
和 FitToPagesTall
之前将 Zoom
属性 设置为 false
:
_xlSheet.PageSetup.Zoom = false;
_xlSheet.PageSetup.FitToPagesWide = 1;
_xlSheet.PageSetup.FitToPagesTall = 100;
来自 MSDN:
If the Zoom property is True, the FitToPagesWide property is ignored.
If the Zoom property is True, the FitToPagesTall property is ignored.