如何使用 IronXL 在 C# .NET Core 中建立 Excel 電子表格
在ASP.NET Core中程式生成Excel試算表開啟了強大的自動化可能性—從財務報告和庫存跟蹤到資料匯出和自動化儀表板。 在Web應用開發中,整合.NET Core Excel試算表生成增強了資料的可存取性和報告功能,允許使用者與複雜資料集互動並提取有價值的見解。 使用IronXL for .NET,開發人員可以在不安裝Microsoft Office或依賴Office Interop的情況下建立Excel文件。此跨平台程式庫可在Windows、Linux和macOS上運行,對於部署到Azure或Docker容器的現代資料驅動應用程式尤其理想。
本教程介紹了建立具有專業格式、公式和多種匯出選項的.NET Core Excel試算表。 無論是構建ASP.NET Core網頁應用程式、控制台應用程式還是後台服務,這些技術都適用於所有.NET 10應用程式。 最終,您將擁有能在Visual Studio或任何.NET開發環境中與現有專案整合的生產就緒Excel文件生成程式碼。
如何在 .NET Core 專案中安裝 IronXL?
在建立試算表之前,您需要將IronXL新增到您的專案中。 在Visual Studio中打開NuGet Package Manager控制台並運行以下命令之一:
Install-Package IronXL.Excel
第一個命令在Visual Studio Package Manager控制台中有效。 第二個在任何使用.NET CLI的終端中有效。 這兩者安裝相同的NuGet包並自動將IronXL新增到您的專案引用中。
安裝完成後,IronXL即用,僅需一個using指令。該程式庫不需要任何額外配置、運行時依賴或Microsoft Office安裝。 它可以在任何.NET 10運行的平台上工作—Windows、Linux、macOS或任何雲環境。
欲了解詳細的安裝選項,包括手動下載DLL,請參閱IronXL安裝指南。 Linux開發人員還應查看Linux部署文件以獲得平台特定的指導。

如何在沒有Office依賴的情況下建立Excel試算表?
傳統的Microsoft Excel自動化需要安裝MS Office,並依賴於Office Interop,這在Linux或容器化環境中無法使用。 如Microsoft有關Office Interop的文件中所述,Office Interop引入了部署複雜性和授權問題。 IronXL for .NET通過提供一個純.NET解決方案來消除這些限制,該解決方案以原生方式處理Excel文件,完全支持現代試算表功能。
此程式庫支持.NET 8、.NET 9和.NET 10,以及早期的.NET Core版本。 它處理XLSX、XLS、CSV和其他試算表格式,無需外部依賴。 這使其對於需要伺服器端應用的情況、微服務和安裝Microsoft Office不切實際的場景特別有價值。 通過NuGet的簡易整合意味著您可以在幾分鐘內開始編寫Excel文件:
using IronXL;
// Create a new workbook in XLSX format
WorkBook workbook = WorkBook.Create(ExcelFileFormat.XLSX);
// Add an Excel worksheet with a custom name
WorkSheet sheet = workbook.CreateWorkSheet("SalesReport");
// Set a cell value
sheet["A1"].Value = "Product Sales Summary";
// Save the generated Excel file
workbook.SaveAs("SalesReport.xlsx");
using IronXL;
// Create a new workbook in XLSX format
WorkBook workbook = WorkBook.Create(ExcelFileFormat.XLSX);
// Add an Excel worksheet with a custom name
WorkSheet sheet = workbook.CreateWorkSheet("SalesReport");
// Set a cell value
sheet["A1"].Value = "Product Sales Summary";
// Save the generated Excel file
workbook.SaveAs("SalesReport.xlsx");
Imports IronXL
' Create a new workbook in XLSX format
Dim workbook As WorkBook = WorkBook.Create(ExcelFileFormat.XLSX)
' Add an Excel worksheet with a custom name
Dim sheet As WorkSheet = workbook.CreateWorkSheet("SalesReport")
' Set a cell value
sheet("A1").Value = "Product Sales Summary"
' Save the generated Excel file
workbook.SaveAs("SalesReport.xlsx")
ExcelFileFormat參數來指定XLSX(在Excel 2007中引入的現代XML格式)或XLS(遺留二進制格式)。 由於文件大小較小且與現代工具的相容性較好,XLSX被推薦用於大多數情況。 CreateWorkSheet()方法新增了命名的工作表,Excel資料位於其中—每個工作簿可以包含多個獨立工作表以組織相關資料。
使用反映Excel尋址系統的括號表示法來設置單元格值—sheet["A1"]直接鎖定在單元格A1。 這種語法支持特定單元格和範圍,使任何試算表專案中的批量操作變得簡單明瞭。
輸出

如何程式化地新增工作表和填充資料?
真實世界中的Excel試算表包含多個工作表中的結構化資料。 IronXL提供優雅的方案來高效組織資訊和填充值,即使在手動資料輸入或資料驅動應用中的自動化資料管道中也是如此。
using IronXL;
WorkBook workbook = WorkBook.Create(ExcelFileFormat.XLSX);
WorkSheet sheet = workbook.CreateWorkSheet("MonthlySales");
// Set column names as headers
sheet["A1"].Value = "Month";
sheet["B1"].Value = "Revenue";
sheet["C1"].Value = "Units Sold";
// Populate Excel data using a loop (mock sales data)
string[] months = { "January", "February", "March", "April", "May", "June" };
decimal[] revenue = { 45000.50m, 52000.75m, 48500.25m, 61000.00m, 58750.50m, 67200.25m };
int[] units = { 150, 175, 160, 200, 190, 220 };
for (int i = 0; i < months.Length; i++)
{
int row = i + 2;
sheet[$"A{row}"].Value = months[i];
sheet[$"B{row}"].Value = revenue[i];
sheet[$"C{row}"].Value = units[i];
}
// Set a range of cells to the same value across columns
sheet["D2:D7"].Value = "Active";
workbook.SaveAs("MonthlySales.xlsx");
using IronXL;
WorkBook workbook = WorkBook.Create(ExcelFileFormat.XLSX);
WorkSheet sheet = workbook.CreateWorkSheet("MonthlySales");
// Set column names as headers
sheet["A1"].Value = "Month";
sheet["B1"].Value = "Revenue";
sheet["C1"].Value = "Units Sold";
// Populate Excel data using a loop (mock sales data)
string[] months = { "January", "February", "March", "April", "May", "June" };
decimal[] revenue = { 45000.50m, 52000.75m, 48500.25m, 61000.00m, 58750.50m, 67200.25m };
int[] units = { 150, 175, 160, 200, 190, 220 };
for (int i = 0; i < months.Length; i++)
{
int row = i + 2;
sheet[$"A{row}"].Value = months[i];
sheet[$"B{row}"].Value = revenue[i];
sheet[$"C{row}"].Value = units[i];
}
// Set a range of cells to the same value across columns
sheet["D2:D7"].Value = "Active";
workbook.SaveAs("MonthlySales.xlsx");
Imports IronXL
Dim workbook As WorkBook = WorkBook.Create(ExcelFileFormat.XLSX)
Dim sheet As WorkSheet = workbook.CreateWorkSheet("MonthlySales")
' Set column names as headers
sheet("A1").Value = "Month"
sheet("B1").Value = "Revenue"
sheet("C1").Value = "Units Sold"
' Populate Excel data using a loop (mock sales data)
Dim months As String() = {"January", "February", "March", "April", "May", "June"}
Dim revenue As Decimal() = {45000.5D, 52000.75D, 48500.25D, 61000.0D, 58750.5D, 67200.25D}
Dim units As Integer() = {150, 175, 160, 200, 190, 220}
For i As Integer = 0 To months.Length - 1
Dim row As Integer = i + 2
sheet($"A{row}").Value = months(i)
sheet($"B{row}").Value = revenue(i)
sheet($"C{row}").Value = units(i)
Next
' Set a range of cells to the same value across columns
sheet("D2:D7").Value = "Active"
workbook.SaveAs("MonthlySales.xlsx")
字串插值($"A{row}")允許在迴圈內動態地尋址單元格,使其能夠從任何資料源程式化地填充行變得簡單明了。 範圍語法sheet["D2:D7"]對多個單元格同時設置值——對於狀態列、預設值或初始化資料區非常有用。 IronXL自動處理資料型別轉換,將小數儲存為數值,將字串內容儲存為文字,同時保留生成的文件中的適當Excel資料型別。
與多個工作表一起工作
建立多個工作表,在單一工作簿內對相關Excel資料進行邏輯組織:
WorkSheet summarySheet = workbook.CreateWorkSheet("Summary");
WorkSheet detailSheet = workbook.CreateWorkSheet("Details");
WorkSheet archiveSheet = workbook.CreateWorkSheet("Archive");
WorkSheet summarySheet = workbook.CreateWorkSheet("Summary");
WorkSheet detailSheet = workbook.CreateWorkSheet("Details");
WorkSheet archiveSheet = workbook.CreateWorkSheet("Archive");
Dim summarySheet As WorkSheet = workbook.CreateWorkSheet("Summary")
Dim detailSheet As WorkSheet = workbook.CreateWorkSheet("Details")
Dim archiveSheet As WorkSheet = workbook.CreateWorkSheet("Archive")
對於需要資料庫整合的應用,IronXL與Entity Framework Core、Dapper或原生ADO.NET一起工作。 來自DataTable物件的資料可以直接匯出到工作表中,簡化報告工作流程,讓使用者可以跨系統共享資料。
請在文件中了解更多關於管理工作表和編寫Excel文件的資料。 要讀取現有Excel文件,請參閱Excel文件載入教程。
輸出

如何應用專業格式和樣式?
原始資料在正確格式化後變得有意義。 IronXL支持背景顏色、字體、邊框和數字格式—這些是將Excel試算表轉換成適合高管演示或客戶交付的精緻報告的基本格式功能。
using IronXL;
WorkBook workbook = WorkBook.Create(ExcelFileFormat.XLSX);
WorkSheet sheet = workbook.CreateWorkSheet("FormattedReport");
// Create headers with styling
sheet["A1"].Value = "Category";
sheet["B1"].Value = "Amount";
sheet["C1"].Value = "Date";
// Apply header formatting to the Excel sheet
sheet["A1:C1"].Style.SetBackgroundColor("#2E86AB");
sheet["A1:C1"].Style.Font.Bold = true;
sheet["A1:C1"].Style.Font.SetColor("#FFFFFF");
// Add sample data to specific cells
sheet["A2"].Value = "Software License";
sheet["B2"].Value = 1299.99m;
sheet["C2"].Value = DateTime.Now;
// Format currency and date columns
sheet["B2"].FormatString = "$#,##0.00";
sheet["C2"].FormatString = "yyyy-MM-dd";
// Add borders around the data range
var dataRange = sheet["A1:C2"];
dataRange.Style.BottomBorder.SetColor("#000000");
dataRange.Style.BottomBorder.Type = IronXL.Styles.BorderType.Thin;
workbook.SaveAs("FormattedReport.xlsx");
using IronXL;
WorkBook workbook = WorkBook.Create(ExcelFileFormat.XLSX);
WorkSheet sheet = workbook.CreateWorkSheet("FormattedReport");
// Create headers with styling
sheet["A1"].Value = "Category";
sheet["B1"].Value = "Amount";
sheet["C1"].Value = "Date";
// Apply header formatting to the Excel sheet
sheet["A1:C1"].Style.SetBackgroundColor("#2E86AB");
sheet["A1:C1"].Style.Font.Bold = true;
sheet["A1:C1"].Style.Font.SetColor("#FFFFFF");
// Add sample data to specific cells
sheet["A2"].Value = "Software License";
sheet["B2"].Value = 1299.99m;
sheet["C2"].Value = DateTime.Now;
// Format currency and date columns
sheet["B2"].FormatString = "$#,##0.00";
sheet["C2"].FormatString = "yyyy-MM-dd";
// Add borders around the data range
var dataRange = sheet["A1:C2"];
dataRange.Style.BottomBorder.SetColor("#000000");
dataRange.Style.BottomBorder.Type = IronXL.Styles.BorderType.Thin;
workbook.SaveAs("FormattedReport.xlsx");
Imports IronXL
Dim workbook As WorkBook = WorkBook.Create(ExcelFileFormat.XLSX)
Dim sheet As WorkSheet = workbook.CreateWorkSheet("FormattedReport")
' Create headers with styling
sheet("A1").Value = "Category"
sheet("B1").Value = "Amount"
sheet("C1").Value = "Date"
' Apply header formatting to the Excel sheet
sheet("A1:C1").Style.SetBackgroundColor("#2E86AB")
sheet("A1:C1").Style.Font.Bold = True
sheet("A1:C1").Style.Font.SetColor("#FFFFFF")
' Add sample data to specific cells
sheet("A2").Value = "Software License"
sheet("B2").Value = 1299.99D
sheet("C2").Value = DateTime.Now
' Format currency and date columns
sheet("B2").FormatString = "$#,##0.00"
sheet("C2").FormatString = "yyyy-MM-dd"
' Add borders around the data range
Dim dataRange = sheet("A1:C2")
dataRange.Style.BottomBorder.SetColor("#000000")
dataRange.Style.BottomBorder.Type = IronXL.Styles.BorderType.Thin
workbook.SaveAs("FormattedReport.xlsx")
Style屬性公開了符合Microsoft Excel功能的格式選項。 背景色接受十六進制程式碼(無論有無FormatString應用與Excel自定義格式語法相同的數字格式——兩個環境中均適用相同的模式。 邊框樣式支持Thin、Medium、Thick和Double型別,允許您精確控製Excel工作表中的單元格邊界。
高級格式技術
對於包含大量資料的Excel試算表,CreateFreezePane(0, 1)在滾動時保持標題可見——這是一個微妙的增強,能顯著提升大型資料集的可用性。 通過sheet.PrintSetup進行列印配置,處理方向、邊距和縮放以進行實物輸出。
在單元格格式指南和邊框配置教程中探索其他樣式選擇。 這些工具使您能夠完全控製單元格外觀的每一個方面。
如何使用Excel公式進行自動計算?
Excel的計算引擎自動化資料分析,並且IronXL完全支持公式。 使用標準Excel語法作為字串設置公式,並且IronXL在請求時自動計算結果——這對於報告和財務分析至關重要。
using IronXL;
WorkBook workbook = WorkBook.Create(ExcelFileFormat.XLSX);
WorkSheet sheet = workbook.CreateWorkSheet("BudgetCalculations");
// Add expense data to the Excel workbook
sheet["A1"].Value = "Expense";
sheet["B1"].Value = "Amount";
sheet["A2"].Value = "Rent";
sheet["B2"].Value = 2500;
sheet["A3"].Value = "Utilities";
sheet["B3"].Value = 350;
sheet["A4"].Value = "Supplies";
sheet["B4"].Value = 875;
sheet["A5"].Value = "Marketing";
sheet["B5"].Value = 1200;
// Add formulas for calculations
sheet["A7"].Value = "Total:";
sheet["B7"].Formula = "=SUM(B2:B5)";
sheet["A8"].Value = "Average:";
sheet["B8"].Formula = "=AVERAGE(B2:B5)";
sheet["A9"].Value = "Maximum:";
sheet["B9"].Formula = "=MAX(B2:B5)";
sheet["A10"].Value = "Count:";
sheet["B10"].Formula = "=COUNT(B2:B5)";
// Calculate all formulas
workbook.EvaluateAll();
// Access calculated values programmatically
decimal total = sheet["B7"].DecimalValue;
Console.WriteLine($"Calculated total: {total}");
workbook.SaveAs("BudgetCalculations.xlsx");
using IronXL;
WorkBook workbook = WorkBook.Create(ExcelFileFormat.XLSX);
WorkSheet sheet = workbook.CreateWorkSheet("BudgetCalculations");
// Add expense data to the Excel workbook
sheet["A1"].Value = "Expense";
sheet["B1"].Value = "Amount";
sheet["A2"].Value = "Rent";
sheet["B2"].Value = 2500;
sheet["A3"].Value = "Utilities";
sheet["B3"].Value = 350;
sheet["A4"].Value = "Supplies";
sheet["B4"].Value = 875;
sheet["A5"].Value = "Marketing";
sheet["B5"].Value = 1200;
// Add formulas for calculations
sheet["A7"].Value = "Total:";
sheet["B7"].Formula = "=SUM(B2:B5)";
sheet["A8"].Value = "Average:";
sheet["B8"].Formula = "=AVERAGE(B2:B5)";
sheet["A9"].Value = "Maximum:";
sheet["B9"].Formula = "=MAX(B2:B5)";
sheet["A10"].Value = "Count:";
sheet["B10"].Formula = "=COUNT(B2:B5)";
// Calculate all formulas
workbook.EvaluateAll();
// Access calculated values programmatically
decimal total = sheet["B7"].DecimalValue;
Console.WriteLine($"Calculated total: {total}");
workbook.SaveAs("BudgetCalculations.xlsx");
Imports IronXL
Dim workbook As WorkBook = WorkBook.Create(ExcelFileFormat.XLSX)
Dim sheet As WorkSheet = workbook.CreateWorkSheet("BudgetCalculations")
' Add expense data to the Excel workbook
sheet("A1").Value = "Expense"
sheet("B1").Value = "Amount"
sheet("A2").Value = "Rent"
sheet("B2").Value = 2500
sheet("A3").Value = "Utilities"
sheet("B3").Value = 350
sheet("A4").Value = "Supplies"
sheet("B4").Value = 875
sheet("A5").Value = "Marketing"
sheet("B5").Value = 1200
' Add formulas for calculations
sheet("A7").Value = "Total:"
sheet("B7").Formula = "=SUM(B2:B5)"
sheet("A8").Value = "Average:"
sheet("B8").Formula = "=AVERAGE(B2:B5)"
sheet("A9").Value = "Maximum:"
sheet("B9").Formula = "=MAX(B2:B5)"
sheet("A10").Value = "Count:"
sheet("B10").Formula = "=COUNT(B2:B5)"
' Calculate all formulas
workbook.EvaluateAll()
' Access calculated values programmatically
Dim total As Decimal = sheet("B7").DecimalValue
Console.WriteLine($"Calculated total: {total}")
workbook.SaveAs("BudgetCalculations.xlsx")
Formula屬性接受標準的Excel公式語法——在Microsoft Excel中有效的公式在這裡同樣有效。 設置公式後,調用EvaluateAll()計算結果。 這個步驟保證通過型別屬性如StringValue立即獲得計算值。 若不調用EvaluateAll(),公式仍然會正確保存並在Excel中打開時進行計算,但如需程式化存取結果,首先需要進行評估。
輸出


IronXL支持超過150個Excel函式,包括數學運算(SUM、AVERAGE、ROUND)、統計函式(COUNT、MAX、MIN、STDEV)、文字操作(CONCATENATE、LEFT、RIGHT)以及邏輯運算(IF、AND、OR)。 查看公式編輯指南以獲得高級場景,包括跨工作表的單元格引用。
內建聚合方法
對於不需要在Excel文件中保留公式的簡單場景,IronXL提供內建聚合方法:
decimal sum = sheet["B2:B5"].Sum();
decimal avg = sheet["B2:B5"].Avg();
decimal max = sheet["B2:B5"].Max();
decimal sum = sheet["B2:B5"].Sum();
decimal avg = sheet["B2:B5"].Avg();
decimal max = sheet["B2:B5"].Max();
Dim sum As Decimal = sheet("B2:B5").Sum()
Dim avg As Decimal = sheet("B2:B5").Avg()
Dim max As Decimal = sheet("B2:B5").Max()
當計算不需要以可見公式的形式出現在試算表中時,這些方法提供了C#本地的替代方案。 面向物件的API保持您的程式碼可讀且型別安全,無需基於字串的公式語法。
如何匯出Excel文件並提供下載?
IronXL支持多種匯出格式以滿足不同的整合要求。 除了標準的Excel格式外,試算表還可以匯出為CSV以進行資料交互、JSON以用於Web應用或TSV以相容於遺留系統。 這種靈活性使得將Excel生成整合到任何工作流程中變得容易。
using IronXL;
WorkBook workbook = WorkBook.Load("BudgetCalculations.xlsx");
// Export to different formats
workbook.SaveAs("output.xlsx"); // Modern Excel (Office 2007+)
workbook.SaveAs("output.xls"); // Legacy Excel (97-2003)
workbook.SaveAsCsv("output.csv"); // CSV for data import/export
workbook.SaveAsJson("output.json"); // JSON for web APIs
using IronXL;
WorkBook workbook = WorkBook.Load("BudgetCalculations.xlsx");
// Export to different formats
workbook.SaveAs("output.xlsx"); // Modern Excel (Office 2007+)
workbook.SaveAs("output.xls"); // Legacy Excel (97-2003)
workbook.SaveAsCsv("output.csv"); // CSV for data import/export
workbook.SaveAsJson("output.json"); // JSON for web APIs
Imports IronXL
Dim workbook As WorkBook = WorkBook.Load("BudgetCalculations.xlsx")
' Export to different formats
workbook.SaveAs("output.xlsx") ' Modern Excel (Office 2007+)
workbook.SaveAs("output.xls") ' Legacy Excel (97-2003)
workbook.SaveAsCsv("output.csv") ' CSV for data import/export
workbook.SaveAsJson("output.json") ' JSON for web APIs
每種格式都有特定的使用案例。 XLSX在與Excel使用者共享時最適合用來保留格式和公式。 CSV提供了最大相容性,可用於導入到資料庫、分析工具或其他試算表應用中。 JSON自然與JavaScript前端和REST API整合。
輸出


在ASP.NET Core中提供Excel文件
對於ASP.NET Core網頁應用程式,將Excel文件作為可下載響應服務只需幾行程式碼:
[HttpGet("download-report")]
public IActionResult DownloadReport()
{
WorkBook workbook = WorkBook.Create(ExcelFileFormat.XLSX);
WorkSheet sheet = workbook.CreateWorkSheet("Report");
sheet["A1"].Value = "Generated Report";
sheet["A2"].Value = DateTime.Now;
var stream = workbook.ToStream();
return File(
stream,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"Report.xlsx"
);
}
[HttpGet("download-report")]
public IActionResult DownloadReport()
{
WorkBook workbook = WorkBook.Create(ExcelFileFormat.XLSX);
WorkSheet sheet = workbook.CreateWorkSheet("Report");
sheet["A1"].Value = "Generated Report";
sheet["A2"].Value = DateTime.Now;
var stream = workbook.ToStream();
return File(
stream,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"Report.xlsx"
);
}
Imports Microsoft.AspNetCore.Mvc
<HttpGet("download-report")>
Public Function DownloadReport() As IActionResult
Dim workbook As WorkBook = WorkBook.Create(ExcelFileFormat.XLSX)
Dim sheet As WorkSheet = workbook.CreateWorkSheet("Report")
sheet("A1").Value = "Generated Report"
sheet("A2").Value = DateTime.Now
Dim stream = workbook.ToStream()
Return File(
stream,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"Report.xlsx"
)
End Function
MemoryStream,其中包含完整的Excel文件,通過ASP.NET Core的File()方法返回,並具有適當的MIME型別。 此模式對MVC控制器、API控制器和簡約API完全相同。瀏覽器自動觸發文件下載,並指定文件名,允許使用者在本地保存生成的Excel文件。
對於高流量應用,考慮異步生成報告並在基礎資料不頻繁變化時快取結果——此方法能顯著提高性能。 格式轉換文件涵蓋其他匯出場景,包括密碼保護的文件。
IronXL與其他.NET Excel程式庫比較如何?
市場上有幾個用于.NET Excel操作的程式庫,每個都有不同的優勢。 下面的表格展示了它們在生產應用中最重要的標準上如何比較:
| 功能 | IronXL | 開源替代方案 |
|---|---|---|
| 需要安裝Microsoft Office | 否 | 否 |
| 技術支援 | 是的 (24/5工程團隊) | 基於社群 |
| 跨平台(.NET Core) | 完全支持 | 依程式庫不同 |
| 公式計算引擎 | 150+個功能 | 有限或無 |
| 授權模式 | 商業授權,帶免費試用 | 各種開源 |
IronXL在企業場景中表現出色,這些場景需要可靠的技術支援、文件和不斷更新。 該程式庫優雅地處理邊緣案例—損壞的文件、複雜的公式和大型資料集,而開源替代方案可能會有困難。 對於重視開發速度和生產可靠性的團隊而言,IronXL的商業支持提供了安心。
根據在Stack Overflow的討論,開發者經常提到API簡單性和文件質量是一選擇Excel程式庫為其.NET Core專案時的決定因素。 .NET基金會還強調跨平台部署是現代.NET開發的一個優先事項,使得不依賴Office的程式庫對於可維護的解決方案是必須的。
對安全意識強的團隊而言:IronXL獨立於Microsoft Office運行,並避免Office Interop,從而將外部漏洞的風險降到最低。 內建支持加密和密碼保護,允許您保護生成的Excel文件,確保只有授權使用者才能存取或編輯關鍵工作表和資料。 查看IronXL授權選項以找到適合您團隊的方案。
如何在大規模操作上處理性能?
當您的應用程式為許多同時使用者生成Excel文件或處理大型資料集時,性能規劃變得至關重要。 IronXL高效地處理大型工作簿,因為它完全在記憶體中運行,無需生成Office進程或COM物件。 這種架構使CPU和記憶體開銷保持可預測。
關鍵性能策略
對於資料密集型報告,將資料批量地寫入單元格而不是一次寫入一個。使用sheet["A1:Z1000"]的括號表示法寫入範圍可以比遍歷單個單元格設置統一值快得多。 對於異構資料,使用帶有字串插值的迴圈進行動態單元格尋址。
對於按需生成報告的ASP.NET Core端點,考慮使用MemoryStream輸出。 當基礎資料在請求之間不變時,可以立即返回快取的Excel文件,而不需要重新生成。 此策略對於儀表板匯出和定時報告特別有效。
當每個執行緒操作其自己的WorkBook實例時,IronXL的多執行緒生成是安全的。 避免在不同步的情況下跨執行緒共享工作簿或工作表實例。 對於後台作業處理,像Hangfire或Quartz.NET這樣的程式庫可以與IronXL一起使用於計劃報告生成,允許您在非高峰時預生成文件。
對於最大資料集,考慮將資料分割到多個工作表中,而不是建立擁有數萬行的單一表。 匯出DataTable文件顯示了從ADO.NET來源進行批量資料傳輸的高效模式。 在完整的API參考中提供了涵蓋高級場景的額外程式碼範例,如讀取現有Excel文件或操作密碼保護工作簿。
您接下來的步驟是什麼?
使用IronXL建立.NET Core Excel試算表把本來對依賴性重的任務變成簡單的.NET操作。 從基本的單元格操作到公式計算和專業格式,該程式庫提供了一個完整的試算表自動化工具包,可以在.NET 10運行的任何地方運行—Windows伺服器、Linux容器或雲平台。
跨平台架構確保了在開發機和生產環境中的行為一致,消除了Office Interop解決方案常見的"在我機器上運行"的問題。 從NuGet安裝命令開始,建立您的第一本工作簿,並使用本指南中顯示的模式進行構建。
下載免費30天試用版以探索所有功能,而無任何限制,或查看授權選項以進行生產部署。 瀏覽IronXL程式碼範例以查看其他場景並試用,並查閱IronXL文件中心以獲取完整的API參考和高級配置指南。
常見問題
使用IronXL在.NET Core中生成Excel電子試算表的好處是什麼?
IronXL允許開發者以程式方式建立Excel文件,無需Microsoft Office或Office Interop,提供在Windows、Linux和macOS上的跨平台相容性。這使其非常適合現代資料驅動的應用程式。
IronXL可以用於ASP.NET Core應用程式嗎?
可以,IronXL可以整合到ASP.NET Core應用程式中,實現強大的自動化功能,例如財務報告、庫存跟踪和資料匯出。
IronXL能否在網路應用程式中生成Excel電子試算表?
可以。IronXL支持在網路應用程式中生成並下載Excel表單,提高使用者體驗,允許使用者匯出和互動複雜的資料表。
IronXL是否需要安裝Microsoft Office?
不,IronXL無需安裝Microsoft Office。它獨立於Office Interop運行,簡化了部屬和整合。
IronXL如何在.NET Core應用程式中增強資料可存取性?
IronXL增強資料可存取性,允許開發者以程式方式生成Excel電子試算表,使使用者更容易與複雜的資料集互動和獲得洞察。
IronXL可以部屬於如Azure的雲端環境中嗎?
可以,IronXL可以部屬於如Azure和Docker容器的雲端環境中,非常適合可擴展的雲基應用程式。
IronXL與macOS和Linux相容嗎?
IronXL完全與macOS和Linux相容,提供一個為.NET應用程式生成Excel電子試算表的跨平台解決方案。
哪些型別的應用程式得益於使用IronXL?
需要資料驅動解決方案的應用程式,例如財務報告、庫存管理和自動化儀表板,從使用IronXL生成Excel電子試算表中獲益甚多。
IronXL如何改善網路應用程式中的使用者體驗?
IronXL通過將複雜資料表匯出為Excel電子試算表來改善使用者體驗,使資料更可存取和便攜。




