diff --git a/FAQ/Formula Recalculation/.NET/Formula Recalculation/Formula Recalculation.slnx b/FAQ/Formula Recalculation/.NET/Formula Recalculation/Formula Recalculation.slnx new file mode 100644 index 00000000..63a59110 --- /dev/null +++ b/FAQ/Formula Recalculation/.NET/Formula Recalculation/Formula Recalculation.slnx @@ -0,0 +1,3 @@ + + + diff --git a/FAQ/Formula Recalculation/.NET/Formula Recalculation/Formula Recalculation/Formula Recalculation.csproj b/FAQ/Formula Recalculation/.NET/Formula Recalculation/Formula Recalculation/Formula Recalculation.csproj new file mode 100644 index 00000000..5a1cc0ef --- /dev/null +++ b/FAQ/Formula Recalculation/.NET/Formula Recalculation/Formula Recalculation/Formula Recalculation.csproj @@ -0,0 +1,19 @@ + + + + Exe + net8.0 + Formula_Recalculation + enable + enable + + + + + + + + Always + + + diff --git a/FAQ/Formula Recalculation/.NET/Formula Recalculation/Formula Recalculation/Output/.gitkeep b/FAQ/Formula Recalculation/.NET/Formula Recalculation/Formula Recalculation/Output/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/FAQ/Formula Recalculation/.NET/Formula Recalculation/Formula Recalculation/Program.cs b/FAQ/Formula Recalculation/.NET/Formula Recalculation/Formula Recalculation/Program.cs new file mode 100644 index 00000000..b11b9b58 --- /dev/null +++ b/FAQ/Formula Recalculation/.NET/Formula Recalculation/Formula Recalculation/Program.cs @@ -0,0 +1,34 @@ +using Syncfusion.XlsIO; + +class Program +{ + static void Main(string[] args) + { + 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"; + + worksheet.EnableSheetCalculations(); + // 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")); + } + } +}