gpt4 book ai didi

excel - VB.net Excel ExportAsFixedFormat 失败来自 HRESULT : 0x80010105 (RPC_E_SERVERFAULT)) 的异常

转载 作者:太空宇宙 更新时间:2023-11-03 15:03:03 25 4
gpt4 key购买 nike

我正在尝试编写一个非常简单的 VB.net 应用程序,它可以打开一个 excel 文件并将其另存为 excel。

我工作的环境如下:

  • Windows 10
  • Visual Studio 2016
  • Office 2016

我已成功打开 Excel 工作表并保存到另一个位置。但是,当尝试打开 excel 并另存为 pdf 时,出现以下错误消息

The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))

查看错误的详细信息,我可以看到以下内容:

System.Runtime.InteropServices.COMException {"The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))"}

error code: -2147417851

我使用的代码如下:

Dim xlApp As New Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
xlApp.Visible = False
xlApp.AlertBeforeOverwriting = False

Dim sheetname As String = "d:\test\test.xlsx"

xlWorkBook = xlApp.Workbooks.Open(sheetname)


xlWorkBook.Activate()
xlWorkSheet = xlWorkBook.Sheets("Sheet1")
xlWorkSheet.Activate()
xlApp.DisplayAlerts = False
xlWorkSheet.ExportAsFixedFormat(Type:=Excel.XlFixedFormatType.xlTypePDF, Filename:=
"d:\test\test.pdf", Quality:=Excel.XlFixedFormatQuality.xlQualityStandard _
, IncludeDocProperties:=True, IgnorePrintAreas:=True, OpenAfterPublish:=
False)





xlWorkBook.Close(SaveChanges:=False)
xlApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) : xlApp = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkBook) : xlWorkBook = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkSheet) : xlWorkSheet = Nothing

帮助!

问题似乎是由于 Excel 工作表有公式,将内容复制并粘贴到新工作表(仅粘贴特殊值和数字格式)并运行上面的代码有效

最佳答案

像那样将其保存为 .PDF:

xlWorkSheet.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, "d:\test\test.pdf")

关于excel - VB.net Excel ExportAsFixedFormat 失败来自 HRESULT : 0x80010105 (RPC_E_SERVERFAULT)) 的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45199698/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com