From 62cd115a28ff91334baac6cda4eaaa8945a83238 Mon Sep 17 00:00:00 2001 From: VinothSF5015 Date: Tue, 5 May 2026 23:33:19 +0530 Subject: [PATCH 1/3] 1014444 - Content Added --- Document-Processing-toc.html | 6 + ...rmula-in-a-cell-contains-an-error-value.md | 103 ++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 Document-Processing/Excel/Excel-Library/NET/faqs/how-to-check-if-a-formula-in-a-cell-contains-an-error-value.md diff --git a/Document-Processing-toc.html b/Document-Processing-toc.html index 26c1bfa6f..d55488f3e 100644 --- a/Document-Processing-toc.html +++ b/Document-Processing-toc.html @@ -6364,6 +6364,9 @@
  • How to check whether an Excel document contains macro?
  • +
  • + How to check if a formula in a cell contains an error value? +
  • Does XlsIO support password protected macro in the Excel documents?
  • @@ -6772,6 +6775,9 @@
  • How to merge cells preserving topleft value and format in XlsIO?
  • +
  • + How to check if a formula in a cell contains an error value? +
  • diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-check-if-a-formula-in-a-cell-contains-an-error-value.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-check-if-a-formula-in-a-cell-contains-an-error-value.md new file mode 100644 index 000000000..fbc4f691f --- /dev/null +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-check-if-a-formula-in-a-cell-contains-an-error-value.md @@ -0,0 +1,103 @@ +--- +title: How to check if a formula in a cell contains an error value? | Syncfusion +description: Explains how to detect whether a formula returns an error using HasFormulaErrorValue and read the FormulaErrorValue via IRange in XlsIO. +platform: document-processing +control: XlsIO +documentation: UG +--- + +# How to check if a formula in a cell contains an error value? + +In XlsIO there is no direct property that predicts whether a formula will evaluate to an error at design time, but the `IRange` interface exposes two useful members: + +- `HasFormulaErrorValue` (Read-Only): returns true when the formula in the cell evaluates to an error value. +- `FormulaErrorValue` (Read-Only): returns the error value as a string (for example `#DIV/0!`, `#N/A`, etc.). + +The example below shows how to iterate the used range of a worksheet, check each cell for `HasFormulaErrorValue`, and print the `FormulaErrorValue` and the cell address. + +{% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Input/InputTemplate.xlsx")); + IWorksheet worksheet = workbook.Worksheets[0]; + + IRange usedRange = worksheet.UsedRange; + int firstrow = usedRange.Row; + int lastrow = usedRange.LastRow; + int firstcol = usedRange.Column; + int lastcol = usedRange.LastColumn; + + for (int row = firstrow; row <= lastrow; row++) + { + for (int col = firstcol; col <= lastcol; col++) + { + if (worksheet[row, col] != null && worksheet[row, col].HasFormulaErrorValue) + { + Console.WriteLine($"Formula error value: {worksheet[row,col].FormulaErrorValue} in Address: {worksheet[row,col].AddressLocal}"); + } + } + } + + workbook.SaveAs(Path.GetFullPath(@"Output/Output.xlsx")); +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx"); + IWorksheet worksheet = workbook.Worksheets[0]; + + IRange usedRange = worksheet.UsedRange; + int firstrow = usedRange.Row; + int lastrow = usedRange.LastRow; + int firstcol = usedRange.Column; + int lastcol = usedRange.LastColumn; + + for (int row = firstrow; row <= lastrow; row++) + { + for (int col = firstcol; col <= lastcol; col++) + { + if (worksheet[row, col] != null && worksheet[row, col].HasFormulaErrorValue) + { + Console.WriteLine($"Formula error value: {worksheet[row,col].FormulaErrorValue} in Address: {worksheet[row,col].AddressLocal}"); + } + } + } + + workbook.SaveAs("Output.xlsx"); +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Using excelEngine As New ExcelEngine() + Dim application As IApplication = excelEngine.Excel + application.DefaultVersion = ExcelVersion.Xlsx + Dim workbook As IWorkbook = application.Workbooks.Open("InputTemplate.xlsx") + Dim worksheet As IWorksheet = workbook.Worksheets(0) + + Dim usedRange As IRange = worksheet.UsedRange + Dim firstrow As Integer = usedRange.Row + Dim lastrow As Integer = usedRange.LastRow + Dim firstcol As Integer = usedRange.Column + Dim lastcol As Integer = usedRange.LastColumn + + For row As Integer = firstrow To lastrow + For col As Integer = firstcol To lastcol + If worksheet(row, col) IsNot Nothing AndAlso worksheet(row, col).HasFormulaErrorValue Then + Console.WriteLine("Formula error value: " & worksheet(row, col).FormulaErrorValue & " in Address: " & worksheet(row, col).AddressLocal) + End If + Next + Next + + 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 054388eedfb8b52c7b9a206548012982a93c5522 Mon Sep 17 00:00:00 2001 From: VinothSF5015 Date: Tue, 5 May 2026 23:36:35 +0530 Subject: [PATCH 2/3] Remove FAQ link for formula error value check Removed FAQ link about checking for error values in formulas. --- Document-Processing-toc.html | 3 --- 1 file changed, 3 deletions(-) diff --git a/Document-Processing-toc.html b/Document-Processing-toc.html index d55488f3e..9cd2efc6f 100644 --- a/Document-Processing-toc.html +++ b/Document-Processing-toc.html @@ -6364,9 +6364,6 @@
  • How to check whether an Excel document contains macro?
  • -
  • - How to check if a formula in a cell contains an error value? -
  • Does XlsIO support password protected macro in the Excel documents?
  • From 8bac3f9a63cdfcd5e6c2ea42a8ebd5d1088ace19 Mon Sep 17 00:00:00 2001 From: VinothSF5015 Date: Tue, 5 May 2026 23:44:54 +0530 Subject: [PATCH 3/3] Update title for formula error value documentation --- ...to-check-if-a-formula-in-a-cell-contains-an-error-value.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-check-if-a-formula-in-a-cell-contains-an-error-value.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-check-if-a-formula-in-a-cell-contains-an-error-value.md index fbc4f691f..778c73791 100644 --- a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-check-if-a-formula-in-a-cell-contains-an-error-value.md +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-check-if-a-formula-in-a-cell-contains-an-error-value.md @@ -1,5 +1,5 @@ --- -title: How to check if a formula in a cell contains an error value? | Syncfusion +title: How to Check Formula Error Values in a Cell | Syncfusion description: Explains how to detect whether a formula returns an error using HasFormulaErrorValue and read the FormulaErrorValue via IRange in XlsIO. platform: document-processing control: XlsIO @@ -100,4 +100,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.