XlExpression Class
An object which can be used to specify a worksheet cell formula.
Namespace: DevExpress.Export.Xl
Assembly: DevExpress.Printing.v24.1.Core.dll
NuGet Package: DevExpress.Printing.Core
Declaration
Related API Members
The following members return XlExpression objects:
Remarks
The XlExpression is a List<DevExpress.Export.Xl.XlPtgBase> list of formula tokens (aka PTGs, “parsed things”) arranged in Reverse-Polish Notation order.
To create an expression, add required tokens in the proper order to the XlExpression instance.
Use the XlExpression instance to specify a worksheet cell formula with the IXlCell.SetFormula or IXlCell.SetSharedFormula methods.
Example
This code snippet show how to create an expression “from scratch” by adding formula tokens (aka PTGs, “parsed things”) to the XlExpression
instance which is a List<DevExpress.Export.Xl.XlPtgBase> list of tokens arranged in Reverse-Polish Notation order. Subsequently, the expression is passed to the IXlCell.SetFormula method to specify a cell formula.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/excel-export-api-examples
// Create a formula using XlExpression.
using (IXlRow row = sheet.CreateRow()) {
row.SkipCells(2);
using (IXlCell cell = row.CreateCell()) {
cell.Value = "Mean value:";
cell.ApplyFormatting(totalRowFormatting);
}
using (IXlCell cell = row.CreateCell()) {
// Set the formula to calculate the mean value.
// =$D$6/4
XlExpression expression = new XlExpression();
expression.Add(new XlPtgRef(new XlCellPosition(cell.ColumnIndex, row.RowIndex - 1, XlPositionType.Absolute, XlPositionType.Absolute)));
expression.Add(new XlPtgInt(row.RowIndex - 2));
expression.Add(new XlPtgBinaryOperator(XlPtgTypeCode.Div));
cell.SetFormula(expression);
cell.ApplyFormatting(totalRowFormatting);
}
}