VB.net Excel ExportAsFixedFormat fails Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))

前端 未结 2 1282
滥情空心
滥情空心 2021-01-28 23:18

I am trying to write a very simple VB.net app which would open an excel file and save it as excel.

The environment I am working on is as follows:

  • Windows 1
相关标签:
2条回答
  • 2021-01-28 23:36

    Right! Thank you to all that tried to help. By reading your responses I kept trying till I figured out the issue.

    It appears that ExportAsFixedFormat doesn't like Excel sheets with formulas in. To work around this issue, I just created a new blank worksheet and copied and pasted (values only) the content from my main sheet into it. This seems to work perfectly. I then automated this in my code as follows:

        Dim xlworksheet_static As Excel.Worksheet = xlWorkBook.Worksheets(2)
        xlWorkSheet.Range("A1", "H35").Copy()
        xlworksheet_static.Activate()
        xlworksheet_static.Range("A1", "H35").Select()
        xlworksheet_static.PasteSpecial(Excel.XlPasteType.xlPasteValuesAndNumberFormats)
    
        xlworksheet_static.ExportAsFixedFormat(Type:=Excel.XlFixedFormatType.xlTypePDF, Filename:=
         "d:\test\test.pdf", Quality:=Excel.XlFixedFormatQuality.xlQualityStandard _
        , IncludeDocProperties:=True, IgnorePrintAreas:=True, OpenAfterPublish:=
        False)
    

    Probably not the most straight forward way but I couldn't get it to work otherwise!

    0 讨论(0)
  • 2021-01-28 23:47

    Save it as .PDF like that:

    xlWorkSheet.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, "d:\test\test.pdf")
    
    0 讨论(0)
提交回复
热议问题