Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
e50efc5
Add example: load-a-workbook-from-a-file-stream-modify-cells-then-cal…
agent-aspose-cells-examples Jul 6, 2026
32b996d
Add example: load-a-workbook-from-a-memory-stream-change-a-formula-an…
agent-aspose-cells-examples Jul 6, 2026
9c507bc
Add example: return-a-scalar-numeric-result-from-a-custom-function-af…
agent-aspose-cells-examples Jul 6, 2026
3263bc8
Add example: replace-icustomfunction-implementation-with-an-abstractc…
agent-aspose-cells-examples Jul 6, 2026
761e7e9
Add example: create-a-class-derived-from-abstractcalculationmonitor-a…
agent-aspose-cells-examples Jul 6, 2026
1c5d9e8
Add example: assign-a-custom-monitor-instance-to-calculationoptionsca…
agent-aspose-cells-examples Jul 6, 2026
602ef25
Add example: set-calculationoptionscalculationmode-to-manual-before-i…
agent-aspose-cells-examples Jul 6, 2026
24e88a2
Add example: invoke-workbookcalculateformulacalculationoptions-to-rec…
agent-aspose-cells-examples Jul 6, 2026
9df5205
Add example: evaluate-the-builtin-ifna-function-by-writing-ifnaa1-fal…
agent-aspose-cells-examples Jul 6, 2026
44120d5
Add example: use-workbookcalculateformula-without-options-to-compute-…
agent-aspose-cells-examples Jul 6, 2026
56bf462
Add example: set-calculationoptionsenableiterativecalculation-to-true…
agent-aspose-cells-examples Jul 6, 2026
8d6ccc2
Add example: set-calculationoptionsmaxiterationcount-to-100-to-limit-…
agent-aspose-cells-examples Jul 6, 2026
a84ef43
Add example: set-calculationoptionsignoreerrorvalue-to-true-to-skip-e…
agent-aspose-cells-examples Jul 6, 2026
039e46b
Add example: enable-rounding-to-displayed-format-by-setting-calculati…
agent-aspose-cells-examples Jul 6, 2026
4d222d8
Add example: after-inserting-a-new-row-call-workbookcalculateformula-…
agent-aspose-cells-examples Jul 6, 2026
99d25d5
Add example: after-deleting-a-column-call-workbookcalculateformula-to…
agent-aspose-cells-examples Jul 6, 2026
2a15fd3
Add example: after-renaming-a-worksheet-call-workbookcalculateformula…
agent-aspose-cells-examples Jul 6, 2026
3eb53dd
Add example: after-applying-data-validation-call-workbookcalculatefor…
agent-aspose-cells-examples Jul 6, 2026
831c3e0
Add example: after-applying-conditional-formatting-call-workbookcalcu…
agent-aspose-cells-examples Jul 6, 2026
652e923
Add example: after-protecting-a-worksheet-call-workbookcalculateformu…
agent-aspose-cells-examples Jul 6, 2026
9c66082
Add example: set-calculationoptionscalculationmode-to-automatic-and-c…
agent-aspose-cells-examples Jul 6, 2026
3f1e39d
Add example: use-calculationoptions-to-ignore-errors-and-then-evaluat…
agent-aspose-cells-examples Jul 6, 2026
3a8f41a
Add example: register-the-custom-calculation-engine-with-the-workbook…
agent-aspose-cells-examples Jul 6, 2026
bb83ef0
Add example: assign-a-formula-that-calls-the-custom-function-to-a-tar…
agent-aspose-cells-examples Jul 6, 2026
bb49f86
Add example: call-workbookcalculate-to-evaluate-all-formulas-using-th…
agent-aspose-cells-examples Jul 6, 2026
7d6d408
Add example: add-multiple-cells-to-the-watch-window-in-a-loop-to-moni…
agent-aspose-cells-examples Jul 6, 2026
78e21c6
Add example: remove-a-cell-from-the-watch-window-programmatically-aft…
agent-aspose-cells-examples Jul 6, 2026
7a5cec0
Add example: retrieve-the-list-of-cells-currently-monitored-by-the-wa…
agent-aspose-cells-examples Jul 6, 2026
1338339
Add example: open-the-saved-workbook-in-excel-and-verify-that-the-spe…
agent-aspose-cells-examples Jul 6, 2026
68aecb8
Add example: resume-a-paused-calculation-session-and-verify-that-resu…
agent-aspose-cells-examples Jul 6, 2026
67a147a
Add example: trigger-manual-recalculation-only-for-cells-that-have-ch…
agent-aspose-cells-examples Jul 6, 2026
fe8f8da
Add example: use-cellcalculate-method-to-evaluate-a-single-cells-form…
agent-aspose-cells-examples Jul 6, 2026
03f6fc8
Add example: compare-results-of-cellcalculate-with-those-obtained-fro…
agent-aspose-cells-examples Jul 6, 2026
8da616f
Add example: generate-a-csv-file-containing-all-formulas-in-the-workb…
agent-aspose-cells-examples Jul 6, 2026
9187eef
Add example: filter-formulas-that-contain-specific-functions-such-as-…
agent-aspose-cells-examples Jul 6, 2026
2a64650
Add example: count-the-number-of-array-formulas-present-in-a-workshee…
agent-aspose-cells-examples Jul 6, 2026
58b09e3
Add example: identify-cells-that-participate-in-circular-references-a…
agent-aspose-cells-examples Jul 6, 2026
cee5b8f
Add example: highlight-cells-with-error-values-after-calculation-usin…
agent-aspose-cells-examples Jul 6, 2026
c0804ad
Add example: apply-conditional-formatting-based-on-formula-results-to…
agent-aspose-cells-examples Jul 6, 2026
218a08c
Add example: programmatically-clear-the-watch-window-before-adding-a-…
agent-aspose-cells-examples Jul 6, 2026
cd36bf9
Add example: serialize-the-watch-window-configuration-to-json-for-ext…
agent-aspose-cells-examples Jul 6, 2026
9efbbe9
Add example: register-a-custom-function-implementing-icustomfunction-…
agent-aspose-cells-examples Jul 6, 2026
60e9d26
Add example: add-a-custom-function-that-returns-the-user-name-registe…
agent-aspose-cells-examples Jul 6, 2026
2bc4051
Add example: create-a-subclass-of-abstractcalculationengine-that-over…
agent-aspose-cells-examples Jul 6, 2026
98227aa
Add example: register-the-custom-engine-via-workbooksettingscustomeng…
agent-aspose-cells-examples Jul 6, 2026
2ab9575
Add example: set-calculationoptionsprecision-to-a-higher-value-when-e…
agent-aspose-cells-examples Jul 6, 2026
fc2793a
Add example: switch-workbooksettingscalculationmode-to-manual-perform…
agent-aspose-cells-examples Jul 6, 2026
af2cc6c
Add example: set-calculationmode-to-semiautomatic-to-recalculate-only…
agent-aspose-cells-examples Jul 6, 2026
c39e393
Add example: disable-automatic-calculation-import-data-from-a-databas…
agent-aspose-cells-examples Jul 6, 2026
81f34cf
Add example: load-an-xlsx-workbook-from-a-file-path-and-set-calculati…
agent-aspose-cells-examples Jul 6, 2026
3610e41
Add example: set-the-workbooks-calculation-mode-to-automatic-for-imme…
agent-aspose-cells-examples Jul 6, 2026
cdab643
Add example: set-calculation-mode-to-automaticexcepttables-to-exclude…
agent-aspose-cells-examples Jul 6, 2026
fbc25bf
Add example: programmatically-disable-automatic-calculation-for-table…
agent-aspose-cells-examples Jul 6, 2026
014ad79
Add example: load-multiple-xlsx-files-from-a-directory-set-each-to-au…
agent-aspose-cells-examples Jul 6, 2026
be268e2
Add example: recalculate-all-formulas-using-workbookcalculateformula-…
agent-aspose-cells-examples Jul 6, 2026
21cdc5f
Add example: evaluate-a-single-cells-formula-with-cellcalculate-for-i…
agent-aspose-cells-examples Jul 6, 2026
179747d
Add example: implement-a-custom-worksheet-function-by-creating-a-clas…
agent-aspose-cells-examples Jul 6, 2026
9b7134a
Add example: register-the-icustomfunction-implementation-with-the-wor…
agent-aspose-cells-examples Jul 6, 2026
8fc0643
Add example: derive-a-custom-calculation-engine-from-abstractcalculat…
agent-aspose-cells-examples Jul 6, 2026
5c00e52
Add example: configure-the-custom-engine-to-log-each-cell-evaluation-…
agent-aspose-cells-examples Jul 6, 2026
b97245e
Add example: apply-a-custom-calculation-engine-that-substitutes-missi…
agent-aspose-cells-examples Jul 6, 2026
c2863ff
Add example: interrupt-an-ongoing-workbookcalculateformula-operation-…
agent-aspose-cells-examples Jul 6, 2026
0e068a5
Add example: generate-a-report-listing-all-cells-containing-volatile-…
agent-aspose-cells-examples Jul 6, 2026
bdf5625
Add example: validate-minifs-functions-return-correct-results-after-s…
agent-aspose-cells-examples Jul 6, 2026
0393814
Add example: verify-minifs-calculations-respect-filtered-rows-by-appl…
agent-aspose-cells-examples Jul 6, 2026
9d5fceb
Add example: measure-performance-difference-between-automatic-and-man…
agent-aspose-cells-examples Jul 6, 2026
e24954a
Add example: measure-memory-consumption-differences-between-automatic…
agent-aspose-cells-examples Jul 6, 2026
3f6a1d7
Add example: log-time-taken-for-each-cell-calculation-when-using-cell…
agent-aspose-cells-examples Jul 6, 2026
a11c034
Add example: create-a-utility-that-toggles-calculation-mode-based-on-…
agent-aspose-cells-examples Jul 6, 2026
3af1b9a
Add example: test-that-manual-calculation-mode-prevents-any-formula-e…
agent-aspose-cells-examples Jul 6, 2026
5dad027
Add example: create-a-commandline-tool-that-accepts-a-folder-path-rec…
agent-aspose-cells-examples Jul 6, 2026
f1c43ad
Add example: write-a-utility-that-iterates-through-all-worksheets-set…
agent-aspose-cells-examples Jul 6, 2026
8ec00dd
Add example: develop-a-plugin-that-replaces-the-default-calculation-e…
agent-aspose-cells-examples Jul 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using Aspose.Cells;

namespace AsposeCellsCustomFunctionDemo
{
// Custom calculation engine that implements the GETUSERNAME() function
public class UserNameEngine : AbstractCalculationEngine
{
// Called for each custom function during calculation
public override void Calculate(CalculationData data)
{
// Check if the function being evaluated is our custom function
if (data.FunctionName.Equals("GETUSERNAME", StringComparison.OrdinalIgnoreCase))
{
// Return the current Windows user name as the function result
data.CalculatedValue = Environment.UserName;
}
}

// Ensure the function is recalculated each time (useful for volatile data like user name)
public override bool ForceRecalculate(string functionName)
{
return functionName.Equals("GETUSERNAME", StringComparison.OrdinalIgnoreCase);
}
}

public class Program
{
public static void Main()
{
// Create a new workbook (lifecycle: create)
Workbook workbook = new Workbook();

// Access the first worksheet
Worksheet sheet = workbook.Worksheets[0];

// Place the custom function in cell A1
// The formula name must match the name used in the custom engine
sheet.Cells["A1"].Formula = "=GETUSERNAME()";

// Configure calculation options to use the custom engine
CalculationOptions options = new CalculationOptions
{
CustomEngine = new UserNameEngine()
};

// Perform calculation (invokes the custom function)
workbook.CalculateFormula(options);

// Retrieve and display the result
string userName = sheet.Cells["A1"].StringValue;
Console.WriteLine("Custom function result (User Name): " + userName);

// Audit log example – write to console (could be written to a file or DB)
Console.WriteLine($"[Audit] GETUSERNAME() evaluated at {DateTime.UtcNow:u} – Result: {userName}");

// Save the workbook (lifecycle: save)
workbook.Save("UserNameFunctionDemo.xlsx");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using Aspose.Cells;

namespace AsposeCellsWatchDemo
{
class Program
{
static void Main()
{
// Create a new workbook
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];

// Add watches for a batch of cells (A1 to A10) in a loop
for (int i = 0; i < 10; i++)
{
// Define the cell address (e.g., A1, A2, ...)
string cellName = $"A{i + 1}";

// Optionally set a formula in the cell to be monitored
sheet.Cells[cellName].Formula = $"=ROW()*2";

// Add the cell to the Watch Window
sheet.CellWatches.Add(cellName);
}

// Output the total number of watches added
Console.WriteLine($"Total watches added: {sheet.CellWatches.Count}");

// Save the workbook with the watch window configuration
workbook.Save("WatchWindowDemo.xlsx");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using Aspose.Cells;

namespace AsposeCellsConditionalFormattingDemo
{
class Program
{
static void Main()
{
// Create a new workbook (lifecycle rule: create)
Workbook workbook = new Workbook();

// Access the first worksheet
Worksheet sheet = workbook.Worksheets[0];
Cells cells = sheet.Cells;

// Populate sample data
cells["A1"].PutValue(10);
cells["A2"].PutValue(20);
cells["A3"].PutValue(30);
cells["B1"].Formula = "=A1*2"; // Formula that will be affected by conditional formatting
cells["B2"].Formula = "=A2*2";
cells["B3"].Formula = "=A3*2";

// Add a conditional formatting rule: highlight cells in column A between 15 and 25
int cfIndex = sheet.ConditionalFormattings.Add();
FormatConditionCollection fcc = sheet.ConditionalFormattings[cfIndex];

// Define the range A1:A3 for the conditional formatting
CellArea area = new CellArea
{
StartRow = 0,
StartColumn = 0,
EndRow = 2,
EndColumn = 0
};
fcc.AddArea(area);

// Add the condition (type: CellValue, operator: Between, formulas "15" and "25")
int conditionIdx = fcc.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "15", "25");
FormatCondition condition = fcc[conditionIdx];

// Set the style to be applied when the condition is met (e.g., red background)
Style style = workbook.CreateStyle();
style.ForegroundColor = System.Drawing.Color.Red;
style.Pattern = BackgroundType.Solid;
condition.Style = style;

// After setting up conditional formatting, recalculate all formulas
// This ensures that any formulas dependent on the formatted cells are updated
workbook.CalculateFormula();

// Save the workbook (lifecycle rule: save)
workbook.Save("ConditionalFormattingWithRecalc.xlsx");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using Aspose.Cells;

class Program
{
static void Main()
{
// Create a new workbook (lifecycle rule: create)
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
Cells cells = sheet.Cells;

// Sample data and a dependent formula
cells["A1"].PutValue(10); // Base value
cells["B1"].Formula = "=A1*2"; // Formula depends on A1

// Add data validation to cell C1 (whole number between 5 and 20)
Validation validation = sheet.Validations[sheet.Validations.Add()];
validation.Type = ValidationType.WholeNumber;
validation.Operator = OperatorType.Between;
validation.Formula1 = "5";
validation.Formula2 = "20";

// Apply the validation to cell C1
CellArea area = new CellArea
{
StartRow = 0, // Row 0 (A)
StartColumn = 2, // Column C
EndRow = 0,
EndColumn = 2
};
validation.AddArea(area);

// After applying validation, calculate all formulas (required step)
workbook.CalculateFormula();

// Display calculated results
Console.WriteLine("A1 value: " + cells["A1"].IntValue);
Console.WriteLine("B1 formula result: " + cells["B1"].IntValue);

// Save the workbook (lifecycle rule: save)
workbook.Save("Output.xlsx");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using Aspose.Cells;

class DeleteColumnAndRecalculate
{
static void Main()
{
// Create a new workbook
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
Cells cells = sheet.Cells;

// Add sample data
cells["A1"].PutValue(10);
cells["B1"].PutValue(20);
cells["C1"].PutValue(30);

// Formula that references the three columns
cells["D1"].Formula = "=SUM(A1:C1)";

// Delete column B (index 1) and update references in formulas
cells.DeleteColumn(1, true);

// Recalculate formulas after the column deletion
workbook.CalculateFormula();

// Save the modified workbook
workbook.Save("AfterDeleteColumn.xlsx");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using Aspose.Cells;

namespace AsposeCellsInsertRowAndRecalculate
{
class Program
{
static void Main()
{
// Create a new workbook (lifecycle rule: create)
Workbook workbook = new Workbook();

// Access the first worksheet and its cells collection
Worksheet sheet = workbook.Worksheets[0];
Cells cells = sheet.Cells;

// Populate some initial data and a formula that depends on the data
cells["A1"].PutValue(10); // Row 0
cells["A2"].PutValue(20); // Row 1 (will be shifted after insertion)
cells["A3"].Formula = "=A1+A2"; // Depends on A1 and A2

// Insert a new row at index 1 (between the original rows 0 and 1)
// This uses the Cells.InsertRow method rule
cells.InsertRow(1);

// After inserting the row, recalculate all formulas so that dependent
// cells (e.g., A3) reflect the new layout.
// This uses the Workbook.CalculateFormula method rule.
workbook.CalculateFormula();

// Save the workbook (lifecycle rule: save)
workbook.Save("InsertedRowWithRecalculatedFormulas.xlsx");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using Aspose.Cells;

namespace AsposeCellsProtectedFormulaDemo
{
class Program
{
static void Main(string[] args)
{
// Create a new workbook
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
Cells cells = sheet.Cells;

// Populate cells with values and a formula that depends on them
cells["A1"].PutValue(5); // Input value
cells["B1"].Formula = "=A1*2"; // Formula to calculate
cells["C1"].Formula = "=B1+10"; // Dependent formula

// Protect the worksheet with a password
sheet.Protect(ProtectionType.All, "myPassword", null);

// Verify protection status (optional)
Console.WriteLine($"Worksheet protected: {sheet.IsProtected}");

// Calculate all formulas in the workbook after protection
workbook.CalculateFormula();

// Display the calculated results
Console.WriteLine($"A1 value: {cells["A1"].IntValue}");
Console.WriteLine($"B1 formula result: {cells["B1"].IntValue}");
Console.WriteLine($"C1 formula result: {cells["C1"].IntValue}");

// Save the workbook (optional)
workbook.Save("ProtectedFormulaDemo.xlsx", SaveFormat.Xlsx);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using Aspose.Cells;

class Program
{
static void Main()
{
// Create a new workbook (lifecycle: create)
Workbook wb = new Workbook();

// Access the default first worksheet and give it an initial name
Worksheet sheet1 = wb.Worksheets[0];
sheet1.Name = "Data";

// Populate some data in the first worksheet
sheet1.Cells["A1"].PutValue(10);
sheet1.Cells["A2"].PutValue(20);

// Add a second worksheet that contains a formula referencing the first sheet
Worksheet sheet2 = wb.Worksheets.Add("Summary");
// Formula uses the sheet name "Data"
sheet2.Cells["B1"].Formula = "=Data!A1+Data!A2";

// Initial calculation so the formula has a value
wb.CalculateFormula();

Console.WriteLine("Before rename, B1 value: " + sheet2.Cells["B1"].Value);

// Rename the first worksheet
sheet1.Name = "RenamedData";

// Refresh all formulas after the rename operation
wb.CalculateFormula();

Console.WriteLine("After rename, B1 value: " + sheet2.Cells["B1"].Value);

// Save the workbook (lifecycle: save)
wb.Save("RenamedSheetDemo.xlsx");
}
}
Loading