C#打印特定的Excel工作表
目前我有这个代码打印工作簿中的所有工作表:
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()
for n WorkSheets将创buildn个打印作业,对吧?