目前我得到的代码可以打印工作簿中的所有工作表:
MyApp = new Excel.Application();
MyApp.Visible = false;
MyBook = MyApp.Workbooks.Open(generatedFile);
foreach (Excel.Worksheet ws in MyBook.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;
}
MyBook.Worksheets.PrintOutEx();
MyBook.Close(SaveChanges: true);
MyApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(MyApp);
我的问题是如何在同一个打印作业中只打印选定的工作表(特定单元格不为空的工作表)?
如果我没有错误地调用WorkSheet.PrintOut()
n,那么WorkSheets会创建n个打印作业,对吧?