Forcing Excel to print multiple sheets as a single job

我怕爱的太早我们不能终老 提交于 2019-12-07 16:57:29

问题


In some Excel (2003) workbooks, when I attempt to print multiple sheets, Excel treats the sheets as separate print jobs. This fubars the excel automation app I've been writing since it causes Adobe PDF Printer to stop and ask the user for the second file name.

It looks like it might be something to do with the assigned print area of each page though clearing (or even resetting) the print area does not make a difference.

How can I force Excel to print all selected sheets as a single print job? (I'm using the virtual Adobe PDF Printer)

Barring that, how can I detect, in advance of printing, when Excel will treat one or more of the selected tabs as a separate print job?

I'm automating Excel 2003 with C3/.net3.5 and printing using the Adobe PDF Printer installed by Acrobat 7 Pro.


回答1:


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();  



回答2:


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.



来源:https://stackoverflow.com/questions/5821818/forcing-excel-to-print-multiple-sheets-as-a-single-job

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