我当前的项目使用EPPlus来创建Excel文件.这些文件由用户打印,我试图强制Excel文件只在一个A4页面打印,无论宽度和内容如何.
实际上,当打印文件时,它需要两页,而第二页只包含一列.
我的代码:
ws.PrinterSettings.Orientation = eOrientation.Landscape;
ws.PrinterSettings.PrintArea = ws.Cells[ws_dimension_adress];
ws.PrinterSettings.TopMargin= 0;
ws.PrinterSettings.RightMargin = 0;
ws.PrinterSettings.BottomMargin = 0;
ws.PrinterSettings.LeftMargin = 0;
ws.Cells[ws_dimension_adress].AutoFitColumns();
ws.Cells[ws_dimension_adress].Style.Font.Size = 9;
Run Code Online (Sandbox Code Playgroud)
结果:我的代码提供的结果
我需要的:
我搜索了"autofit to A4 page"之类的内容,但是还没有解决方案.
备注:需要所有列.在创建文件之前,我不能简单地删除一个.
谢谢你的帮助!