Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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 my windows 7 PC. Here is the stacktrace

   at Microsoft.Office.Interop.Excel.WorkbookClass.ExportAsFixedFormat(XlFixedFormatType Type, Object Filename, Object Quality, Object IncludeDocProperties, Object IgnorePrintAreas, Object From, Object To, Object OpenAfterPublish, Object FixedFormatExtClassPtr)

at schoolwisereportprint.converttopdf() in    
C:\Users\username\Desktop\Dpp2012New\schoolwisereportprint.aspx.vb:line 33

at schoolwisereportprint.Button1_Click(Object sender, EventArgs e) in C:\Users\username\Desktop\Dpp2012New\schoolwisereportprint.aspx.vb:line 158

Here is my converttopdf() function:

Public Sub converttopdf()
    Dim fileName As String = Server.MapPath("rahulserver/pdfreprt.xlsx")
    Dim xlsApp = New Microsoft.Office.Interop.Excel.Application
    xlsApp.ScreenUpdating = False
    Dim xlsBook As Microsoft.Office.Interop.Excel.Workbook
    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
    xlsBook = xlsApp.Workbooks.Open(fileName, UpdateLinks:=False, ReadOnly:=False)
    xlsBook.ExportAsFixedFormat(paramExportFormat, "rahulserver/pdfreprt" & ".pdf", paramExportQuality, paramIncludeDocProps, paramIgnorePrintAreas,paramFromPage, paramToPage, paramOpenAfterPublish)
    xlsBook.Close(SaveChanges:=False)
    xlsApp.Quit()
    MsgBox("successfully converted to pdf!")
End Sub

Even changing paramFromPage and paramToPage to 1 and 1 respectively does not help. I have already spent a whole day troubleshooting this error but could not find a way. Now I look upon SO to get me out of this...

share|improve this question
Do you have permission to write to the server? Additionally, I am not sure that your path is correct - do you need a "server.mappath" there? As an afterthaught: using interop on the server is not recommended by Microsoft - maybe you could use EPPLUS for reading the file and Itextsharp for writing it to pdf. – Christian Sauer Oct 25 '12 at 8:31
Still having the issue? I'm having the same proble, I've tried it locally and it works fine, I've also tried using pdf995 which is a third party pdf converter for excel which also works fine, its just the exportasfixedformat that doesn't seem to work, It did however work earlier on today without any substantial code changes, so im thinking its an excel issue – Alex Nov 13 '12 at 15:34
@Alex yes! I am still having the issue. I tried all that I could and finally decided not to have the feature in my project. – rahulserver Nov 14 '12 at 0:00

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.