我試圖改變紙張尺寸和Excel工作表方向 代碼運行沒有任何錯誤更改Excel的PageSetup類的紙張大小和方向特性,但沒有在Excel無法從VB.net
改變這裏代碼:
Private Sub doCompare()
Dim xlApp As Excel.Application = Nothing
Dim DEs As Excel.Worksheet = Nothing
Dim Rws As Excel.Worksheet = Nothing
Dim ewb As Excel.Workbook = Nothing
XLapp = New Excel.Application
ewb = XLapp.Workbooks.Open("xxxxxxx0.xls")
DEs = ewb.Worksheets("Data Entry")
Rws = ewb.Worksheets("Comparing Results")
'Do something with these worksheets
'Now trying to change default settings. Code copied from Excel macro
xlApp.PrintCommunication = False
Rws.PageSetup.PrintArea = ""
DEs.PageSetup.PrintArea = ""
With Rws.PageSetup
.Orientation = Excel.XlPageOrientation.xlLandscape
.PaperSize = Excel.XlPaperSize.xlPaperA4
.FitToPagesWide = 1 'Fit All Columns to page
End With
xlApp.PrintCommunication = True
End Sub
打印機驅動程序安裝
找到解決方案!首先,'Rws.PageSetup.PrintArea =「」'必須在'xlApp.PrintCommunication = False'之前,必須對工作簿中的所有**工作表應用更改 –