From 5fa664c24d5146282aa6b48a1a09a409100bbc38 Mon Sep 17 00:00:00 2001 From: VinothSF5015 Date: Sun, 26 Apr 2026 17:25:21 +0530 Subject: [PATCH 1/2] 1017887 - Content Added --- Document-Processing-toc.html | 3 + ...alculate-after-moving-or-copying-ranges.md | 98 +++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 Document-Processing/Excel/Excel-Library/NET/faqs/how-to-ensure-formulas-recalculate-after-moving-or-copying-ranges.md diff --git a/Document-Processing-toc.html b/Document-Processing-toc.html index 2027461d5..fc6ee7d78 100644 --- a/Document-Processing-toc.html +++ b/Document-Processing-toc.html @@ -6668,6 +6668,9 @@
  • How to retrieve the name of the chart in an Excel worksheet?
  • +
  • + How to ensure formulas recalculate after moving or copying ranges? +
  • diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-ensure-formulas-recalculate-after-moving-or-copying-ranges.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-ensure-formulas-recalculate-after-moving-or-copying-ranges.md new file mode 100644 index 000000000..7df2cd588 --- /dev/null +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-ensure-formulas-recalculate-after-moving-or-copying-ranges.md @@ -0,0 +1,98 @@ +--- +title: Formulas recalculate after moving or copying ranges | Syncfusion +description: Explains why formulas may not recalculate after a move or copy operation in XlsIO and shows how to clear the CalcEngine formula info table to force recalculation. +platform: document-processing +control: XlsIO +documentation: UG +--- + +# How to ensure formulas recalculate after moving or copying ranges? + +When moving or copying a range containing formulas, the formula text may remain unchanged even though dependent cell values change. Since the formula cell itself is not modified, XlsIO's CalcEngine does not automatically recalculate and instead returns the previously stored calculated value. + +To force recalculation after move or copy operations, clear the `FormulaInfoTable` from `CalcEngine`. This ensures formulas are reevaluated when their calculated value is accessed. + +The following code example demonstrates the required workaround. + +{% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet worksheet = workbook.Worksheets[0]; + + // Set up sample data + worksheet["A1"].Value2 = 10; + worksheet["A2"].Value2 = 20; + worksheet["A3"].Value2 = 30; + + // Create formulas + worksheet["B1"].Formula = "=A1*2"; + worksheet["B2"].Formula = "=A2*2"; + worksheet["B3"].Formula = "=A3*2"; + + // Move range B1:B3 to C1:C3 + worksheet["B1:B3"].MoveTo(worksheet["C1:C3"]); + + // Clear the formula info table to ensure dependent formulas recalculate + worksheet.CalcEngine.FormulaInfoTable.Clear(); + + // Now the formulas will recalculate correctly when their values are accessed + workbook.SaveAs(Path.GetFullPath(@"Output/Output.xlsx")); +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + excelEngine.Excel.DefaultVersion = ExcelVersion.Excel2016; + IWorkbook workbook = excelEngine.Excel.Workbooks.Create(1); + IWorksheet worksheet = workbook.Worksheets[0]; + + worksheet["A1"].Value2 = 10; + worksheet["A2"].Value2 = 20; + worksheet["A3"].Value2 = 30; + + worksheet["B1"].Formula = "=A1*2"; + worksheet["B2"].Formula = "=A2*2"; + worksheet["B3"].Formula = "=A3*2"; + + worksheet.EnableSheetCalculations(); + // Move the range + worksheet["B1:B3"].MoveTo(worksheet["C1:C3"]); + + // Clear formula cache to force recalculation + worksheet.CalcEngine.FormulaInfoTable.Clear(); + + workbook.SaveAs("Output.xlsx"); +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Using excelEngine As New ExcelEngine() + excelEngine.Excel.DefaultVersion = ExcelVersion.Excel2016 + Dim workbook As IWorkbook = excelEngine.Excel.Workbooks.Create(1) + Dim worksheet As IWorksheet = workbook.Worksheets(0) + + worksheet("A1").Value2 = 10 + worksheet("A2").Value2 = 20 + worksheet("A3").Value2 = 30 + + worksheet("B1").Formula = "=A1*2" + worksheet("B2").Formula = "=A2*2" + worksheet("B3").Formula = "=A3*2" + + worksheet.EnableSheetCalculations() + ' Move the range + worksheet("B1:B3").MoveTo(worksheet("C1:C3")) + + ' Clear formula cache to force recalculation + worksheet.CalcEngine.FormulaInfoTable.Clear() + + workbook.SaveAs("Output.xlsx") +End Using +{% endhighlight %} +{% endtabs %} + +A complete working example in C# is present on this GitHub page. \ No newline at end of file From 1c37023637409ffd5dd2ca87bf94559599845b7e Mon Sep 17 00:00:00 2001 From: VinothSF5015 Date: Sun, 26 Apr 2026 17:33:57 +0530 Subject: [PATCH 2/2] Update description for formula recalculation guidance --- ...ure-formulas-recalculate-after-moving-or-copying-ranges.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-ensure-formulas-recalculate-after-moving-or-copying-ranges.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-ensure-formulas-recalculate-after-moving-or-copying-ranges.md index 7df2cd588..d695b5717 100644 --- a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-ensure-formulas-recalculate-after-moving-or-copying-ranges.md +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-ensure-formulas-recalculate-after-moving-or-copying-ranges.md @@ -1,6 +1,6 @@ --- title: Formulas recalculate after moving or copying ranges | Syncfusion -description: Explains why formulas may not recalculate after a move or copy operation in XlsIO and shows how to clear the CalcEngine formula info table to force recalculation. +description: Explains why formulas may not recalculate after moving or copying in XlsIO and how clearing the CalcEngine formula info table forces recalculation. platform: document-processing control: XlsIO documentation: UG @@ -95,4 +95,4 @@ End Using {% endhighlight %} {% endtabs %} -A complete working example in C# is present on this GitHub page. \ No newline at end of file +A complete working example in C# is present on this GitHub page.