Back to Devexpress

XlFunc Class

corelibraries-devexpress-dot-export-dot-xl-57cfc859.md

latest3.6 KB
Original Source

XlFunc Class

Provides static methods used to construct an internal representation of an expression (an IXlFormulaParameter object).

Namespace : DevExpress.Export.Xl

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

NuGet Package : DevExpress.Printing.Core

Declaration

csharp
public static class XlFunc
vb
Public Module XlFunc

Example

This code snippet creates an IXlFormulaParameter expression from a combination of constants, operators and functions. Constants are transformed into the IXlFormulaParameter objects with the XlFunc.Param method. Operators are static methods of the XlOper object and functions are static methods of the XlFunc object.

When an expression is created, the IXlCell.SetFormula method is used to enter expression into a worksheet cell as the cell formula.

Note

A complete sample project is available at https://github.com/DevExpress-Examples/excel-export-api-examples

csharp
// Create the total row using IXlFormulaParameter.
using (IXlRow row = sheet.CreateRow()) {
    row.SkipCells(2);
    using (IXlCell cell = row.CreateCell()) {
        cell.Value = "Total:";
        cell.ApplyFormatting(totalRowFormatting);
    }
    using (IXlCell cell = row.CreateCell()) {
        // Set the formula to calculate the total amount plus 10 handling fee.
        // =SUM($D$2:$D$5)+10
        IXlFormulaParameter const10 = XlFunc.Param(10);
        IXlFormulaParameter sumAmountFunction = XlFunc.Sum(XlCellRange.FromLTRB(cell.ColumnIndex, 1, cell.ColumnIndex, row.RowIndex - 1).AsAbsolute());
        cell.SetFormula(XlOper.Add(sumAmountFunction, const10));
        cell.ApplyFormatting(totalRowFormatting);
    }
}
vb
' Create the total row using IXlFormulaParameter.
Using row As IXlRow = sheet.CreateRow()
    row.SkipCells(2)
    Using cell As IXlCell = row.CreateCell()
        cell.Value = "Total:"
        cell.ApplyFormatting(totalRowFormatting)
    End Using
    Using cell As IXlCell = row.CreateCell()
        ' Set the formula to calculate the total amount plus 10 handling fee.
        ' =SUM($D$2:$D$5)+10
        Dim const10 As IXlFormulaParameter = XlFunc.Param(10)
        Dim sumAmountFunction As IXlFormulaParameter = XlFunc.Sum(XlCellRange.FromLTRB(cell.ColumnIndex, 1, cell.ColumnIndex, row.RowIndex - 1).AsAbsolute())
        cell.SetFormula(XlOper.Add(sumAmountFunction, const10))
        cell.ApplyFormatting(totalRowFormatting)
    End Using
End Using

Inheritance

Object XlFunc

See Also

XlFunc Members

IXlFormulaParameter

XlOper

SetFormula

DevExpress.Export.Xl Namespace