원본주소 : http://jxls.sourceforge.net/reference/formulas.html
Overview
This section demonstrates how to apply different formulas to your exported data. First any static Excel formulas (which are supported by POI) will be copied to result Excel file untouched. But if you want to apply formula to dynamic data like exported collections you have to use predefined notation. Any cell with value starting with$[
and ending with ]
will be rendered as a formula cell. For example$[formula]
formula
is the real formula which will be processed by jXLS engine.Formula Cell References notation.
When you reference a worksheet cell in a jXLS formula and that cell is transformed into some other cell or a set of cells the cell reference in the formula will be updated accordingly. For example if you have a formula like$[E5 + B4 * 5]
E20 + B15 * 5
$[SUM(C2)]
SUM(C2:C6)
If result cells do not form any cell range original cell will be replaced with list of all cells separated with commas. If in previous example cell C2 is transformed into cells C2, C3, C4, C10, C11, C20 result formula will look like
SUM(C2,C3,C4,C10,C11,C20)
$[SUM(Sheet2!B10) - 'Sheet 1'!D15]
jx:forEach
tag like this<jx:forEach items="${employees}" var="employee"> ${employee.name} | ${employee.payment} <jx:forEach>
B5
and after transformation we have employee payments in all cells from B5
to B10
then if any other cell references original cell B5
like for example $[SUM(B5)]
then all such formulas will be updated. In this case we will get a formula like SUM(B5:B10)
.Default Formula Values
Sometime you may have a situation when all cells referenced in your formula are removed from the sheet. For example it can happen when formula references a cell inside jx:forEach tag and the collection is empty. To deal with this situation you can use@
symbol to define default formula value. Default formula value will replace the formula only in that case when all underlying cell references were removed during processing.Example
$[SUM(B6) + SUM(B13)@0 + (SUM(B20)@0) +SUM(B27)@0 + SUM(B34)]
=SUM(B5:B9)+0+(SUM(B18:B21))+0+SUM(B30:B32)
댓글 없음:
댓글 쓰기