Excel的互操作打印 [英] Excel Interop Print

查看:228
本文介绍了Excel的互操作打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要打印一个Excel工作表的选定区域(我与Range.Select()选择)使用下列打印设置:



打印机:微软XPS文档编写结果
打印选择结果
景观定位结果
A4结果
。正常边距结果
上的一个页面<适合表/ p>

我怎样才能做到这一点使用_Worksheet.PrintOut或_Worksheet.PrintOutEx?

提前

谢谢!


解决方案

试试这个(久经考验



我假设你已经设置参考Excel和已申报的对象,如

 的Microsoft.Office.Interop.Excel。应用xlexcel; 
Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
Microsoft.Office.Interop.Excel.Range xlRange;
对象misValue = System.Reflection.Missing.Value;



这正好代码的最新部分。



  //获取当前的打印机
字符串Defprinter = NULL;
Defprinter = xlexcel.ActivePrinter;

//设置打印机微软XPS文档写入
xlexcel.ActivePrinter =Microsoft XPS文档编写器上Ne01:

//设置我们的表
VAR _with1 = xlWorkSheet.PageSetup;
// A4纸型
_with1.PaperSize = Excel.XlPaperSize.xlPaperA4;
//横向方向
_with1.Orientation = Excel.XlPageOrientation.xlLandscape;在一页上
_with1.FitToPagesWide = 1
//飞度表;
_with1.FitToPagesTall = 1;
//普通保证金
_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);

//打印范围
xlRange.PrintOutEx(misValue,misValue,misValue,misValue,
misValue,misValue,misValue,misValue);

//设置打印机回到这是什么
xlexcel.ActivePrinter = Defprinter;


I need to print a selected area of an excel sheet (which I selected with Range.Select()) using the following print settings:

Printer: Microsoft XPS Document Writer
Print Selection
Landscape Orientation
A4
Normal Margins
Fit Sheet on One Page

How can I achieve this using _Worksheet.PrintOut or _Worksheet.PrintOutEx?

Thanks in advance!

解决方案

Try this (TRIED AND TESTED)

I am assuming that you have set reference to Excel and have already declared your objects like

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;

This goes in the later part of the code.

// 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;

这篇关于Excel的互操作打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆