IXlCell.SetFormula(String) Method

Assigns the specified formula string to a cell.

Namespace: DevExpress.Export.Xl

Assembly: DevExpress.Printing.v21.2.Core.dll


void SetFormula(
    string formula


Name Type Description
formula String

A string that is a formula contained in the cell.


A spreadsheet formula is an equation that performs a calculation on data contained in worksheet cells. A string specified as the worksheet formula should conform to the formula syntax rules and contain only supported elements (refer to the Excel Export and Spreadsheet Document API Feature Comparison document for a list of supported features).

Before a formula is assigned to a cell, it is analyzed with a formula parser specified in the XlExport.CreateExporter method. If the use of named ranges (defined names) is detected or other unsupported elements are found, an exception is thrown.

If the parser is not specified, the export to the Excel 97-2003 (.xls) format fails because this format requires a parsed formula to assign to a cell. Export to OpenXml (.xlsx) format without a parser leaves the string formula unvalidated.


// Create data rows using string formulas.
for (int i = 0; i < 4; i++) {
    using (IXlRow row = sheet.CreateRow()) {
        using (IXlCell cell = row.CreateCell()) {
            cell.Value = product[i];
        using (IXlCell cell = row.CreateCell()) {
            cell.Value = qty[i];
        using (IXlCell cell = row.CreateCell()) {
            cell.Value = price[i];
        using (IXlCell cell = row.CreateCell()) {
            // Set the formula to calculate the amount per product.
            cell.SetFormula(String.Format("B{0}*C{0}", i + 2));
See Also