我正在尝试使用 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
这段代码在我的开发机器上工作,一旦我部署到测试服务器,代码就会失败。服务器上已经安装了默认打印机驱动程序。