【发布时间】:2014-03-26 15:46:00
【问题描述】:
我编写了一个 VB .NET 程序,它打开一个 Excel 工作簿来放置一些值。 这是打开文件的代码:
OpenFileDialog1.FileName = ""
OpenFileDialog1.Filter = "Excel files (*.xls)|*.xls"
OpenFileDialog1.ShowDialog()
filePath = OpenFileDialog1.FileName
If System.IO.File.Exists(filePath) Then
oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
oBook = oExcel.Workbooks.Open(filePath)
End If
在我不得不在一台既没有 .NET Framework 4.5 也没有 4.0 的旧计算机上运行它之前,它运行良好
然后我将框架目标更改为 3.5,它在运行时给了我这个错误:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.VisualBasic.dll
Additional information: Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))
我猜3.5和4.5打开Excel文件的方式不一样所以不知道该怎么做。
【问题讨论】:
-
您在编译时是否还针对 x86 或 x64?根据您的 Office 版本,它可能需要 x86。