Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Solution>
<Project Path="Formula Recalculation/Formula Recalculation.csproj" />
</Solution>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Formula_Recalculation</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="*" />
</ItemGroup>
<ItemGroup>
<None Update="Output\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -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"));
}
}
}
Loading