IRONSOFTWAREHOME
C# 中的 Excel 公式
using IronXL;
using System.Linq;

WorkBook workBook = WorkBook.Load("sample.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;

// Set Formulas
workSheet["A1"].Formula = "Sum(B8:C12)";
workSheet["B8"].Formula = "=C9/C11";
workSheet["G30"].Formula = "Max(C3:C7)";

// Force recalculate all formula values in all sheets.
workBook.EvaluateAll();

// Get the formula's calculated value.  e.g. "52"
var formulaValue = workSheet["G30"].First().FormattedCellValue;

// Get the formula as a string. e.g. "Max(C3:C7)"
string formulaString = workSheet["G30"].Formula;

// Save changes with updated formulas and calculated values.
workBook.Save();
Imports IronXL
Imports System.Linq

Dim workBook As WorkBook = WorkBook.Load("sample.xlsx")
Dim workSheet As WorkSheet = workBook.DefaultWorkSheet

' Set Formulas
workSheet("A1").Formula = "Sum(B8:C12)"
workSheet("B8").Formula = "=C9/C11"
workSheet("G30").Formula = "Max(C3:C7)"

' Force recalculate all formula values in all sheets.
workBook.EvaluateAll()

' Get the formula's calculated value.  e.g. "52"
Dim formulaValue = workSheet("G30").First().FormattedCellValue

' Get the formula as a string. e.g. "Max(C3:C7)"
Dim formulaString As String = workSheet("G30").Formula

' Save changes with updated formulas and calculated values.
workBook.Save()
NuGet Download
PM > Install-Package IronXL.Excel
C# 中的 Excel 公式

C# 中的 Excel 公式

using IronXL to handle Excel formulas

IronXL 允許在不需 Office Interop 的情況下設定和評估 Excel 公式。它支援超過 150 種公式,且會定期新增更多公式。 公式可透過 Range.Formula 屬性進行賦值。 以下為範例:

公式是用來計算儲存格數值的運算式。 在 Excel 中,函式是預先定義且隨時可用的公式。

IronXL程式庫在眾多 .NET Excel 函式庫中脫穎而出,因其支援廣泛的 Excel 公式,並能進行即時計算。

How to Use Excel Formulas in C#

以下是在 C# 專案中使用 IronXL 套用 Excel 公式的步驟:

  1. 安裝 Excel 函式庫:從 NuGet 下載並安裝 IronXL,以使用 Excel 功能。
  2. **載入 Excel 文件:**開啟您的 Excel 檔案,並選取您要套用公式的預設 Worksheet 位置。
  3. **設定公式與數值:**為您欲操作的試算表儲存格指派公式及任何必要的數值。
  4. **評估公式:**使用 EvaluateAll 方法計算所有已套用公式的結果。 Workbook
  5. **儲存工作簿:**將您的 Workbook 物件儲存回 Excel 檔案,並反映所有變更與計算結果。

IronXL 提供了一種簡便且高效的方法,可在 C# 應用程式中透過程式化方式處理 Excel 公式,無需在伺服器或客戶端安裝 Excel。

透過 IronXL 學習如何在 C# 中編輯 Excel 公式
在GitHub上查看

準備好開始了嗎?

Nuget Downloads 2,237,574版本:2026.9剛剛發布

Key in blue circle

立即免費取得 30 天試用金鑰

Your trial license will be sent to your email address

無任何限制。100% 解鎖。無需信用卡。

bullet_checked無需信用卡或建立帳號無任何限制。100% 解鎖。無需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
預約您的免費即時演示
Booking Badge

全球數百萬工程師的信賴

Iron Software的客戶標誌
獲得無義務諮詢
填寫以下表格或電郵sales@ironsoftware.com
您的資料將始終保密。
全球數百萬工程師的信賴
Iron Software的客戶標誌
立即獲取您的30天試用金鑰
無需信用卡或帳戶建立