C# 讀取 XLSX 檔案
要在C#中讀取XLSX文件,您可以使用IronXL的WorkBook.Load方法來打開Excel文件並訪問工作表,以讀取儲存格數據、執行計算、並轉換為DataTable或DataSet格式。
使用IronXL,您可以在單行中利用WorkBook.Load方法載入XLSX檔案。然後立即存取其第一或命名的工作表並開始讀取儲存格值。
-
1使用 IronXL 安裝 NuGet Package Manager
-
2複製並運行這段程式碼。
IronXL.WorkBook workbook = IronXL.WorkBook.Load("your-file.xlsx");Dim workbook As IronXL.WorkBook = IronXL.WorkBook.Load("your-file.xlsx")Dim workbook As IronXL.WorkBook = IronXL.WorkBook.Load("your-file.xlsx") -
3部署到您的生產環境進行測試
立即在您的項目中開始使用 IronXL,並使用 免費試用
讀取 .XLSX 檔(C#)
- 為您的專案選擇 IronXL
- 載入
WorkBook - 從
WorkSheet存取資料 - 應用求和、最小值和最大值等函數
- 將
WorkSheet讀取為 DataTable、DataSet 等。
如何獲取IronXL以用於我的專案?
在您的專案中使用 IronXL,可以以簡單的方式在 C# 中處理 Excel 檔案格式。 您可以通過直接下載安裝IronXL,或選擇使用NuGet在Visual Studio中安裝。 該軟體可免費用於開發。
在深入閱讀XLSX檔案之前,請探索全面的IronXL檔案以瞭解所有可用功能。 IronXL 支援 .xls 和 .xlsx 兩種格式,因此可通用於傳統和現代 Excel 檔案。
操作指南
如何載入WorkBook?
WorkBook是IronXL的類,其物件提供對Excel檔案及全部功能的完整存取。 例如,若要存取 Excel 檔案,請使用代碼:
using IronXL;
// Load the workbook
WorkBook workBook = WorkBook.Load("sample.xlsx"); // Excel file pathusing IronXL;
// Load the workbook
WorkBook workBook = WorkBook.Load("sample.xlsx"); // Excel file pathImports IronXL
' Load the workbook
Dim workBook As WorkBook = WorkBook.Load("sample.xlsx") ' Excel file pathImports IronXL
' Load the workbook
Dim workBook As WorkBook = WorkBook.Load("sample.xlsx") ' Excel file path為什麼使用WorkBook.Load()方法?
在上述程式碼中,Load()函數將WorkBook載入到WorkBook。 可以通過訪問Excel文件的特定WorkSheet,對WorkBook執行任何類型的函數。Load()方法能自動偵測文件格式,無論是XLS、XLSX、XLSM、XLTX或CSV。如果需要更高級的載入方案,請查看詳細的電子表格載入指南。
將整個工作簿保存在記憶體中,就是讓您在本指南中得到其他所有功能:工作表存取、範圍、聚合和DataTable轉換。 那有一個上限。 一旦XLSX檔案達到數十萬列,工作僅限於從中提取數值,請流式處理列。
如何存取特定工作表?
要訪問Excel文件的特定WorkSheet,IronXL提供了WorkBook類。 它可以用於幾種不同的方式:
有哪些方法可以存取工作表?
using IronXL;
// Access sheet by name
WorkSheet workSheet = workBook.GetWorkSheet("Sheet1");using IronXL;
// Access sheet by name
WorkSheet workSheet = workBook.GetWorkSheet("Sheet1");Imports IronXL
' Access sheet by name
Dim workSheet As WorkSheet = workBook.GetWorkSheet("Sheet1")Imports IronXL
' Access sheet by name
Dim workSheet As WorkSheet = workBook.GetWorkSheet("Sheet1")WorkBook["SheetName"]是上面部分中聲明的WorkSheet。
OR
WorkBook
OR
using IronXL;
// Access sheet by index
WorkSheet workSheet = workBook.WorkSheets[0];using IronXL;
// Access sheet by index
WorkSheet workSheet = workBook.WorkSheets[0];Imports IronXL
' Access sheet by index
Dim workSheet As WorkSheet = workBook.WorkSheets(0)Imports IronXL
' Access sheet by index
Dim workSheet As WorkSheet = workBook.WorkSheets(0)OR
WorkBook.Load()
OR
using IronXL;
// Access the default worksheet
WorkSheet workSheet = workBook.DefaultWorkSheet;using IronXL;
// Access the default worksheet
WorkSheet workSheet = workBook.DefaultWorkSheet;Imports IronXL
' Access the default worksheet
Dim workSheet As WorkSheet = workBook.DefaultWorkSheetImports IronXL
' Access the default worksheet
Dim workSheet As WorkSheet = workBook.DefaultWorkSheetOR
sample.xlsx
OR
using IronXL;
using System.Linq;
// Access the first worksheet
WorkSheet workSheet = workBook.WorkSheets.First();using IronXL;
using System.Linq;
// Access the first worksheet
WorkSheet workSheet = workBook.WorkSheets.First();Imports IronXL
Imports System.Linq
' Access the first worksheet
Dim workSheet As WorkSheet = workBook.WorkSheets.First()Imports IronXL
Imports System.Linq
' Access the first worksheet
Dim workSheet As WorkSheet = workBook.WorkSheets.First()OR
workBook
OR
using IronXL;
using System.Linq;
// Access the first or default worksheet
WorkSheet workSheet = workBook.WorkSheets.FirstOrDefault();using IronXL;
using System.Linq;
// Access the first or default worksheet
WorkSheet workSheet = workBook.WorkSheets.FirstOrDefault();Imports IronXL
Imports System.Linq
' Access the first or default worksheet
Dim workSheet As WorkSheet = workBook.WorkSheets.FirstOrDefault()Imports IronXL
Imports System.Linq
' Access the first or default worksheet
Dim workSheet As WorkSheet = workBook.WorkSheets.FirstOrDefault()OR
workBook
OR
WorkBook.Load
OR
WorkSheet
OR
WorkSheet
OR
workBook
OR
WorkBook
何時應該使用每種工作表存取方法?
每種方法都有其理想的使用個案:
GetWorkSheet("name"): 當您知道確切的工作表名稱時WorkSheets[index]: 程式化地遍歷工作表時DefaultWorkSheet: 處理單張工作表檔案的快速存取First()orFirstOrDefault(): 在工作表名稱可能改變時的安全選擇
在得到ExcelSheet workSheet後,您可以從中獲取任何類型的資料並在其上執行所有Excel功能。 對於更複雜的工作表操作,請參閱在C#中開啟Excel工作表的指南。
如何從工作表中存取資料?
可以從ExcelSheet workSheet存取資料,流程如下:
我可以從儲存格中讀取哪些資料類型?
using IronXL;
// Accessing data as a string
string dataString = workSheet["A1"].ToString();
// Accessing data as an integer
int dataInt = workSheet["B1"].Int32Value;using IronXL;
// Accessing data as a string
string dataString = workSheet["A1"].ToString();
// Accessing data as an integer
int dataInt = workSheet["B1"].Int32Value;Imports IronXL
' Accessing data as a string
Dim dataString As String = workSheet("A1").ToString()
' Accessing data as an integer
Dim dataInt As Integer = workSheet("B1").Int32ValueImports IronXL
' Accessing data as a string
Dim dataString As String = workSheet("A1").ToString()
' Accessing data as an integer
Dim dataInt As Integer = workSheet("B1").Int32ValueIronXL 為不同的資料類型提供各種值存取器:
StringValue: 用於文本資料Int32Value: 用於整數DoubleValue: 用於小數DateTimeValue: 用於日期BoolValue: 用於是/否值
如何一次讀取多個儲存格?
您也可以從特定列的多個儲存格取得資料:
foreach (var cell in workSheet["A2:A10"])
{
Console.WriteLine("Value is: {0}", cell.Text);
}foreach (var cell in workSheet["A2:A10"])
{
Console.WriteLine("Value is: {0}", cell.Text);
}For Each cell In workSheet("A2:A10")
Console.WriteLine("Value is: {0}", cell.Text)
Next cellFor Each cell In workSheet("A2:A10")
Console.WriteLine("Value is: {0}", cell.Text)
Next cell這將顯示從儲存格A2到A10的值。 有關更進階的範圍選擇技術,請訪問選擇範圍教學。
完整實現看起來如何?
在此提供上述具體內容的完整程式碼範例:
using IronXL;
using System;
// Load an Excel file
WorkBook workBook = WorkBook.Load("sample.xlsx");
WorkSheet workSheet = workBook.GetWorkSheet("Sheet1");
// Specify the range
foreach (var cell in workSheet["B2:B10"])
{
Console.WriteLine("Value is: {0}", cell.Text);
}using IronXL;
using System;
// Load an Excel file
WorkBook workBook = WorkBook.Load("sample.xlsx");
WorkSheet workSheet = workBook.GetWorkSheet("Sheet1");
// Specify the range
foreach (var cell in workSheet["B2:B10"])
{
Console.WriteLine("Value is: {0}", cell.Text);
}Imports IronXL
Imports System
' Load an Excel file
Dim workBook As WorkBook = WorkBook.Load("sample.xlsx")
Dim workSheet As WorkSheet = workBook.GetWorkSheet("Sheet1")
' Specify the range
For Each cell In workSheet("B2:B10")
Console.WriteLine("Value is: {0}", cell.Text)
NextImports IronXL
Imports System
' Load an Excel file
Dim workBook As WorkBook = WorkBook.Load("sample.xlsx")
Dim workSheet As WorkSheet = workBook.GetWorkSheet("Sheet1")
' Specify the range
For Each cell In workSheet("B2:B10")
Console.WriteLine("Value is: {0}", cell.Text)
Next它會顯示以下結果:
對於Excel檔案Sample.xlsx:
這些方法說明在專案中使用 Excel 檔案資料是多麼毫不費力。 有關不使用Interop讀取Excel檔案的實用範例,請探索讀取Excel範例。
我如何在資料上執行函數?
通過應用彙總函數如Sum、Min或Max,從Excel WorkSheet中訪問篩選後的數據,使用以下程式碼:
有哪些聚合函數可用?
using IronXL;
// Apply aggregate functions
decimal sum = workSheet["G2:G10"].Sum(); // Sum of cells from G2 to G10
decimal min = workSheet["G2:G10"].Min(); // Minimum value in cells from G2 to G10
decimal max = workSheet["G2:G10"].Max(); // Maximum value in cells from G2 to G10using IronXL;
// Apply aggregate functions
decimal sum = workSheet["G2:G10"].Sum(); // Sum of cells from G2 to G10
decimal min = workSheet["G2:G10"].Min(); // Minimum value in cells from G2 to G10
decimal max = workSheet["G2:G10"].Max(); // Maximum value in cells from G2 to G10Imports IronXL
' Apply aggregate functions
Dim sum As Decimal = workSheet("G2:G10").Sum() ' Sum of cells from G2 to G10
Dim min As Decimal = workSheet("G2:G10").Min() ' Minimum value in cells from G2 to G10
Dim max As Decimal = workSheet("G2:G10").Max() ' Maximum value in cells from G2 to G10Imports IronXL
' Apply aggregate functions
Dim sum As Decimal = workSheet("G2:G10").Sum() ' Sum of cells from G2 to G10
Dim min As Decimal = workSheet("G2:G10").Min() ' Minimum value in cells from G2 to G10
Dim max As Decimal = workSheet("G2:G10").Max() ' Maximum value in cells from G2 to G10IronXL支援多種可直接在範圍上調用的聚合方法,包括:
Avg(): 計算平均值Count(): 計算非空儲存格數Sum(): 將所有值相加Min(): 找出最小值Max(): 找出最大值
對於沒有專用方法的函數,例如MEDIAN、COUNTIF或STDEV,將對應的Excel公式分配給一個儲存格(例如cell.Formula = "=MEDIAN(G2:G10)")並讓IronXL評估它。
如何結合實作多個函數?
欲了解更多詳情,請查看我們的深入教學課程 - 如何使用C#寫Excel檔案,其中詳細介紹了聚合函數。 您還可以探索IronXL中可用的數學函數完整列表。
using IronXL;
using System;
// Load the Excel workbook
WorkBook workBook = WorkBook.Load("sample.xlsx");
// Get the specified WorkSheet
WorkSheet workSheet = workBook.GetWorkSheet("Sheet1");
// Calculate sum, minimum, and maximum for a range of cells
decimal sum = workSheet["G2:G10"].Sum();
decimal min = workSheet["G2:G10"].Min();
decimal max = workSheet["G2:G10"].Max();
// Output results
Console.WriteLine("Sum is: {0}", sum);
Console.WriteLine("Min is: {0}", min);
Console.WriteLine("Max is: {0}", max);using IronXL;
using System;
// Load the Excel workbook
WorkBook workBook = WorkBook.Load("sample.xlsx");
// Get the specified WorkSheet
WorkSheet workSheet = workBook.GetWorkSheet("Sheet1");
// Calculate sum, minimum, and maximum for a range of cells
decimal sum = workSheet["G2:G10"].Sum();
decimal min = workSheet["G2:G10"].Min();
decimal max = workSheet["G2:G10"].Max();
// Output results
Console.WriteLine("Sum is: {0}", sum);
Console.WriteLine("Min is: {0}", min);
Console.WriteLine("Max is: {0}", max);Imports IronXL
Imports System
' Load the Excel workbook
Dim workBook As WorkBook = WorkBook.Load("sample.xlsx")
' Get the specified WorkSheet
Dim workSheet As WorkSheet = workBook.GetWorkSheet("Sheet1")
' Calculate sum, minimum, and maximum for a range of cells
Dim sum As Decimal = workSheet("G2:G10").Sum()
Dim min As Decimal = workSheet("G2:G10").Min()
Dim max As Decimal = workSheet("G2:G10").Max()
' Output results
Console.WriteLine("Sum is: {0}", sum)
Console.WriteLine("Min is: {0}", min)
Console.WriteLine("Max is: {0}", max)Imports IronXL
Imports System
' Load the Excel workbook
Dim workBook As WorkBook = WorkBook.Load("sample.xlsx")
' Get the specified WorkSheet
Dim workSheet As WorkSheet = workBook.GetWorkSheet("Sheet1")
' Calculate sum, minimum, and maximum for a range of cells
Dim sum As Decimal = workSheet("G2:G10").Sum()
Dim min As Decimal = workSheet("G2:G10").Min()
Dim max As Decimal = workSheet("G2:G10").Max()
' Output results
Console.WriteLine("Sum is: {0}", sum)
Console.WriteLine("Min is: {0}", min)
Console.WriteLine("Max is: {0}", max)這段程式碼會顯示以下輸出:
這就是Excel檔案Sample.xlsx的樣子:
如何將Excel工作表讀取為DataTable?
使用IronXL可以輕鬆地將Excel WorkSheet作為DataTable操作。 當您需要將 Excel 資料整合至現有的資料處理管道或將資料綁定至 UI 控制項時,此功能尤其有用。
基本轉換方法是什麼?
using IronXL;
using System.Data;
// Convert worksheet to DataTable
DataTable dt = workSheet.ToDataTable();using IronXL;
using System.Data;
// Convert worksheet to DataTable
DataTable dt = workSheet.ToDataTable();Imports IronXL
Imports System.Data
' Convert worksheet to DataTable
Dim dt As DataTable = workSheet.ToDataTable()Imports IronXL
Imports System.Data
' Convert worksheet to DataTable
Dim dt As DataTable = workSheet.ToDataTable()我如何將第一行用作列標題?
要使用ExcelSheet的第一行作為DataTable ColumnName:
using IronXL;
using System.Data;
// Convert worksheet to DataTable with the first row as column names
DataTable dt = workSheet.ToDataTable(true);using IronXL;
using System.Data;
// Convert worksheet to DataTable with the first row as column names
DataTable dt = workSheet.ToDataTable(true);Imports IronXL
Imports System.Data
' Convert worksheet to DataTable with the first row as column names
Dim dt As DataTable = workSheet.ToDataTable(True)Imports IronXL
Imports System.Data
' Convert worksheet to DataTable with the first row as column names
Dim dt As DataTable = workSheet.ToDataTable(True)ToDataTable()的布林參數設置第一行為您的DataTable的列名。 預設情況下,其值為False。 這在處理包含標頭的結構化資料時尤其有用。
我如何遍歷DataTable?
using IronXL;
using System;
using System.Data;
// Load the Excel workbook
WorkBook workBook = WorkBook.Load("sample.xlsx");
// Get the specified WorkSheet
WorkSheet workSheet = workBook.GetWorkSheet("Sheet1");
// Convert WorkSheet to DataTable
DataTable dt = workSheet.ToDataTable(true); // Use first row as column names
// Iterate through rows and columns and display data
foreach (DataRow row in dt.Rows) // Access rows
{
for (int i = 0; i < dt.Columns.Count; i++) // Access columns of corresponding row
{
Console.Write(row[i] + " ");
}
Console.WriteLine();
}using IronXL;
using System;
using System.Data;
// Load the Excel workbook
WorkBook workBook = WorkBook.Load("sample.xlsx");
// Get the specified WorkSheet
WorkSheet workSheet = workBook.GetWorkSheet("Sheet1");
// Convert WorkSheet to DataTable
DataTable dt = workSheet.ToDataTable(true); // Use first row as column names
// Iterate through rows and columns and display data
foreach (DataRow row in dt.Rows) // Access rows
{
for (int i = 0; i < dt.Columns.Count; i++) // Access columns of corresponding row
{
Console.Write(row[i] + " ");
}
Console.WriteLine();
}Imports IronXL
Imports System
Imports System.Data
' Load the Excel workbook
Dim workBook As WorkBook = WorkBook.Load("sample.xlsx")
' Get the specified WorkSheet
Dim workSheet As WorkSheet = workBook.GetWorkSheet("Sheet1")
' Convert WorkSheet to DataTable
Dim dt As DataTable = workSheet.ToDataTable(True) ' Use first row as column names
' Iterate through rows and columns and display data
For Each row As DataRow In dt.Rows ' Access rows
For i As Integer = 0 To dt.Columns.Count - 1 ' Access columns of corresponding row
Console.Write(row(i) & " ")
Next
Console.WriteLine()
NextImports IronXL
Imports System
Imports System.Data
' Load the Excel workbook
Dim workBook As WorkBook = WorkBook.Load("sample.xlsx")
' Get the specified WorkSheet
Dim workSheet As WorkSheet = workBook.GetWorkSheet("Sheet1")
' Convert WorkSheet to DataTable
Dim dt As DataTable = workSheet.ToDataTable(True) ' Use first row as column names
' Iterate through rows and columns and display data
For Each row As DataRow In dt.Rows ' Access rows
For i As Integer = 0 To dt.Columns.Count - 1 ' Access columns of corresponding row
Console.Write(row(i) & " ")
Next
Console.WriteLine()
Next使用上述程式碼,可以存取並根據需要使用WorkSheet的每個儲存格值。 有關更進階的DataTable操作,請參閱導入和導出為DataSet的指南。
如何將Excel檔案讀取為DataSet?
IronXL提供了一個簡單的函數,將完整的Excel文件(WorkBook)用作DataSet。 使用ToDataSet方法將整個工作簿轉換為DataSet。
在這個範例中,我們將看到如何將Excel檔案用作DataSet。
如何將工作簿轉換為DataSet?
using IronXL;
using System;
using System.Data;
// Load the Excel workbook
WorkBook workBook = WorkBook.Load("sample.xlsx");
// Convert the WorkBook to a DataSet
DataSet ds = workBook.ToDataSet();
// Iterate through tables in the DataSet and display table names
foreach (DataTable dt in ds.Tables)
{
Console.WriteLine(dt.TableName);
}using IronXL;
using System;
using System.Data;
// Load the Excel workbook
WorkBook workBook = WorkBook.Load("sample.xlsx");
// Convert the WorkBook to a DataSet
DataSet ds = workBook.ToDataSet();
// Iterate through tables in the DataSet and display table names
foreach (DataTable dt in ds.Tables)
{
Console.WriteLine(dt.TableName);
}Imports IronXL
Imports System
Imports System.Data
' Load the Excel workbook
Dim workBook As WorkBook = WorkBook.Load("sample.xlsx")
' Convert the WorkBook to a DataSet
Dim ds As DataSet = workBook.ToDataSet()
' Iterate through tables in the DataSet and display table names
For Each dt As DataTable In ds.Tables
Console.WriteLine(dt.TableName)
NextImports IronXL
Imports System
Imports System.Data
' Load the Excel workbook
Dim workBook As WorkBook = WorkBook.Load("sample.xlsx")
' Convert the WorkBook to a DataSet
Dim ds As DataSet = workBook.ToDataSet()
' Iterate through tables in the DataSet and display table names
For Each dt As DataTable In ds.Tables
Console.WriteLine(dt.TableName)
Next上述程式碼的輸出如下:
而Excel檔案Sample.xlsx看起來像這樣:
(出於簡潔省略中間內容)
如何在所有工作表中存取每個儲存格的值?
在上面的例子中,我們可以輕鬆地將Excel文件解析為DataSet,並將Excel文件中的每個DataTable作為DataTable操作。 深入瞭解如何將Excel解析為DataSet,其中包括程式碼範例。
讓我們來看另一個範例,說明如何存取所有ExcelSheets的每個儲存格值。 在這裡,我們可以存取Excel檔案的每個ExcelSheet的每個儲存格值。
using IronXL;
using System;
// Load the Excel workbook
WorkBook workBook = WorkBook.Load("sample.xlsx");
// Iterate through every WorkSheet in the WorkBook
foreach (WorkSheet workSheet in workBook.WorkSheets)
{
Console.WriteLine($"Worksheet: {workSheet.Name}");
// Access each filled cell value on the current WorkSheet
foreach (var cell in workSheet.FilledCells)
{
Console.WriteLine($"{cell.Address}: {cell.Text}");
}
}using IronXL;
using System;
// Load the Excel workbook
WorkBook workBook = WorkBook.Load("sample.xlsx");
// Iterate through every WorkSheet in the WorkBook
foreach (WorkSheet workSheet in workBook.WorkSheets)
{
Console.WriteLine($"Worksheet: {workSheet.Name}");
// Access each filled cell value on the current WorkSheet
foreach (var cell in workSheet.FilledCells)
{
Console.WriteLine($"{cell.Address}: {cell.Text}");
}
}Imports IronXL
Imports System
' Load the Excel workbook
Dim workBook As WorkBook = WorkBook.Load("sample.xlsx")
' Iterate through every WorkSheet in the WorkBook
For Each workSheet As WorkSheet In workBook.WorkSheets
Console.WriteLine($"Worksheet: {workSheet.Name}")
' Access each filled cell value on the current WorkSheet
For Each cell In workSheet.FilledCells
Console.WriteLine($"{cell.Address}: {cell.Text}")
Next
NextImports IronXL
Imports System
' Load the Excel workbook
Dim workBook As WorkBook = WorkBook.Load("sample.xlsx")
' Iterate through every WorkSheet in the WorkBook
For Each workSheet As WorkSheet In workBook.WorkSheets
Console.WriteLine($"Worksheet: {workSheet.Name}")
' Access each filled cell value on the current WorkSheet
For Each cell In workSheet.FilledCells
Console.WriteLine($"{cell.Address}: {cell.Text}")
Next
Next使用上述範例,可方便地存取Excel檔案的每個ExcelSheet的每個儲存格值。這種方法在處理多表工作簿時特別有用,因為資料分佈在不同的頁籤上。
有關如何不使用Interop讀取Excel檔案的詳細資訊,請查看這裡的程式碼。 API參考文件提供關於IronXL API參考中所有可用方法和屬性的詳細資訊。
教程快速存取
WorkSheet
WorkSheet
WorkSheet
常見問題
如何在C#中使用IronXL讀取XLSX文件?
您可以通過使用IronXL的WorkBook.Load方法在C#中讀取XLSX文件,這使您能夠打開Excel文件並訪問其工作表以執行各種操作。
我應該使用什麼方法來從IronXL中特定的工作表中訪問數據?
您可以使用多種方法從特定的工作表中訪問數據,例如GetWorkSheet("name")、WorkSheets[index]、DefaultWorkSheet,或使用LINQ方法如First()或FirstOrDefault()。
如何使用IronXL將Excel工作表轉換為DataTable?
您可以使用ToDataTable方法將Excel工作表轉換為DataTable,並且可以將工作表的第一列作為欄標題(如果指定)。
如何使用IronXL執行Sum、Min和Max等聚合函數?
IronXL允許您直接在一系列單元格上執行聚合函數,如Sum()、Min()和Max(),以便輕鬆進行數據分析。
使用IronXL在C#中讀取XLSX文件有什麼好處?
IronXL提供了一個簡單的API,用於在C#中讀取XLSX文件,支持多種Excel格式,並允許在不需要Excel Interop的情況下進行數據操作和轉換。
在使用IronXL訪問單元格值時,如何處理不同的數據類型?
IronXL提供了針對不同數據類型的特定值訪問器,如文本的StringValue、整數的Int32Value、小數的DoubleValue和日期的DateTimeValue。
我可以使用IronXL將整個工作簿轉換為DataSet嗎?
是的,您可以使用ToDataSet方法將整個工作簿轉換為DataSet,這使您能夠將每個工作表作為一個單獨的DataTable進行操作。
在IronXL中一次讀取多個單元格的推薦方法是什麼?
您可以通過遍歷指定範圍來讀取多個單元格,例如在workSheet["A2:A10"]上使用foreach來讀取每個單元格的值。
如何在我的 C# 項目中安裝 IronXL?
您可以通過直接下載或通過Visual Studio中的NuGet Package Manager安裝IronXL。該程式庫可免費用於開發用途。
如何使用IronXL在控制台中顯示Excel工作表數據結果?
要在控制台中顯示Excel工作表數據,請使用WorkBook.Load加載工作簿,訪問所需的工作表,並遍歷單元格以使用Console.WriteLine輸出其值。
Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。




