corelibraries-devexpress-dot-export-dot-xl-98f0cba2.md
An object which can be used to specify a worksheet cell formula.
Namespace : DevExpress.Export.Xl
Assembly : DevExpress.Printing.v25.2.Core.dll
NuGet Package : DevExpress.Printing.Core
public class XlExpression :
List<XlPtgBase>
Public Class XlExpression
Inherits List(Of XlPtgBase)
The following members return XlExpression objects:
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.
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);
}
}
' Create a formula using XlExpression.
Using row As IXlRow = sheet.CreateRow()
row.SkipCells(2)
Using cell As IXlCell = row.CreateCell()
cell.Value = "Mean value:"
cell.ApplyFormatting(totalRowFormatting)
End Using
Using cell As IXlCell = row.CreateCell()
' Set the formula to calculate the mean value.
' =$D$6/4
Dim expression As 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)
End Using
End Using
Object List<DevExpress.Export.Xl.XlPtgBase> XlExpression
See Also