我有一个生成 excel 文件的应用程序。用以下方法打印时,第一页不打印。
我们通过as传递 excel 文件名 asfilename
和打印机设置。然后我们使用打开然后给定的文件并打开工作簿并通过. 在我选择 XPS 打印机作为打印机的情况下,它会两次获取输出文件名(打印第一张纸的时间和打印其他纸的时间)。当我更改调用输出文件的打印方法时,尚未创建。PrintDialog
printerSettings
Microsoft.Office.Interop.Excel.Application
Microsoft.Office.Interop.Excel.Workbook
wb.Worksheets.PrintOutEx()
wb.Worksheets.PrintOutEx(1,1, ... )
public static void PrintWorksheet(string fileName, PrinterSettings printerSettings )
{
Application excelApp = null;//excel application
Microsoft.Office.Interop.Excel.Workbook wb = null;//workbook
try
{
excelApp = new Microsoft.Office.Interop.Excel.Application();//initialize excel app
wb = excelApp.Workbooks.Open(
fileName,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing); //open workbook
wb.Worksheets.PrintOutEx(1, wb.Worksheets.Count, printerSettings.Copies, false, printerSettings.PrinterName, false, printerSettings.Collate, false, Type.Missing);//calling print method
}
catch(Exception e)
{
string err = e.Message;
}
finally
{
//closing the excel app and workbook
GC.Collect();
GC.WaitForPendingFinalizers();
if (wb != null)
{
Marshal.FinalReleaseComObject(wb.Worksheets);
wb.Close(false, Type.Missing, Type.Missing);
Marshal.FinalReleaseComObject(wb);
}
if (excelApp != null)
{
excelApp.Quit();
Marshal.FinalReleaseComObject(excelApp);
}
}
}
有谁能够帮我?