透過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
對象可以包含表格、關聯和約束的集合。