IXlCell.SetSharedFormula(String, XlCellRange) Method

Assigns the specified formula string to the given cell range to create a shared formula.

Namespace: DevExpress.Export.Xl

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


void SetSharedFormula(
    string formula,
    XlCellRange range


Name Type Description
formula String

A string that is the textual expression used as a cell formula.

range XlCellRange

An XlCellRange object that is the worksheet cell range in which each cell will contain a shared formula.


It takes two steps to build a shared formula. First, add a formula to the first cell in a range - it is the host formula. Next, add a reference to the host formula to any other cell of the range. The IXlCell.SetSharedFormula method with different parameters serves both steps, as illustrated in the code below.

// Create data rows.
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()) {
            // Use the shared formula to calculate the amount per product. 
            if (i == 0)
                cell.SetSharedFormula("B2*C2", XlCellRange.FromLTRB(3, 1, 3, 4));
                cell.SetSharedFormula(new XlCellPosition(3, 1));

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SetSharedFormula(String, XlCellRange) method.


The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also