I'm using Visual Studio 2010 (VB.Net) and Open XML SDK 2.0. How do you insert a formula into an Excel 2010 worksheet? When I do this I also wish to set the CellValue property of the cell to a DBNull or EmptyString to force Excel to recalculate the cell when the user opens the workbok.
Just leave the CellValue as null, and instantiate a new CellFormula like so:
Cell cell = new Cell()
{
CellReference = "A3",
DataType = new EnumValue<CellValues>(CellValues.Number),
CellFormula = "SUM(A1:A2)"
};
The cells value will be computed when the document is opened in Excel
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With