From 94d347b27ea103dc5721750227a559eec021c32d Mon Sep 17 00:00:00 2001 From: VinothSF5015 Date: Tue, 12 May 2026 17:23:49 +0530 Subject: [PATCH 1/3] 1017888 - Content Added --- Document-Processing-toc.html | 3 + ...ences-when-retrieving-calculated-values.md | 120 ++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 Document-Processing/Excel/Excel-Library/NET/faqs/how-to-handle-circular-references-when-retrieving-calculated-values.md diff --git a/Document-Processing-toc.html b/Document-Processing-toc.html index 610dc233e..b564a7b5a 100644 --- a/Document-Processing-toc.html +++ b/Document-Processing-toc.html @@ -6805,6 +6805,9 @@
  • How to merge cells preserving topleft value and format in XlsIO?
  • +
  • + How to handle circular references when retrieving calculated values? +
  • diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-handle-circular-references-when-retrieving-calculated-values.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-handle-circular-references-when-retrieving-calculated-values.md new file mode 100644 index 000000000..663271ee2 --- /dev/null +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-handle-circular-references-when-retrieving-calculated-values.md @@ -0,0 +1,120 @@ +--- +title: How to handle circular references when retrieving calculated values? | Syncfusion +description: This FAQ explains how to handle circular references in Excel formulas when retrieving calculated values using Syncfusion XlsIO's calculation engine properties. +platform: document-processing +control: XlsIO +documentation: UG +--- + +# How to handle circular references when retrieving calculated values? + +Circular references occur when a formula refers back to one of its own cells, creating a loop that Excel must resolve through iteration. XlsIO provides properties in the [CalcEngine](https://help.syncfusion.com/cr/document-processing/Syncfusion.XlsIO.ICalcEngine.html) to control how circular references are handled, including enabling iteration, setting maximum iteration count, and configuring exception handling. + +The following code example illustrates how to enable circular reference handling and retrieve calculated values. + +{% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + // Create a new Excel application instance + IApplication application = excelEngine.Excel; + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath("Data/InputTemplate.xlsx")); + + foreach (IWorksheet worksheetxls in workbook.Worksheets) + { + // Enable sheet calculations to compute formula values + worksheetxls.EnableSheetCalculations(); + + // Configure calculation engine for circular reference handling + worksheetxls.CalcEngine.AllowShortCircuitIFs = true; + worksheetxls.CalcEngine.UseFormulaValues = true; + + // Enable circular reference handling with exception throwing + worksheetxls.CalcEngine.ThrowCircularException = true; + + // Set maximum iteration count for resolving circular references + worksheetxls.CalcEngine.IterationMaxCount = 1000; + } + + // Access the first worksheet to retrieve calculated values + IWorksheet worksheet = workbook.Worksheets.First(); + + // Display the calculated values from cells I234 and J234 + Console.WriteLine(worksheet["I234"].CalculatedValue); + Console.WriteLine(worksheet["J234"].CalculatedValue); + + // Save the workbook to the specified output path + workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx")); +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + // Create a new Excel application instance + IApplication application = excelEngine.Excel; + IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx"); + + foreach (IWorksheet worksheetxls in workbook.Worksheets) + { + // Enable sheet calculations to compute formula values + worksheetxls.EnableSheetCalculations(); + + // Configure calculation engine for circular reference handling + worksheetxls.CalcEngine.AllowShortCircuitIFs = true; + worksheetxls.CalcEngine.UseFormulaValues = true; + + // Enable circular reference handling with exception throwing + worksheetxls.CalcEngine.ThrowCircularException = true; + + // Set maximum iteration count for resolving circular references + worksheetxls.CalcEngine.IterationMaxCount = 1000; + } + + // Access the first worksheet to retrieve calculated values + IWorksheet worksheet = workbook.Worksheets.First(); + + // Display the calculated values from cells I234 and J234 + Console.WriteLine(worksheet["I234"].CalculatedValue); + Console.WriteLine(worksheet["J234"].CalculatedValue); + + // Save the workbook to the specified output path + workbook.SaveAs("Output.xlsx"); +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Using excelEngine As New ExcelEngine() + ' Create a new Excel application instance + Dim application As IApplication = excelEngine.Excel + Dim workbook As IWorkbook = application.Workbooks.Open("InputTemplate.xlsx") + + For Each worksheetxls As IWorksheet In workbook.Worksheets + ' Enable sheet calculations to compute formula values + worksheetxls.EnableSheetCalculations() + + ' Configure calculation engine for circular reference handling + worksheetxls.CalcEngine.AllowShortCircuitIFs = True + worksheetxls.CalcEngine.UseFormulaValues = True + + ' Enable circular reference handling with exception throwing + worksheetxls.CalcEngine.ThrowCircularException = True + + ' Set maximum iteration count for resolving circular references + worksheetxls.CalcEngine.IterationMaxCount = 1000 + Next + + ' Access the first worksheet to retrieve calculated values + Dim worksheet As IWorksheet = workbook.Worksheets.First() + + ' Display the calculated values from cells I234 and J234 + Console.WriteLine(worksheet("I234").CalculatedValue) + Console.WriteLine(worksheet("J234").CalculatedValue) + + ' Save the workbook to the specified output path + 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 4af3046c4933314182ccd9a7c27728faab2d2573 Mon Sep 17 00:00:00 2001 From: VinothSF5015 Date: Tue, 12 May 2026 17:39:04 +0530 Subject: [PATCH 2/3] Update title for circular references FAQ --- ...e-circular-references-when-retrieving-calculated-values.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-handle-circular-references-when-retrieving-calculated-values.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-handle-circular-references-when-retrieving-calculated-values.md index 663271ee2..ac4b3083b 100644 --- a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-handle-circular-references-when-retrieving-calculated-values.md +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-handle-circular-references-when-retrieving-calculated-values.md @@ -1,5 +1,5 @@ --- -title: How to handle circular references when retrieving calculated values? | Syncfusion +title: Handle circular references when get calculated values | Syncfusion description: This FAQ explains how to handle circular references in Excel formulas when retrieving calculated values using Syncfusion XlsIO's calculation engine properties. platform: document-processing control: XlsIO @@ -117,4 +117,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. From 0dbdd1a5d44a14cd45ed45266c4a1c109cec8c82 Mon Sep 17 00:00:00 2001 From: VinothSF5015 Date: Wed, 13 May 2026 16:53:53 +0530 Subject: [PATCH 3/3] Remove FAQ on circular references in XlsIO Removed FAQ link about handling circular references. --- Document-Processing-toc.html | 3 --- 1 file changed, 3 deletions(-) diff --git a/Document-Processing-toc.html b/Document-Processing-toc.html index b564a7b5a..610dc233e 100644 --- a/Document-Processing-toc.html +++ b/Document-Processing-toc.html @@ -6805,9 +6805,6 @@
  • How to merge cells preserving topleft value and format in XlsIO?
  • -
  • - How to handle circular references when retrieving calculated values? -