導入數據使用MS VS 2013和SQL Server 2012的從Excel工作表
我寫一個控制檯應用程序從Excel的一些數據複製到一個SQL表。我不是很遠。下面的代碼打開文件,然後2-3秒後,我得到一個錯誤。
有誤差 -
Additional information: Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Excel.Worksheet'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D8-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Imports Microsoft.Office.Interop.Excel
Imports Microsoft.Office.Interop
Imports System.Data.SqlClient
Imports System.IO
Module Module1
Sub Main()
Dim xlApp As Application
Dim xlWorkBookSrc As Excel.Workbook
Dim xlWorkBookDest As Excel.Workbook
Dim xlWorkSheetSrc As Excel.Worksheet
Dim xlWorkSheetDest As Excel.Worksheet
xlApp = New Excel.Application
xlApp.Visible = True
xlApp.DisplayAlerts = False
xlWorkSheetSrc = xlApp.Workbooks.Open("Folder path")
xlWorkSheetSrc = xlWorkBookSrc.Worksheets("Spectrometer")
End Sub
End Module
當文件打開OK,我不知道爲什麼我那麼得到的錯誤。 Excel工作表是一個.xls,但我也嘗試使用.xlsx並得到相同的結果。
任何想法
乾杯像魅力一樣工作 – Silentbob