简体   繁体   English

在.NET C#中从Excel读取数据的建议

[英]Suggestions for reading data from excel in .net c#

I need to read in data from excel files in my c# winforms app. 我需要在c#winforms应用程序中从excel文件中读取数据。 Any recommendations on good components for this? 有什么好的组件建议吗? I've used syncfusion some years ago and that seemed to do the trick. 几年前,我使用过同步融合,似乎可以解决问题。

There'll be a bunch of header lines I need to skip (so a straight ADO approach won't work easily) and then a table of data with standard columns but variable number of rows. 我需要跳过一堆标题行(因此,直接的ADO方法不容易工作),然后是具有标准列但行数可变的数据表。

I'll be pumping the data into SQL Server db once it's read, but probably need to do validation etc on it before that. 读取数据后,我将其泵入SQL Server db,但在此之前可能需要对其进行验证等。

thanks! 谢谢!

SpreadsheetGear for .NET will do it. .NET的SpreadsheetGear可以做到。

You can see ASP.NET samples with C# and VB source here and download the free trial here if you want to try it out. 你可以看到ASP.NET样本C#和VB源在这里和下载免费试用这里 ,如果你想尝试一下。

Disclaimer: I own SpreadsheetGear LLC 免责声明:我拥有SpreadsheetGear LLC

Using ASPOSE Tools 使用ASPOSE工具

Using ADO.NET 使用ADO.NET

Do you need graphic support? 您需要图形支持吗?

Im using the ComponentOne XLS component right now. 我现在正在使用ComponentOne XLS组件。 It is pretty stable and does it job. 它非常稳定并且可以正常工作。 Im using it for data integration too. 我也使用它进行数据集成。

I also wanted to do some xls reports, however the API does not support the full excel stack (not even launching an excel instance) so i had to go over Mirosoft.Office.Interop 我也想做一些xls报告,但是API不支持完整的excel堆栈(甚至不启动excel实例),因此我不得不检查Mirosoft.Office.Interop

替代方案之一: 面向.NET的MS Office包装器

you can use LINQ to XML also, see the link below... 您也可以使用LINQ to XML,请参见下面的链接...

Video Tutorial 影片教学

We're currently using Flexcel . 我们目前正在使用Flexcel It has some nice features including a tool for reading a spreadsheet and generating the necessary C# (or VB or Delphi) code to generate that sheet using their toolkit -- it makes designing a sheet a snap. 它具有一些不错的功能,包括一个工具,用于读取电子表格并生成必要的C#(或VB或Delphi)代码,以使用其工具包来生成该工作表-它使设计工作表变得轻而易举。 The licensing wasn't expensive (site license for developers, redistribution free). 许可并不昂贵(开发人员的站点许可,免费重新分发)。

The only thing against it is that XLSX (Excel 2007 native format) compatibility is "real soon now". 唯一反对的是XLSX(Excel 2007本机格式)的兼容性“现在就可以实现”。

You can do something like this: 你可以这样做:

// Connection String to Excel Workbook
string excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Extended Properties=\"Excel 8.0;HDR=YES;\"";

OleDbDataAdapter oleDbDataAdapter = new OleDbDataAdapter("Select * FROM [Sheet1$]", excelConnectionString);

DataSet dataSet = new DataSet();

oleDbDataAdapter.Fill(dataSet);

Also see "SqlBulkCopy" 另请参见“ SqlBulkCopy”

Read this blog post on Reading and Writing Excel Spreadsheets. 阅读有关阅读和编写Excel电子表格的博客文章。

Reading and Writing Excel Spreadsheets 读写Excel电子表格

Ultimately we opted for Syncfusion's XLSIO which works well. 最终,我们选择了效果很好的Syncfusion的XLSIO

Thanks for the other suggestions too. 也感谢其他建议。

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

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