Попробуйте установить поставщика ACE по следующей ссылке
https://www.microsoft.com/en-us/download/confirmation.aspx?id=13255
Как импортировать Excel в SQL Server, ознакомьтесь с
https://www.red -gate.com / простой разговор / DotNet / с-программирование / офис-развитие-в-визуальной студии /
Или попробуйте использовать этот фрагмент
Imports System
Imports System.Collections.Generic
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Runtime.InteropServices
Imports Excel = Microsoft.Office.Interop.Excel
Public Module Program
Public Sub Main()
Dim officeType = Type.GetTypeFromProgID("Excel.Application")
If officeType Is Nothing Then
Console.WriteLine("Sorry, Excel must be installed!")
Console.WriteLine("Press any key to exit")
Console.ReadLine()
Return
End If
Const fileToRead As String = "C:\TMP\FirstTest.xlsx"
Dim xlApp As Excel.Application = Nothing
Dim workbooks As Excel.Workbooks = Nothing
Dim xlWorkBook As Excel.Workbook = Nothing
Dim sheets As Excel.Sheets = Nothing
Dim t1 As Excel.Worksheet = Nothing
Try
xlApp = New Excel.Application()
Console.WriteLine($"Trying to open file {fileToRead}")
workbooks = xlApp.Workbooks
xlWorkBook = workbooks.Open(fileToRead, 0, True, 5, "", "", True, Origin:=Excel.XlPlatform.xlWindows, Delimiter:=vbTab, Editable:=False, Notify:=False, Converter:=0, AddToMru:=True, Local:=1, CorruptLoad:=0)
sheets = xlApp.ActiveWorkbook.Sheets
Dim dic = New List(Of String)()
For Each mSheet In sheets
dic.Add($"[{t1.Name}$]")
Next
Using myConnection = New OleDbConnection($"Provider=Microsoft.Ace.OLEDB.12.0;Data Source={fileToRead};Extended Properties='Excel 12.0 Xml;HDR = YES;'")
Using dtSet = New DataSet()
For Each s In dic
Console.WriteLine($" Processing {s} table")
Dim myCommand = New OleDbDataAdapter($"select * from {s};", myConnection)
myCommand.TableMappings.Add("Table", s)
myCommand.Fill(dtSet)
Next
For Each t As DataTable In dtSet.Tables
Console.WriteLine($" Table {t.TableName} has {t.Rows.Count} records")
Next
End Using
End Using
dic = Nothing
Console.WriteLine("Successfully imported!")
Console.WriteLine("After closing Console Windows start Task Manager and be sure that Excel instance is not there!")
Console.WriteLine("Press any key to exit")
Console.ReadLine()
Catch e As Exception
Console.WriteLine($"Error importing from Excel : {e.Message}")
Console.ReadLine()
Finally
GC.Collect()
GC.WaitForPendingFinalizers()
If sheets IsNot Nothing Then
Marshal.FinalReleaseComObject(sheets)
sheets = Nothing
End If
xlWorkBook.Close()
If xlWorkBook IsNot Nothing Then
Marshal.FinalReleaseComObject(xlWorkBook)
xlWorkBook = Nothing
End If
xlApp.Quit()
If xlApp IsNot Nothing Then
Marshal.FinalReleaseComObject(xlApp)
xlApp = Nothing
End If
GC.Collect()
GC.WaitForPendingFinalizers()
End Try
End Sub
End Module