【发布时间】:2013-03-22 14:15:35
【问题描述】:
我正在尝试使用 VB.NET 打印 Excel 电子表格,但出现错误
无法设置 PageSetup 类的 PaperSize 属性
这是我的代码,
Dim oldCI As System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture
System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-US")
With application
.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable
.Visible = False
.EnableEvents = False
.DisplayAlerts = False
.ScreenUpdating = False
End With
Dim workbook As Excel.Workbook
Dim worksheet As Excel.Worksheet
'Open as readonly and do not update links
workbook = application.Workbooks.Open(_fileName, 2, True)
For Each worksheet In workbook.Worksheets
worksheet.PageSetup.PaperSize = _paperSize
Next
workbook.PrintOutEx()
workbook.Close(False)
application.Quit()
System.Threading.Thread.CurrentThread.CurrentCulture = oldCI
worksheet = Nothing
application = Nothing
此代码在我的开发机器上运行,一旦我部署到测试服务器,代码就会失败。服务器上已经安装了默认的打印机驱动程序。
【问题讨论】:
-
它在第一个实例上是否已经失败?还是在特定的工作表上?
-
您遇到了什么错误?您使用的是正确的枚举,对吗? msdn.microsoft.com/en-us/library/…
-
第一次失败
-
是的,使用了正确的枚举。它只是由另一个类计算出来的,用_paperSize表示
-
请告知我们计算机是否安装了打印机,如果安装了,该打印机是否支持您尝试设置的纸张尺寸。