通过System.Data.DataSet将Excel转为SQL
将任何 XLSX、XLS、XLSM、XLTX、CSV 和 TSV 文件转换为 System.Data.DataTable
以实现与 System.Data.SQL
的完全互操作性或填充 DataGrid。 此DataTable
对象可以包含表集合、关系和约束。
using IronXL; using System; using System.Data; // Supported for XLSX, XLS, XLSM, XLTX, CSV and TSV WorkBook workBook = WorkBook.Load("sample.xlsx"); // Convert the whole Excel WorkBook to a DataSet DataSet dataSet = workBook.ToDataSet(); foreach (DataTable table in dataSet.Tables) { Console.WriteLine(table.TableName); // Enumerate by rows or columns first at your preference foreach (DataRow row in table.Rows) { for (int i = 0 ; i < table.Columns.Count ; i++) { Console.Write(row[i]); } } }
Imports IronXL Imports System Imports System.Data ' Supported for XLSX, XLS, XLSM, XLTX, CSV and TSV Private workBook As WorkBook = WorkBook.Load("sample.xlsx") ' Convert the whole Excel WorkBook to a DataSet Private dataSet As DataSet = workBook.ToDataSet() For Each table As DataTable In dataSet.Tables Console.WriteLine(table.TableName) ' Enumerate by rows or columns first at your preference For Each row As DataRow In table.Rows For i As Integer = 0 To table.Columns.Count - 1 Console.Write(row(i)) Next i Next row Next table
Install-Package IronXL.Excel
将任何 XLSX、XLS、XLSM、XLTX、CSV 和 TSV 文件转换为 System.Data.DataTable
以实现与 System.Data.SQL
的完全互操作性或填充 DataGrid。 此DataTable
对象可以包含表集合、关系和约束。