Click here to Skip to main content
15,881,881 members
Please Sign up or sign in to vote.
1.11/5 (2 votes)
I am getting the above error while trying to export the excel 2007(xlsx) format workbook to pdf. The workbook contains only one sheet and I have Ms Office 2007 installed on windows 2003 sp2 server.
Here is my converttopdf() function:

VB
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
Posted
Updated 16-Jun-13 0:22am
v5
Comments
Ron Beyer 16-Jun-13 8:25am    
Which line is this error happening on? We can't recreate your whole project and run it, we need more information.

1 solution

MS Office 2007 does not support 'export' to pdf option by default. You need to download Add-Ins for that.
Following link will solve your problem.

2007 Microsoft Office Add-in: Microsoft Save as PDF or XPS
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900