GoExcel automates portions of the Excel Interop API. with the Excel object and the ws (worksheet) object this is the complete Excel Interop method (vb.net) to print/save PDF from Excel using its built in PDF driver.
Try
ws.PageSetup.PrintArea = rngTable.Address
Catch ex As Exception
MsgBox("Error setting print area to table size.")
End Try
Try
ExcelApp.PrintCommunication = False
Catch ex As Exception
End Try
Try
ws.PageSetup.Zoom = False
Catch ex As Exception
MsgBox("Error setting page setup zoom mode to false.")
End Try
Try
ws.PageSetup.FitToPagesWide = 1
Catch ex As Exception
MsgBox("Error setting page setup fit to pages wide to 1.")
End Try
Try
ws.PageSetup.FitToPagesTall = 0
Catch ex As Exception
MsgBox("Error setting page setup fit to pages tall to auto (0).")
End Try
Try
ExcelApp.PrintCommunication = True
Catch ex As Exception
End Try
'save file
If Not String.IsNullOrWhiteSpace(DrawingListPath) Then
If System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(DrawingListPath)) = False Then
System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(DrawingListPath))
End If
If WorkFile.Exists Then
WorkFile.Delete()
WorkFile.Refresh()
End If
wb.SaveAs(DrawingListPath, , , , , , , Excel.XlSaveConflictResolution.xlUserResolution)
'print table to pdf
ws.ExportAsFixedFormat(Excel.XlFixedFormatType.xlTypePDF, WorkFile.FullName, Excel.XlFixedFormatQuality.xlQualityStandard, True, False, , , False)
wb.Close()
End If
WorkFile is an instance of the class System.IO.FileInfo, and since there are many ways Excel can kick back errors I have many try catch blocks.
Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/