首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Excel Interop打印

Excel Interop打印
EN

Stack Overflow用户
提问于 2012-06-05 23:50:43
回答 2查看 18.5K关注 0票数 7

我需要使用以下打印设置打印excel工作表的选定区域(使用Range.Select()选择):

打印机: Microsoft XPS文档写入器

打印选择

横向

A4

正常边距

在一页上调整工作表

如何使用_Worksheet.PrintOut或_Worksheet.PrintOutEx实现这一点?

提前感谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-06-06 00:52:27

尝试一下(尝试并测试了)

我假设您已经设置了对Excel的引用,并且已经声明了如下对象

代码语言:javascript
运行
复制
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;

这将放在代码的后面部分。

代码语言:javascript
运行
复制
// 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;
票数 14
EN

Stack Overflow用户

发布于 2015-03-18 23:30:57

为了让“Fit Sheet on One Page”起作用,我们还应该将Zoom属性设置为false。

//在一页上调整工作表

代码语言:javascript
运行
复制
_with1.FitToPagesWide = 1;

_with1.FitToPagesTall = 1;

_with1.Zoom = False;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10900565

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档