C# 互操作工作表printoutEx不';不要打印第一页
我有一个生成excel文件的应用程序。当按以下方法打印时,第一页不打印 我们将excel文件名作为C# 互操作工作表printoutEx不';不要打印第一页,c#,printing,interop,C#,Printing,Interop,我有一个生成excel文件的应用程序。当按以下方法打印时,第一页不打印 我们将excel文件名作为文件名传递,并通过打印对话框作为打印机设置传递打印机设置。 然后,我们使用Microsoft.Office.Interop.Excel.Application打开给定的文件,使用Microsoft.Office.Interop.Excel.Workbook打开工作簿并通过wb.Worksheets.PrintOutEx()打印整张工作表。 在我选择XPS打印机作为打印机的情况下,它会两次获得输出文件
文件名
传递,并通过打印对话框
作为打印机设置
传递打印机设置。
然后,我们使用Microsoft.Office.Interop.Excel.Application
打开给定的文件,使用Microsoft.Office.Interop.Excel.Workbook
打开工作簿并通过wb.Worksheets.PrintOutEx()打印整张工作表。
在我选择XPS打印机作为打印机的情况下,它会两次获得输出文件名(打印第一张图纸的时间和打印其他图纸的时间)。
当我将打印方法调用更改为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);
}
}
}
有人能帮我吗?你试过用下面的方法吗
您是否尝试过使用以下方法
打印份数的第三个参数时。。您是通过对话框设置的吗?如何设置副本数,例如..?打印副本数的第三个参数时。。您是通过对话框设置的吗?例如,您如何设置副本的数量?您能否详细说明刚才尝试的代码发生了什么。。它做了同样的事情还是什么都没做..?你能详细说明一下你刚才尝试的代码发生了什么。。它做了同样的事情还是什么都没做。。?
Microsoft.Office.Tools.Excel.NamedRange myNamedRange = Globals.Sheet1.namedRange1;
myNamedRange.PrintOutEx(
1,
wb.Worksheets.Count,
printerSettings.Copies,
false,
printerSettings.PrinterName,
false,
printerSettings.Collate,
false
);