Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
143 commits
Select commit Hold shift + click to select a range
298d67b
Add example: load-a-workbook-from-a-file-stream-modify-cells-then-cal…
agent-aspose-cells-examples May 23, 2026
69c8842
Add example: load-a-workbook-from-a-memory-stream-change-a-formula-an…
agent-aspose-cells-examples May 23, 2026
83111e1
Add example: create-a-class-implementing-icustomfunction-and-override…
agent-aspose-cells-examples May 23, 2026
be15bd2
Add example: use-referredareagetvaluerowoffset-coloffset-to-obtain-a-…
agent-aspose-cells-examples May 23, 2026
3eca038
Add example: use-referredareagetvalues-to-retrieve-a-twodimensional-a…
agent-aspose-cells-examples May 23, 2026
1b421af
Add example: return-a-scalar-numeric-result-from-a-custom-function-af…
agent-aspose-cells-examples May 23, 2026
4cc625e
Add example: return-a-twodimensional-object-array-from-a-custom-funct…
agent-aspose-cells-examples May 23, 2026
6e5b1fa
Add example: replace-icustomfunction-implementation-with-an-abstractc…
agent-aspose-cells-examples May 23, 2026
5bf50e7
Add example: create-a-class-derived-from-abstractcalculationmonitor-a…
agent-aspose-cells-examples May 23, 2026
dfb9fd3
Add example: in-beforecalculate-call-interrupt-when-a-specific-cell-a…
agent-aspose-cells-examples May 23, 2026
e1def48
Add example: assign-a-custom-monitor-instance-to-calculationoptionsca…
agent-aspose-cells-examples May 23, 2026
f795d40
Add example: set-calculationoptionscalculationmode-to-manual-before-i…
agent-aspose-cells-examples May 23, 2026
527af67
Add example: invoke-workbookcalculateformulacalculationoptions-to-rec…
agent-aspose-cells-examples May 23, 2026
761aa05
Add example: evaluate-the-builtin-ifna-function-by-writing-ifnaa1-fal…
agent-aspose-cells-examples May 23, 2026
c17fabe
Add example: use-workbookcalculateformula-without-options-to-compute-…
agent-aspose-cells-examples May 23, 2026
ce8ea9c
Add example: set-calculationoptionsenableiterativecalculation-to-true…
agent-aspose-cells-examples May 23, 2026
8ecfeba
Add example: set-calculationoptionsmaxiterationcount-to-100-to-limit-…
agent-aspose-cells-examples May 23, 2026
085afe3
Add example: set-calculationoptionsconvergencethreshold-to-0001-to-de…
agent-aspose-cells-examples May 23, 2026
abd7da5
Add example: set-calculationoptionsignoreerrorvalue-to-true-to-skip-e…
agent-aspose-cells-examples May 23, 2026
81a161e
Add example: set-calculationoptionstreattextaszero-to-true-to-convert…
agent-aspose-cells-examples May 23, 2026
ec86865
Add example: limit-calculation-threads-by-setting-calculationoptionst…
agent-aspose-cells-examples May 23, 2026
0565030
Add example: enable-rounding-to-displayed-format-by-setting-calculati…
agent-aspose-cells-examples May 23, 2026
e64138a
Add example: use-calculationoptionsuse1904datesystem-true-to-calculat…
agent-aspose-cells-examples May 23, 2026
2e4b492
Add example: after-inserting-a-new-row-call-workbookcalculateformula-…
agent-aspose-cells-examples May 23, 2026
c8c5cf4
Add example: after-deleting-a-column-call-workbookcalculateformula-to…
agent-aspose-cells-examples May 23, 2026
3e5fc74
Add example: after-renaming-a-worksheet-call-workbookcalculateformula…
agent-aspose-cells-examples May 23, 2026
3686e9d
Add example: after-updating-a-named-range-call-workbookcalculateformu…
agent-aspose-cells-examples May 23, 2026
62ed549
Add example: after-applying-data-validation-call-workbookcalculatefor…
agent-aspose-cells-examples May 23, 2026
a003498
Add example: after-applying-conditional-formatting-call-workbookcalcu…
agent-aspose-cells-examples May 23, 2026
aba01cf
Add example: after-protecting-a-worksheet-call-workbookcalculateformu…
agent-aspose-cells-examples May 23, 2026
def7d5f
Add example: after-unprotecting-a-worksheet-call-workbookcalculatefor…
agent-aspose-cells-examples May 23, 2026
ce1e31d
Add example: set-calculationoptionscalculationmode-to-automatic-and-c…
agent-aspose-cells-examples May 23, 2026
54efce8
Add example: use-calculationoptions-to-ignore-errors-and-then-evaluat…
agent-aspose-cells-examples May 23, 2026
656bc2f
Add example: use-calculationoptions-to-treat-empty-cells-as-zero-and-…
agent-aspose-cells-examples May 23, 2026
d72d657
Add example: register-the-custom-calculation-engine-with-the-workbook…
agent-aspose-cells-examples May 23, 2026
1a3daab
Add example: assign-a-formula-that-calls-the-custom-function-to-a-tar…
agent-aspose-cells-examples May 23, 2026
596810e
Add example: call-workbookcalculate-to-evaluate-all-formulas-using-th…
agent-aspose-cells-examples May 23, 2026
65260e4
Add example: retrieve-the-range-of-values-returned-by-the-custom-func…
agent-aspose-cells-examples May 23, 2026
151c118
Add example: add-a-specific-cell-to-the-formula-watch-window-using-wo…
agent-aspose-cells-examples May 23, 2026
3f4feec
Add example: add-multiple-cells-to-the-watch-window-in-a-loop-to-moni…
agent-aspose-cells-examples May 23, 2026
317994b
Add example: remove-a-cell-from-the-watch-window-programmatically-aft…
agent-aspose-cells-examples May 23, 2026
14ff650
Add example: retrieve-the-list-of-cells-currently-monitored-by-the-wa…
agent-aspose-cells-examples May 23, 2026
47e03ce
Add example: save-the-workbook-to-an-excel-file-after-configuring-the…
agent-aspose-cells-examples May 23, 2026
eea0996
Add example: open-the-saved-workbook-in-excel-and-verify-that-the-spe…
agent-aspose-cells-examples May 23, 2026
1d598b0
Add example: use-formulatext-to-obtain-the-exact-textual-representati…
agent-aspose-cells-examples May 23, 2026
a0680e9
Add example: write-a-formula-to-a-cell-and-store-its-text-in-another-…
agent-aspose-cells-examples May 23, 2026
7236b82
Add example: apply-formulatext-on-a-range-of-cells-to-extract-each-fo…
agent-aspose-cells-examples May 23, 2026
de2d764
Add example: compare-formula-text-before-and-after-modification-to-en…
agent-aspose-cells-examples May 23, 2026
a40e3e5
Add example: enable-circularreference-detection-in-workbook-calculati…
agent-aspose-cells-examples May 23, 2026
976fa6c
Add example: detect-circular-references-during-formula-evaluation-and…
agent-aspose-cells-examples May 23, 2026
662d87f
Add example: set-the-workbooks-formula-calculation-mode-to-manual-for…
agent-aspose-cells-examples May 23, 2026
328cae3
Add example: configure-the-workbook-to-use-automatic-calculation-mode…
agent-aspose-cells-examples May 23, 2026
3f539b5
Add example: interrupt-an-ongoing-workbookcalculate-operation-using-c…
agent-aspose-cells-examples May 23, 2026
1cceeda
Add example: use-a-cancellation-token-with-workbookcalculate-to-abort…
agent-aspose-cells-examples May 23, 2026
04e8689
Add example: optimize-custom-function-logic-to-reduce-execution-time-…
agent-aspose-cells-examples May 23, 2026
944f3c9
Add example: cache-results-of-a-custom-function-to-improve-performanc…
agent-aspose-cells-examples May 23, 2026
8aea9fb
Add example: invalidate-cached-custom-function-results-automatically-…
agent-aspose-cells-examples May 23, 2026
00f95dc
Add example: implement-icustomfunction-interface-to-create-a-custom-f…
agent-aspose-cells-examples May 23, 2026
e1e47ae
Add example: return-a-twodimensional-array-from-a-custom-function-to-…
agent-aspose-cells-examples May 23, 2026
cc6ef05
Add example: apply-a-custom-function-within-an-array-formula-to-compu…
agent-aspose-cells-examples May 23, 2026
936440d
Add example: calculate-an-array-formula-for-a-data-table-that-aggrega…
agent-aspose-cells-examples May 23, 2026
a705fd3
Add example: validate-array-formula-syntax-programmatically-before-tr…
agent-aspose-cells-examples May 23, 2026
24d287b
Add example: set-iterative-calculation-settings-including-maximum-ite…
agent-aspose-cells-examples May 23, 2026
7c3e76e
Add example: enable-iterative-calculation-for-circular-references-and…
agent-aspose-cells-examples May 23, 2026
2aeebe7
Add example: log-each-step-of-formula-evaluation-using-custom-callbac…
agent-aspose-cells-examples May 23, 2026
a1ea369
Add example: subscribe-to-calculation-engine-events-to-monitor-progre…
agent-aspose-cells-examples May 23, 2026
95d048b
Add example: implement-a-progress-callback-that-reports-percentage-co…
agent-aspose-cells-examples May 23, 2026
91b6949
Add example: pause-calculation-after-a-predefined-time-threshold-and-…
agent-aspose-cells-examples May 23, 2026
889ba1a
Add example: resume-a-paused-calculation-session-and-verify-that-resu…
agent-aspose-cells-examples May 23, 2026
d965a5e
Add example: disable-automatic-recalculation-in-workbook-settings-to-…
agent-aspose-cells-examples May 23, 2026
5972a52
Add example: trigger-manual-recalculation-only-for-cells-that-have-ch…
agent-aspose-cells-examples May 23, 2026
2e56a9b
Add example: use-cellcalculate-method-to-evaluate-a-single-cells-form…
agent-aspose-cells-examples May 23, 2026
b07ded0
Add example: compare-results-of-cellcalculate-with-those-obtained-fro…
agent-aspose-cells-examples May 23, 2026
fa7e2ab
Add example: generate-a-csv-file-containing-all-formulas-in-the-workb…
agent-aspose-cells-examples May 23, 2026
995c974
Add example: filter-formulas-that-contain-specific-functions-such-as-…
agent-aspose-cells-examples May 23, 2026
c09711b
Add example: count-the-number-of-array-formulas-present-in-a-workshee…
agent-aspose-cells-examples May 23, 2026
de6f93b
Add example: identify-cells-that-participate-in-circular-references-a…
agent-aspose-cells-examples May 23, 2026
da05b3e
Add example: highlight-cells-with-error-values-after-calculation-usin…
agent-aspose-cells-examples May 23, 2026
ea7c359
Add example: apply-conditional-formatting-based-on-formula-results-to…
agent-aspose-cells-examples May 23, 2026
fa77580
Add example: programmatically-clear-the-watch-window-before-adding-a-…
agent-aspose-cells-examples May 23, 2026
c17d92c
Add example: serialize-the-watch-window-configuration-to-json-for-ext…
agent-aspose-cells-examples May 23, 2026
bf88a77
Add example: load-a-previously-saved-watch-window-configuration-and-a…
agent-aspose-cells-examples May 23, 2026
1d2ea3c
Add example: use-a-custom-function-to-perform-a-lookup-across-multipl…
agent-aspose-cells-examples May 23, 2026
f152131
Add example: implement-a-class-inheriting-abstractcalculationmonitor-…
agent-aspose-cells-examples May 23, 2026
e3633c9
Add example: assign-the-custom-monitor-to-workbooksettingscalculation…
agent-aspose-cells-examples May 23, 2026
c70f25d
Add example: trigger-circular-reference-detection-by-invoking-workboo…
agent-aspose-cells-examples May 23, 2026
37cba43
Add example: use-calculationcell-objects-from-oncircular-to-extract-r…
agent-aspose-cells-examples May 23, 2026
084a3cd
Add example: configure-calculationoptionsignoreerror-to-true-when-eva…
agent-aspose-cells-examples May 23, 2026
1ac74a6
Add example: capture-calculation-errors-by-setting-calculationoptions…
agent-aspose-cells-examples May 23, 2026
bdb1899
Add example: enable-iterative-calculation-by-setting-calculationoptio…
agent-aspose-cells-examples May 23, 2026
d564245
Add example: test-iterative-calculation-stability-by-configuring-calc…
agent-aspose-cells-examples May 23, 2026
d46ca88
Add example: use-worksheetcalculateformula-with-a-custom-calculationo…
agent-aspose-cells-examples May 23, 2026
540d34a
Add example: register-a-custom-function-implementing-icustomfunction-…
agent-aspose-cells-examples May 23, 2026
1730458
Add example: add-a-custom-function-that-returns-the-user-name-registe…
agent-aspose-cells-examples May 23, 2026
b804288
Add example: create-a-subclass-of-abstractcalculationengine-that-over…
agent-aspose-cells-examples May 23, 2026
88f5759
Add example: register-the-custom-engine-via-workbooksettingscustomeng…
agent-aspose-cells-examples May 23, 2026
e96fb9f
Add example: in-the-overridden-calculate-method-fallback-to-basecalcu…
agent-aspose-cells-examples May 23, 2026
5cea990
Add example: implement-a-custom-engine-that-caches-intermediate-resul…
agent-aspose-cells-examples May 23, 2026
da0b9cc
Add example: provide-a-public-method-to-clear-the-custom-engines-cach…
agent-aspose-cells-examples May 23, 2026
579250f
Add example: verify-workbooksettingscustomengine-is-null-after-resett…
agent-aspose-cells-examples May 23, 2026
21605b6
Add example: set-calculationoptionsprecision-to-a-higher-value-when-e…
agent-aspose-cells-examples May 23, 2026
b226398
Add example: switch-workbooksettingscalculationmode-to-manual-perform…
agent-aspose-cells-examples May 23, 2026
04b2d69
Add example: set-calculationmode-to-semiautomatic-to-recalculate-only…
agent-aspose-cells-examples May 23, 2026
8f6155e
Add example: disable-automatic-calculation-import-data-from-a-databas…
agent-aspose-cells-examples May 23, 2026
bbd1677
Add example: programmatically-disable-automatic-calculation-import-a-…
agent-aspose-cells-examples May 23, 2026
e4a26ac
Add example: improve-performance-by-setting-workbooksettingsenablefas…
agent-aspose-cells-examples May 23, 2026
32e1f05
Add example: reduce-overhead-in-simple-workbooks-by-setting-workbooks…
agent-aspose-cells-examples May 23, 2026
8818d99
Add example: iterate-through-each-worksheet-enable-fast-formula-calcu…
agent-aspose-cells-examples May 23, 2026
f8645d5
Add example: create-a-benchmark-measuring-cellcalculate-latency-with-…
agent-aspose-cells-examples May 23, 2026
6e674f8
Add example: compare-memory-consumption-of-default-versus-custom-calc…
agent-aspose-cells-examples May 23, 2026
11c2d7a
Add example: create-a-test-suite-verifying-custom-engine-correctly-ov…
agent-aspose-cells-examples May 23, 2026
b8b9c83
Add example: write-a-utility-that-enumerates-all-worksheets-sets-calc…
agent-aspose-cells-examples May 23, 2026
db35a79
Add example: demonstrate-worksheetcalculateformula-with-a-formula-ref…
agent-aspose-cells-examples May 23, 2026
fa783d8
Add example: load-an-xlsx-workbook-from-a-file-path-and-set-calculati…
agent-aspose-cells-examples May 23, 2026
24e4024
Add example: set-the-workbooks-calculation-mode-to-automatic-for-imme…
agent-aspose-cells-examples May 23, 2026
93e7fb3
Add example: set-calculation-mode-to-automaticexcepttables-to-exclude…
agent-aspose-cells-examples May 23, 2026
f2510e2
Add example: programmatically-disable-automatic-calculation-for-table…
agent-aspose-cells-examples May 23, 2026
62dc33c
Add example: load-multiple-xlsx-files-from-a-directory-set-each-to-au…
agent-aspose-cells-examples May 23, 2026
5525add
Add example: recalculate-all-formulas-using-workbookcalculateformula-…
agent-aspose-cells-examples May 23, 2026
62db2ee
Add example: implement-a-custom-worksheet-function-by-creating-a-clas…
agent-aspose-cells-examples May 23, 2026
4b1817a
Add example: derive-a-custom-calculation-engine-from-abstractcalculat…
agent-aspose-cells-examples May 23, 2026
06cb1c1
Add example: configure-the-custom-engine-to-log-each-cell-evaluation-…
agent-aspose-cells-examples May 23, 2026
e5e86ae
Add example: apply-a-custom-calculation-engine-that-substitutes-missi…
agent-aspose-cells-examples May 23, 2026
7880eb4
Add example: interrupt-an-ongoing-workbookcalculateformula-operation-…
agent-aspose-cells-examples May 23, 2026
1a1d31f
Add example: implement-a-cancellation-token-that-stops-formula-calcul…
agent-aspose-cells-examples May 23, 2026
4aa9a1e
Add example: handle-calculationexception-during-formula-recalculation…
agent-aspose-cells-examples May 23, 2026
dccb444
Add example: extract-and-log-the-formula-dependency-graph-after-calli…
agent-aspose-cells-examples May 23, 2026
a153138
Add example: implement-a-logger-that-records-the-order-of-formula-eva…
agent-aspose-cells-examples May 23, 2026
4795f14
Add example: generate-a-report-listing-all-cells-containing-volatile-…
agent-aspose-cells-examples May 23, 2026
86710c9
Add example: validate-minifs-functions-return-correct-results-after-s…
agent-aspose-cells-examples May 23, 2026
9904ccf
Add example: verify-minifs-calculations-respect-filtered-rows-by-appl…
agent-aspose-cells-examples May 23, 2026
e2fb610
Add example: compare-maxifs-calculation-accuracy-between-default-engi…
agent-aspose-cells-examples May 23, 2026
e018c88
Add example: measure-performance-difference-between-automatic-and-man…
agent-aspose-cells-examples May 23, 2026
7ea1bed
Add example: measure-memory-consumption-differences-between-automatic…
agent-aspose-cells-examples May 23, 2026
d6e6e42
Add example: log-time-taken-for-each-cell-calculation-when-using-cell…
agent-aspose-cells-examples May 23, 2026
0a061d1
Add example: create-a-utility-that-toggles-calculation-mode-based-on-…
agent-aspose-cells-examples May 23, 2026
c08f28f
Add example: test-that-automaticexcepttables-mode-does-not-recalculat…
agent-aspose-cells-examples May 23, 2026
58e3d49
Add example: test-that-manual-calculation-mode-prevents-any-formula-e…
agent-aspose-cells-examples May 23, 2026
d5a05b7
Add example: create-a-batch-process-that-loads-workbooks-applies-a-cu…
agent-aspose-cells-examples May 23, 2026
db60e98
Add example: create-a-commandline-tool-that-accepts-a-folder-path-rec…
agent-aspose-cells-examples May 23, 2026
ca92e84
Add example: write-a-utility-that-iterates-through-all-worksheets-set…
agent-aspose-cells-examples May 23, 2026
d1ebf1c
Add example: develop-a-plugin-that-replaces-the-default-calculation-e…
agent-aspose-cells-examples May 23, 2026
ffac338
Add example: implement-a-routine-that-clears-all-cached-calculation-r…
agent-aspose-cells-examples May 23, 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,63 @@
using System;
using Aspose.Cells;

namespace AsposeCellsCustomFunctionDemo
{
// Custom calculation engine that implements a function returning the current user name
public class UserNameEngine : AbstractCalculationEngine
{
// Called for each custom function encountered during calculation
public override void Calculate(CalculationData data)
{
// Check if the function name matches our custom function (case‑insensitive)
if (data.FunctionName.Equals("GETUSERNAME", StringComparison.OrdinalIgnoreCase))
{
// Return the Windows user name as the calculated value
data.CalculatedValue = Environment.UserName;
}
}

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

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

// Place the custom function in cell A1
cells["A1"].Formula = "=GETUSERNAME()";

// Set up calculation options to use our custom engine
CalculationOptions options = new CalculationOptions
{
CustomEngine = new UserNameEngine()
};

// Perform calculation
workbook.CalculateFormula(options);

// Retrieve the result (the user name)
string userName = cells["A1"].StringValue;

// Write the audit log entry to cell B1
cells["B1"].PutValue($"Audit: Formula evaluated by user '{userName}' at {DateTime.Now}");

// Optional: demonstrate detection of custom functions
Console.WriteLine($"Cell A1 has custom function: {cells["A1"].HasCustomFunction}");
Console.WriteLine($"Workbook has custom function: {workbook.HasCustomFunction}");
Console.WriteLine($"Calculated user name: {userName}");

// Save the workbook (using the standard save rule)
workbook.Save("UserNameCustomFunction.xlsx", SaveFormat.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();

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

// Set a formula in cell A1 (e.g., sum of B1 and C1)
sheet.Cells["A1"].Formula = "=SUM(B1,C1)";

// Optionally put some values in B1 and C1 for the formula to calculate
sheet.Cells["B1"].PutValue(10);
sheet.Cells["C1"].PutValue(20);

// Add the cell to the Formula Watch Window using its address
int watchIndex = sheet.CellWatches.Add("A1");

// Retrieve the added CellWatch (optional, just to demonstrate access)
CellWatch watch = sheet.CellWatches[watchIndex];
Console.WriteLine($"Added watch for cell: {watch.CellName} (Row={watch.Row}, Column={watch.Column})");

// Save the workbook to a file
workbook.Save("FormulaWatchDemo.xlsx");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using Aspose.Cells;

namespace AsposeCellsWatchWindowDemo
{
class Program
{
static void Main()
{
// Create a new workbook (using the standard creation rule)
Workbook workbook = new Workbook();

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

// Populate some sample formulas in column A (A1:A10)
for (int i = 0; i < 10; i++)
{
// Example formula: each cell sums its row number with a constant
sheet.Cells[i, 0].Formula = $"=ROW()+5";
}

// Get the CellWatchCollection for the worksheet
CellWatchCollection watches = sheet.CellWatches;

// Add watches for the range A1:A10 using a loop
for (int row = 0; row < 10; row++)
{
// Convert row index to cell name (e.g., A1, A2, ...)
string cellName = CellsHelper.CellIndexToName(row, 0);
watches.Add(cellName);
}

// Display the total number of watches added
Console.WriteLine($"Total Cell Watches added: {watches.Count}");

// Optionally, iterate and print each watched cell name
foreach (CellWatch watch in watches)
{
Console.WriteLine($"Watching cell: {watch.CellName}");
}

// Save the workbook (using the standard save rule)
workbook.Save("WatchWindowDemo.xlsx");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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 that will be used by the conditional format
cells["A1"].PutValue(5);
cells["A2"].PutValue(15);
cells["A3"].PutValue(25);
cells["A4"].PutValue(35);
cells["A5"].PutValue(45);

// Add a conditional formatting collection to the worksheet
int cfIndex = sheet.ConditionalFormattings.Add();
FormatConditionCollection fcc = sheet.ConditionalFormattings[cfIndex];

// Define the range to which the conditional formatting will be applied (A1:A5)
CellArea area = new CellArea
{
StartRow = 0,
StartColumn = 0,
EndRow = 4,
EndColumn = 0
};
fcc.AddArea(area);

// Add a condition: highlight cells with values between 10 and 30 (inclusive)
int conditionIdx = fcc.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "10", "30");
FormatCondition condition = fcc[conditionIdx];

// Set the style for the condition (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 formulas
// (ensures any formulas that depend 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,83 @@
using System;
using System.IO;
using Aspose.Cells;

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

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

// -------------------------------------------------
// Set up sample data and formulas
// -------------------------------------------------
// Cell A1 will hold a base value
cells["A1"].PutValue(10);

// Cell B1 contains a formula that depends on A1
cells["B1"].Formula = "=A1*2";

// -------------------------------------------------
// Add data validation to cell A1 (must be between 5 and 20)
// -------------------------------------------------
// Define the area (cell A1) to which the validation applies
CellArea area = new CellArea
{
StartRow = 0,
StartColumn = 0,
EndRow = 0,
EndColumn = 0
};

// Add a new validation for the defined area.
// In older Aspose.Cells versions Add returns the index of the validation.
int validationIndex = sheet.Validations.Add(area);
Validation validation = sheet.Validations[validationIndex];

// Configure the validation rule
validation.Type = ValidationType.WholeNumber;
validation.Operator = OperatorType.Between;
validation.Formula1 = "5"; // Minimum value
validation.Formula2 = "20"; // Maximum value

// -------------------------------------------------
// After setting validation, calculate all formulas
// -------------------------------------------------
workbook.CalculateFormula();

// -------------------------------------------------
// Output the results to verify calculation
// -------------------------------------------------
Console.WriteLine("A1 (validated value) : " + cells["A1"].IntValue);
Console.WriteLine("B1 (formula result) : " + cells["B1"].IntValue);

// Save the workbook (lifecycle rule: save)
string outputPath = "DataValidationAndCalculate.xlsx";

// Ensure the directory exists before saving
string outputDir = Path.GetDirectoryName(Path.GetFullPath(outputPath));
if (!Directory.Exists(outputDir))
{
Directory.CreateDirectory(outputDir);
}

workbook.Save(outputPath, SaveFormat.Xlsx);
Console.WriteLine($"Workbook saved to '{Path.GetFullPath(outputPath)}'.");
}
catch (Exception ex)
{
// Log any unexpected errors
Console.WriteLine("An error occurred: " + ex.Message);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System;
using System.IO;
using Aspose.Cells;

namespace AsposeCellsExamples
{
public class DeleteColumnAndRecalculateDemo
{
public static void Run()
{
try
{
// Create a new workbook
Workbook workbook = new Workbook();

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

// Populate sample data in columns A and B
cells["A1"].PutValue(10);
cells["B1"].PutValue(20);
cells["A2"].PutValue(30);
cells["B2"].PutValue(40);

// Add a formula that sums the values in column A and B
cells["C1"].Formula = "=SUM(A1:B2)";

// Calculate formulas before deletion (optional, just to show initial state)
workbook.CalculateFormula();

Console.WriteLine("Before deleting column:");
Console.WriteLine($"C1 formula result: {cells["C1"].Value}");

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

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

Console.WriteLine("After deleting column B:");
Console.WriteLine($"C1 formula: {cells["C1"].Formula}");
Console.WriteLine($"C1 formula result: {cells["C1"].Value}");

// Define output file path
string outputPath = "DeleteColumnAndRecalculateDemo.xlsx";

// Ensure the output directory exists
string directory = Path.GetDirectoryName(Path.GetFullPath(outputPath));
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}

// Save the workbook
workbook.Save(outputPath);
Console.WriteLine($"Workbook saved to {outputPath}");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}

// Application entry point
public class Program
{
public static void Main(string[] args)
{
DeleteColumnAndRecalculateDemo.Run();
}
}
}
Loading