XlExpression Class
An object which can be used to specify a worksheet cell formula.
Namespace: DevExpress.Export.Xl
Assembly: DevExpress.Printing.v18.1.Core.dll
Declaration
Related API Members
The following members accept/return XlExpression objects:
Remarks
The XlExpression is a List<T><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<T><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/xl-export-api-examples-t253492
// 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);
}
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the XlExpression class.
Note
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.