Table of Contents

Method SetFormula

Namespace
DocWright.Formats.Xlsx
Assembly
DocWright.Formats.Xlsx.dll

SetFormula(int, int, string)

Sets a cell's formula. Its format is kept; it has no value until an application calculates it.

public void SetFormula(int row, int column, string formula)

Parameters

row int

The one-based row.

column int

The one-based column.

formula string

The formula, with or without its leading =, as Excel stores it: English function names, commas between arguments.

Remarks

The formula is stored as given and is not checked: one Excel cannot read makes Excel offer to repair the workbook. After the edit the cell reads back with this formula and a blank value.

Exceptions

ArgumentNullException

formula is null.

ArgumentException

formula is empty or longer than the 8,192 characters a formula may be.

ArgumentOutOfRangeException

The row or the column is outside the worksheet grid.

InvalidOperationException

The sheet is not a worksheet.

UnsupportedFeatureException

The cell is part of an array formula entered over several cells, or is a header or totals cell of a table.

InvalidDocumentException

The sheet's part is malformed.

SetFormula(string, string)

Sets a cell's formula by its reference. See SetFormula(int, int, string).

public void SetFormula(string reference, string formula)

Parameters

reference string

The reference, such as B4.

formula string

The formula, with or without its leading =.

Exceptions

ArgumentNullException

reference or formula is null.

ArgumentException

reference is not a cell reference inside the worksheet grid, or the formula is empty or too long.

InvalidOperationException

The sheet is not a worksheet.

UnsupportedFeatureException

The cell is part of an array formula entered over several cells, or is a header or totals cell of a table.

InvalidDocumentException

The sheet's part is malformed.