From a0f28fadd7ddf7a5a9b133b682260f66325c6342 Mon Sep 17 00:00:00 2001 From: santiprajaSF4793 Date: Mon, 30 Mar 2026 17:34:35 +0530 Subject: [PATCH 1/4] 992532-FAQFormulaHandling --- Document-Processing-toc.html | 3 + ...d-as-strings-using-cell-type-validation.md | 118 ++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 Document-Processing/Excel/Excel-Library/NET/faqs/how-to-handle-excel-formulas-stored-as-strings-using-cell-type-validation.md diff --git a/Document-Processing-toc.html b/Document-Processing-toc.html index b5b14a8539..54f1915995 100644 --- a/Document-Processing-toc.html +++ b/Document-Processing-toc.html @@ -6488,6 +6488,9 @@
  • How to get the RGB color value for the applied cell color?
  • +
  • + How to handle Excel formulas stored as strings using cell type validation? +
  • How to save the edited changes in the same Excel document?
  • diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-handle-excel-formulas-stored-as-strings-using-cell-type-validation.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-handle-excel-formulas-stored-as-strings-using-cell-type-validation.md new file mode 100644 index 0000000000..8846ccf7f8 --- /dev/null +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-handle-excel-formulas-stored-as-strings-using-cell-type-validation.md @@ -0,0 +1,118 @@ +--- +title: Handle Excel formulas stored as strings using cell type validation | Syncfusion +description: Code example to handle Excel formulas stored as strings using Syncfusion .NET Excel library (XlsIO). +platform: document-processing +control: XlsIO +documentation: UG +--- + +# How to handle Excel formulas stored as strings using cell type validation? + +The following code examples demonstrate how to handle Excel formulas stored as strings using cell type validation using C# (Cross-platform and Windows-specific) and VB.NET. + +{% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/FAQ/Formula%20stored%20as%20text%20handling/.NET/FormulaStoredAsTextHandling/FormulaStoredAsTextHandling/Program.cs,180" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + //Create a new workbook with one worksheet + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet worksheet = workbook.Worksheets[0]; + + //Assign a formula as text to the cell + worksheet["A1"].Text = "=SUM(2+2)"; + + //Get the cell type of the cell + Syncfusion.XlsIO.Implementation.WorksheetImpl.TRangeValueType cellType = + (worksheet as WorksheetImpl).GetCellType(1, 1, false); + + //Check if the cell type is string + if (cellType == TRangeValueType.String) + { + //Retrieve the formula text + string formulaText = worksheet["A1"].Text; + + //Clear the cell value + worksheet["A1"].Value = string.Empty; + + //Reassign the formula to the cell + worksheet["A1"].Formula = formulaText; + } + + //Save the workbook + 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; + + //Create a new workbook with one worksheet + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet worksheet = workbook.Worksheets[0]; + + //Assign a formula as text to the cell + worksheet["A1"].Text = "=SUM(2+2)"; + + //Get the cell type of the cell + Syncfusion.XlsIO.Implementation.WorksheetImpl.TRangeValueType cellType = + (worksheet as WorksheetImpl).GetCellType(1, 1, false); + + //Check if the cell type is string + if (cellType == TRangeValueType.String) + { + //Retrieve the formula text + string formulaText = worksheet["A1"].Text; + + //Clear the cell value + worksheet["A1"].Value = string.Empty; + + //Reassign the formula to the cell + worksheet["A1"].Formula = formulaText; + } + + //Save the workbook + 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 + + 'Create a new workbook with one worksheet + Dim workbook As IWorkbook = application.Workbooks.Create(1) + Dim worksheet As IWorksheet = workbook.Worksheets(0) + + 'Assign a formula as text to the cell + worksheet("A1").Text = "=SUM(2+2)" + + 'Get the cell type + Dim cellType As Syncfusion.XlsIO.Implementation.WorksheetImpl.TRangeValueType = + CType(worksheet, WorksheetImpl).GetCellType(1, 1, False) + + 'Check if the cell type is string + If cellType = TRangeValueType.String Then + 'Retrieve the formula text + Dim formulaText As String = worksheet("A1").Text + + 'Clear the cell value + worksheet("A1").Value = String.Empty + + 'Reassign the formula to the cell + worksheet("A1").Formula = formulaText + End If + + 'Save the workbook + workbook.SaveAs(IO.Path.GetFullPath("Output/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 98481b0d1ce8b1c4599f0b57662954c621d63501 Mon Sep 17 00:00:00 2001 From: santiprajaSF4793 Date: Mon, 30 Mar 2026 18:08:51 +0530 Subject: [PATCH 2/4] 992532-FAQFormulaHandling --- ...l-formulas-stored-as-strings-using-cell-type-validation.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-handle-excel-formulas-stored-as-strings-using-cell-type-validation.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-handle-excel-formulas-stored-as-strings-using-cell-type-validation.md index 8846ccf7f8..604fbeea67 100644 --- a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-handle-excel-formulas-stored-as-strings-using-cell-type-validation.md +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-handle-excel-formulas-stored-as-strings-using-cell-type-validation.md @@ -1,12 +1,12 @@ --- -title: Handle Excel formulas stored as strings using cell type validation | Syncfusion +title: Handle Excel formulas stored as strings | Syncfusion description: Code example to handle Excel formulas stored as strings using Syncfusion .NET Excel library (XlsIO). platform: document-processing control: XlsIO documentation: UG --- -# How to handle Excel formulas stored as strings using cell type validation? +# How to handle Excel formulas stored as strings? The following code examples demonstrate how to handle Excel formulas stored as strings using cell type validation using C# (Cross-platform and Windows-specific) and VB.NET. From 9b9035a42679c290d6aa876190c4d98b883e485b Mon Sep 17 00:00:00 2001 From: santiprajaSF4793 Date: Tue, 31 Mar 2026 19:50:04 +0530 Subject: [PATCH 3/4] 992532-FAQFormulaHandling --- Document-Processing-toc.html | 2 +- ...o-restore-formulas-stored-as-text-in-excel-documents.md} | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) rename Document-Processing/Excel/Excel-Library/NET/faqs/{how-to-handle-excel-formulas-stored-as-strings-using-cell-type-validation.md => how-to-restore-formulas-stored-as-text-in-excel-documents.md} (94%) diff --git a/Document-Processing-toc.html b/Document-Processing-toc.html index 54f1915995..d3215b0431 100644 --- a/Document-Processing-toc.html +++ b/Document-Processing-toc.html @@ -6489,7 +6489,7 @@ How to get the RGB color value for the applied cell color?
  • - How to handle Excel formulas stored as strings using cell type validation? + How to restore formulas stored as text in Excel documents?
  • How to save the edited changes in the same Excel document? diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-handle-excel-formulas-stored-as-strings-using-cell-type-validation.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-restore-formulas-stored-as-text-in-excel-documents.md similarity index 94% rename from Document-Processing/Excel/Excel-Library/NET/faqs/how-to-handle-excel-formulas-stored-as-strings-using-cell-type-validation.md rename to Document-Processing/Excel/Excel-Library/NET/faqs/how-to-restore-formulas-stored-as-text-in-excel-documents.md index 604fbeea67..357473fe7d 100644 --- a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-handle-excel-formulas-stored-as-strings-using-cell-type-validation.md +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-restore-formulas-stored-as-text-in-excel-documents.md @@ -1,12 +1,12 @@ --- -title: Handle Excel formulas stored as strings | Syncfusion -description: Code example to handle Excel formulas stored as strings using Syncfusion .NET Excel library (XlsIO). +title: Restore Excel formulas stored as text | Syncfusion +description: Code example to restore Excel formulas stored as text using Syncfusion .NET Excel library (XlsIO). platform: document-processing control: XlsIO documentation: UG --- -# How to handle Excel formulas stored as strings? +# How to restore formulas stored as text in Excel documents? The following code examples demonstrate how to handle Excel formulas stored as strings using cell type validation using C# (Cross-platform and Windows-specific) and VB.NET. From 4acdb7338213d7656a6cdbf81a6f640bdb4f1b3a Mon Sep 17 00:00:00 2001 From: santiprajaSF4793 Date: Tue, 31 Mar 2026 20:34:44 +0530 Subject: [PATCH 4/4] 992532-FAQFormulaHandling --- ...how-to-restore-formulas-stored-as-text-in-excel-documents.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-restore-formulas-stored-as-text-in-excel-documents.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-restore-formulas-stored-as-text-in-excel-documents.md index 357473fe7d..49d1d92f7d 100644 --- a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-restore-formulas-stored-as-text-in-excel-documents.md +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-restore-formulas-stored-as-text-in-excel-documents.md @@ -1,6 +1,6 @@ --- title: Restore Excel formulas stored as text | Syncfusion -description: Code example to restore Excel formulas stored as text using Syncfusion .NET Excel library (XlsIO). +description: Code example to restore Excel formulas stored as text in Excel documents using Syncfusion .NET Excel library (XlsIO). platform: document-processing control: XlsIO documentation: UG