Dim excelApplication As Microsoft.Office.Interop.Excel.ApplicationClass = New Microsoft.Office.Interop.Excel.ApplicationClass() Dim excelWorkbook As Microsoft.Office.Interop.Excel.Workbook = Nothing Dim paramSourceBookPath As String = Server.MapPath(".") & "\" & "TempFile1" & "\" & "TotalRPT1.xlsx" Dim paramExportFilePath As String = Server.MapPath(".") & "\" & "TempFile1" & "\" & "TotalRPT1.pdf" Dim paramExportFormat As Microsoft.Office.Interop.Excel.XlFixedFormatType = _ Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF Dim paramExportQuality As Microsoft.Office.Interop.Excel.XlFixedFormatQuality = Microsoft.Office.Interop.Excel.XlFixedFormatQuality.xlQualityStandard Dim paramOpenAfterPublish As Boolean = False Dim paramIncludeDocProps As Boolean = True Dim paramIgnorePrintAreas As Boolean = True Dim paramFromPage As Object = Type.Missing Dim paramToPage As Object = Type.Missing Try ' Open the source workbook. Dim wkbs As Workbooks = excelApplication.Workbooks excelWorkbook = wkbs.Open(paramSourceBookPath, False, True) Dim file As FileInfo = New FileInfo(paramExportFilePath) If (file.Exists) Then Try file.Delete() Catch ex As Exception End Try End If ' Save it in the target format. If Not excelWorkbook Is Nothing Then excelWorkbook.ExportAsFixedFormat(paramExportFormat, _ paramExportFilePath, paramExportQuality, _ paramIncludeDocProps, paramIgnorePrintAreas, _ paramFromPage, paramToPage, paramOpenAfterPublish) End If Catch ex As Exception ' Respond to the error. Finally ' Close the workbook object. If Not excelWorkbook Is Nothing Then excelWorkbook.Close(False) excelWorkbook = Nothing End If ' Quit Excel and release the ApplicationClass object. If Not excelApplication Is Nothing Then excelApplication.Quit() excelApplication = Nothing End If GC.Collect() GC.WaitForPendingFinalizers() GC.Collect() GC.WaitForPendingFinalizers() End Try
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)