locked
convert from excel to pdf using ExportAsFixedFormat method problem RRS feed

  • Question

  • hello guys:

    i'm developing web application to export excel to pdf format.
    i faced a strange problem.

    Problem:

    1-when running my application on my local machine , wvery thing is ok.
    2-when hosting mt application on machine with windows xp sp2 , wvery thing is ok.
    3-when hosting my application on machine with windows xp sp3 or windows server 2003 sp2 , the application hangs and the file conversion failed.
    it's an urgent issue , i need urgent help.

    this is my code sample for conversion:

    Sub ConvertWorkbookToPDFXPS()

            ' Declare variables to hold references to the Excel ApplicationClass
            ' and Workbook objects.         
            Dim excelApplication As ApplicationClass = Nothing
            Dim excelWorkbook As Workbook = Nothing
            Dim missing As Object = System.Reflection.Missing.Value

            ' Declare a variable for the path to the workbook to convert.
            Dim paramSourceBookPath As String = Server.MapPath("Reports.xlsx")

            ' Declare variables for the Document.ExportAsFixedFormat method parameters.
            Dim paramExportFilePath As String = Server.MapPath("MCS.pdf")
            Dim paramExportFormat As XlFixedFormatType = XlFixedFormatType.xlTypePDF
            Dim paramExportQuality As XlFixedFormatQuality = 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


            ' Create an instance of Excel.
            excelApplication = New Microsoft.Office.Interop.Excel.Application

            ' Open the source workbook.
            excelWorkbook = excelApplication.Workbooks.Open(Server.MapPath("Reports.xlsx"), Nothing, False)

            ' Save it in the target format.
            If Not excelWorkbook Is Nothing Then
               

    excelWorkbook.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF, Server.MapPath("MCS.pdf"), Microsoft.Office.Interop.Excel.XlFixedFormatQuality.xlQualityStandard, missing, False, missing, missing, False, missing)

            End If


            ' Close the Workbook object.
            If Not excelWorkbook Is Nothing Then
                excelWorkbook.Close(False)
                excelWorkbook = Nothing
            End If

            ' Close the ApplicationClass object.
            If Not excelApplication Is Nothing Then
                excelApplication.Quit()
                excelApplication = Nothing
            End If

            GC.Collect()
            GC.WaitForPendingFinalizers()
            GC.Collect()
            GC.WaitForPendingFinalizers()

          
        End Sub

    Tuesday, November 17, 2009 11:30 AM

Answers

  • Hi, 

     

    Thank you for contacting "Innovate on Office" forum!

    We provide support on advisory issues for MS office 2007 where we address "How-to" questions. The issue submitted by you requires troubleshooting, that’s why this forum is not the right place to post your issue.

     

    Depending upon your partner level, you have the following three options available to use our services:

    1.     Purchase an incident pack.

    2.     Contact the main-stream support team of Excel in Microsoft.

    3.     You can call Customer service representative (CSR) at 1-800-936-5800 X 88987

                            OR

    - Use one of the incidents available to you.

                            OR

    - Visit https://partner.microsoft.com/global/supportsecurity/technicalsupport/40014662

     

                   

    Thanks, 

    Sunando

    Wednesday, November 18, 2009 5:22 AM
    Moderator

All replies


  • hello guys:
    i'm developing web application to export excel to pdf format.
    i faced a strange problem.
    Problem:

    1-when running my application on my local machine , wvery thing is ok.
    2-when hosting mt application on machine with windows xp sp2 , wvery thing is ok.
    3-when hosting my application on machine with windows xp sp3 or windows server 2003 sp2 , the application hangs and the file conversion failed.
    it's an urgent issue , i need urgent help.

    this is my code sample for conversion:

    Sub ConvertWorkbookToPDFXPS()

            ' Declare variables to hold references to the Excel ApplicationClass
            ' and Workbook objects.         
            Dim excelApplication As ApplicationClass = Nothing
            Dim excelWorkbook As Workbook = Nothing
            Dim missing As Object = System.Reflection.Missing.Value

            ' Declare a variable for the path to the workbook to convert.
            Dim paramSourceBookPath As String = Server.MapPath("Reports.xlsx")

            ' Declare variables for the Document.ExportAsFixedFormat method parameters.
            Dim paramExportFilePath As String = Server.MapPath("MCS.pdf")
            Dim paramExportFormat As XlFixedFormatType = XlFixedFormatType.xlTypePDF
            Dim paramExportQuality As XlFixedFormatQuality = 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


            ' Create an instance of Excel.
            excelApplication = New Microsoft.Office.Interop.Excel.Application

            ' Open the source workbook.
            excelWorkbook = excelApplication.Workbooks.Open(Server.MapPath("Reports.xlsx"), Nothing, False)

            ' Save it in the target format.
            If Not excelWorkbook Is Nothing Then
               

    excelWorkbook.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF, Server.MapPath("MCS.pdf"), Microsoft.Office.Interop.Excel.XlFixedFormatQuality.xlQualityStandard, missing, False, missing, missing, False, missing)

            End If


            ' Close the Workbook object.
            If Not excelWorkbook Is Nothing Then
                excelWorkbook.Close(False)
                excelWorkbook = Nothing
            End If

            ' Close the ApplicationClass object.
            If Not excelApplication Is Nothing Then
                excelApplication.Quit()
                excelApplication = Nothing
            End If

            GC.Collect()
            GC.WaitForPendingFinalizers()
            GC.Collect()
            GC.WaitForPendingFinalizers()

          
        End Sub

    Tuesday, November 17, 2009 11:37 AM
  • Hi, 

     

    Thank you for contacting "Innovate on Office" forum!

    We provide support on advisory issues for MS office 2007 where we address "How-to" questions. The issue submitted by you requires troubleshooting, that’s why this forum is not the right place to post your issue.

     

    Depending upon your partner level, you have the following three options available to use our services:

    1.     Purchase an incident pack.

    2.     Contact the main-stream support team of Excel in Microsoft.

    3.     You can call Customer service representative (CSR) at 1-800-936-5800 X 88987

                            OR

    - Use one of the incidents available to you.

                            OR

    - Visit https://partner.microsoft.com/global/supportsecurity/technicalsupport/40014662

     

                   

    Thanks, 

    Sunando

    Wednesday, November 18, 2009 5:22 AM
    Moderator
  • Hi,
      
       Thank you for your reply , please try to give me the exact link to solve my problem because i've got confused  or give me an advice to fix it.

    please i need an urgent help.

    thanks
    Sunday, November 22, 2009 9:37 AM
  • Hi

    I understand the urgency around this request and how things can go worse with development sometimes.

    I believe you would like to call CSR @ +1 800 936 5800 x88987

    Thanks
    Sunando
    Sunday, November 22, 2009 10:07 PM
    Moderator
  • Hi Sunando

    I am also getting same error on same location means

    excelWorkbook.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF, Server.MapPath("MCS.pdf"), Microsoft.Office.Interop.Excel.XlFixedFormatQuality.xlQualityStandard, missing, False, missing, missing, False, missing)

     

    You found any solution?? please help.

    thanks

    Amit

     

     


    Amitsp
    Friday, October 29, 2010 5:24 AM
  • i fond the solution of this error required to setting in dcom component.

    http://sqlreporting.blogspot.com/2010/11/office-automation-configuraiton-on.html


    Amitsp
    • Proposed as answer by Amit Prajapati Tuesday, November 2, 2010 10:39 AM
    Tuesday, November 2, 2010 10:33 AM