Excel Interop打印

我需要使用以下打印设置打印选定区域的Excel表单(我使用Range.Select()select):

打印机:Microsoft XPS文档编写器
打印select
景观定位
A4
正常边距
在一页上适合工作表

我怎样才能达到这个使用_Worksheet.PrintOut或_Worksheet.PrintOutEx?

提前致谢!

试试这个( TRIED AND TESTED

我假设你已经设置了Excel的引用,并已经宣布你的对象

Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; Microsoft.Office.Interop.Excel.Range xlRange; object misValue = System.Reflection.Missing.Value; 

这在代码的后面部分。

 // Get the current printer string Defprinter = null; Defprinter = xlexcel.ActivePrinter; // Set the printer to Microsoft XPS Document Writer xlexcel.ActivePrinter = "Microsoft XPS Document Writer on Ne01:"; // Setup our sheet var _with1 = xlWorkSheet.PageSetup; // A4 papersize _with1.PaperSize = Excel.XlPaperSize.xlPaperA4; // Landscape orientation _with1.Orientation = Excel.XlPageOrientation.xlLandscape; // Fit Sheet on One Page _with1.FitToPagesWide = 1; _with1.FitToPagesTall = 1; // Normal Margins _with1.LeftMargin = xlexcel.InchesToPoints(0.7); _with1.RightMargin = xlexcel.InchesToPoints(0.7); _with1.TopMargin = xlexcel.InchesToPoints(0.75); _with1.BottomMargin = xlexcel.InchesToPoints(0.75); _with1.HeaderMargin = xlexcel.InchesToPoints(0.3); _with1.FooterMargin = xlexcel.InchesToPoints(0.3); // Print the range xlRange.PrintOutEx(misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue); // Set printer back to what it was xlexcel.ActivePrinter = Defprinter; 

对于“单页上的适合工作表”的工作,我们也应该把缩放属性设置为false。

//在一页上进行assembly

 _with1.FitToPagesWide = 1; _with1.FitToPagesTall = 1; _with1.Zoom = False;