简体   繁体   English

使用c#将Excel数据导入asp.net中的数据表

[英]Import Excel Data to Datatable in asp.net using c#

Is there any other way to import an Excel file data to a datatable and load it in Gridview in asp.net 2.0 using c#? 有没有其他方法可以将Excel文件数据导入数据表并使用c#在asp.net 2.0中的Gridview中加载它?

I tried using 我试过用

OleDbConnection oconn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+path+";Extended Properties=Excel 12.0");

and it works in my local machine, but when i deployed it in network (server), it gives an error of 它在我的本地机器上工作,但是当我在网络(服务器)中部署它时,它会给出错误

The 'microsoft.ace.oledb.12.0' provider is not registered on the local machine. 'microsoft.ace.oledb.12.0'提供程序未在本地计算机上注册。

I know that I should install something to remove the error and make the web application work, but we are not allowed to install something in the server as it may affect other application integrated with it. 我知道我应该安装一些东西来删除错误并使Web应用程序工作,但我们不允许在服务器中安装一些东西,因为它可能会影响与其集成的其他应用程序。

Any help please... 请帮忙...

First go through following msdn thread and try to resolve issue. 首先通过以下msdn线程并尝试解决问题。

https://social.msdn.microsoft.com/Forums/en-US/1d5c04c7-157f-4955-a14b-41d912d50a64/how-to-fix-error-the-microsoftaceoledb120-provider-is-not-registered-on-the-local-machine?forum=vstsdb https://social.msdn.microsoft.com/Forums/en-US/1d5c04c7-157f-4955-a14b-41d912d50a64/how-to-fix-error-the-microsoftaceoledb120-provider-is-not-registered-on-在本地机器?论坛= vstsdb

If you do not want to install OLEDB provider on server, you should use .NET libraries to read/write Excel files. 如果您不想在服务器上安装OLEDB提供程序,则应使用.NET库来读取/写入Excel文件。 There are plenty of free libraries available like following. 有很多免费图书馆,如下所示。 You can use one of these to populate collection or datatable to bind grid. 您可以使用其中一个来填充集合或数据表以绑定网格。

You can download NPOI and Excel Package from CodePlex website 您可以从CodePlex网站下载NPOI和Excel软件包

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM