在ASP.NET应用程序中导入Excel文件时出错 [英] Error while importing excel file in asp.net application

查看:123
本文介绍了在ASP.NET应用程序中导入Excel文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我创建了一个表单,我要在其中上载Excel文件以保存文件中的数据.我使用了``Microsoft.ACE.OLEDB.12.0''提供程序.
它可以在本地计算机上正常工作,但是当我在网络上发布它时,它将无法正常工作.
它给出错误为:

未在本地计算机上注册"Microsoft.ACE.OLEDB.12.0"提供程序.

使用代码如下:

Hi to all,

I have created a form, in which I want to upload a excel file to save data from the file. I have use ''Microsoft.ACE.OLEDB.12.0'' Provider.
It work fine on local machine, but when I published same on web, it won''t work.
It gives error as:

''Microsoft.ACE.OLEDB.12.0'' provider is not registered on the local machine.

Use code is as follows:

DataTable dtExcel = new DataTable();
string SourceConstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + filename + "';Extended Properties= 'Excel 8.0;HDR=Yes;IMEX=1'";
OleDbConnection con = new OleDbConnection(SourceConstr);
Query = "Select * from [Sheet1$]";
OleDbDataAdapter data = new OleDbDataAdapter(Query, con);
data.Fill(dtExcel);


请指教.
谢谢


Please advice is expected.
Thank You

推荐答案

"; OleDbDataAdapter数据= OleDbDataAdapter(Query,con); data.Fill(dtExcel);
"; OleDbDataAdapter data = new OleDbDataAdapter(Query, con); data.Fill(dtExcel);


请指教.
谢谢


Please advice is expected.
Thank You


您的代码有两个可能的问题.如果其他人有英文Excel版本,那么工作表将不存在.

另一个问题可能是:
http://social.msdn.microsoft.com/论坛/nn-NO/exceldev/thread/0f03c2de-3ee2-475f-b6a2-f4efb97de302 [
There are two possible problems with your code. What if the other person dosent have an english Excel version, then Sheet wont exist.

The other problem could be this:
http://social.msdn.microsoft.com/Forums/nn-NO/exceldev/thread/0f03c2de-3ee2-475f-b6a2-f4efb97de302[^]


除了上传文件,您还可以将Excel数据复制并粘贴到ASP.NET应用程序的文本框中,然后根据定界符将其解析为一个集合.然后可以将此集合循环并推送到数据库.我编写的一些业务批量导入和上传系统都是用这种方式编写的.始终有效!
in addition to whats been already said and as an alternative to uploading files, you can copy and paste excel data into a text-box in ASP.NET application and then just parse it out, based on delimiters, to a collection. This collection can then be looped over and pushed to the database. Some of the business bulk-import and upload systems that I have written, were written this way. Always works!


这篇关于在ASP.NET应用程序中导入Excel文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆