Excel数据无法导入 [英] Excel data can't be import
问题描述
我想通过代码将excel数据导入到数据库中,但是当导入数据时出现错误。还有一件事我想对Web应用程序和Windows应用程序做同样的事情,但它在Web应用程序中工作正常但在windows中却没有我也添加了excel的引用。
导入excel的代码:
I want to import excel data into database through code but there is error when its import data.and one thing more i want to do same thing for both web application and windows application but its work fine in web application but not in windows and i have added reference of excel also.
Code for import excel:
ObjOledbConnection = New System.Data.OleDb.OleDbConnection(provider=Microsoft.ACE.OLEDB.12.0;data source=excelfilepath;Extended Properties=Excel 8.0)
Dim objexcel As New Excel.Application
Dim objExcel As Object = CreateObject("Excel.Application")
Dim objBook As Object = objExcel.Workbooks.Open(excelFilePath)
For Each oSheet As Excel.Worksheet In objBook.Sheets
objDtLoopConfiguration = New DataTable
ObjOledbCommand = New System.Data.OleDb.OleDbDataAdapter("select * from ["&oSheet.Name &"$]";, ObjOledbConnection)
ObjOledbCommand.Fill(objDtLoopConfiguration)
objDtLoopConfiguration.TableName = oSheet.Name
mobjds.Tables.Add(objDtLoopConfiguration.Copy())
Next
相同的代码用于Web和Windows,但它的工作用于Web应用程序,但不用于Windows
当我跟踪此代码然后文件是打开但是当我的数据填入数据表然后出现以下错误:'Microsoft.ACE.OLEDB.12.0'提供程序未在本地计算机上注册
Plz尽快给出解决方案。
Same code use for web and windows but its work for web application but not in windows
When i trace this code then file is open but when i data fill in data table then following error raised:"The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine"
Plz give solution as soon as possible.
推荐答案
;, ObjOledbConnection)
ObjOledbCommand.Fill(objDtLoopConfiguration)
objDtLoopConfiguration.TableName = oSheet.Name
mobjds.Tables.Add(objDtLoopConfiguration.Copy())
Next
";, ObjOledbConnection) ObjOledbCommand.Fill(objDtLoopConfiguration) objDtLoopConfiguration.TableName = oSheet.Name mobjds.Tables.Add(objDtLoopConfiguration.Copy()) Next
相同的代码用于Web和Windows但它的工作用于Web应用程序而不是在windows中
当我跟踪这段代码时,文件是打开但当我的数据填入数据表然后出现以下错误:'Microsoft.ACE.OLEDB.12.0'提供程序未在本地计算机上注册
Plz尽快给出解决方案。
Same code use for web and windows but its work for web application but not in windows
When i trace this code then file is open but when i data fill in data table then following error raised:"The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine"
Plz give solution as soon as possible.
这意味着 Microsoft Access Engine :http://www.microsoft.com/en-us/download/details.aspx?id=13255 [ ^ ] 。
不幸的是,你需要拥有安装了Access,或者只是上面提到的可再发行组件。当您未安装此组件或其所需版本时,可能是您在计算机上运行代码。 Microsoft Office组件也是如此,但这可以通过使用Microsoft Open XML SDK来解决。
-SA
It means Microsoft Access Engine: http://www.microsoft.com/en-us/download/details.aspx?id=13255[^].
Unfortunately, you need to have Access installed, or just the redistributable mentioned above. Probably you are running your code on the machine when this component or its required version is not installed. Same goes about Microsoft Office components, but this can be worked around by using Microsoft Open XML SDK.
—SA
这篇关于Excel数据无法导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!