Forcing Excel to print multiple sheets as a single job

十年热恋 提交于 2019-12-05 21:29:36
Dominik Ras

Use PrintOutEx():

foreach (Excel.Worksheet ws in wb.Worksheets)
{
    Excel.PageSetup ps = (Excel.PageSetup)ws.PageSetup;
    ws.PageSetup.Orientation = Excel.XlPageOrientation.xlLandscape;
    ws.PageSetup.Order = Excel.XlOrder.xlDownThenOver;
    ws.PageSetup.FitToPagesWide = 1;
    ws.PageSetup.FitToPagesTall = 50;
    ws.PageSetup.Zoom = false;  
}
wb.Worksheets.PrintOutEx();  
krassif

According to Microsoft support, Excel may decide to spool multiple print jobs for a single print request. A single Excel print job covers one or more print areas. If you iterate over the print areas and invoke print each and every print area, you regain some control over the output.

Once all the jobs have completed, you can proceed to bind all of the pieces into a single PDF file. Some time ago I used this approach (with Win2PDF driver) to convert Excel to PDF on site.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!