How to: Add Formulas to Cells
// Use constants and calculation operators in a formula. workbook.Worksheets.Cells["B2"].Formula = "= (1+5)*6";
For more information on formulas, refer to the Spreadsheet Formulas section, and review the following examples:
- How to: Use Constants and Calculation Operators in Formulas
- How to: Use Cell and Worksheet References in Formulas
- How to: Use Names in Formulas
- How to: Use Functions and Nested Functions in Formulas
When you set the CellRange.Formula property for a cell range, each cell in this range contains the specified formula with automatically adjusted relative cell references. Therefore, you do not need to duplicate the same formula for each cell and update cell references. Refer to the How to: Create Shared Formulas example for more information.
To perform calculations with arrays of cells, use array formulas. Call the CellRange.ArrayFormula method to create an array formula. Refer to the How to: Create Array Formulas example for more information.