jxlsteam / jxls

Java library for creating Excel reports using Excel templates
http://jxls.sourceforge.net
Apache License 2.0
405 stars 92 forks source link

Table syntax support for Util.getFormulaCellRefs() #240

Closed SoltauFintel closed 6 months ago

SoltauFintel commented 1 year ago

Using German formula =SUMMEWENNS(AktuellerBestandTabelle[Buchwert_Direkt];AktuellerBestandTabelle[Zinsblock ohne 71_72];WAHR;AktuellerBestandTabelle[Erste Fälligkeit Jahr];0) will result in wrong value 0.

Cause is this code in StandardFormulaProcessor.java:116:

if (isFormulaCellRefsEmpty && isFormulaJointedCellRefsEmpty
   && (!formulaCellData.isParameterizedFormulaCell() || formulaCellData.isJointedFormulaCell())) {
         targetFormulaString = formulaCellData.getDefaultValue() != null ? formulaCellData.getDefaultValue() : "0";
}

isFormulaCellRefsEmpty is true because JXLS doesn't recognize the table syntax (e.g. "AktuellerBestandTabelle[Buchwert_Direkt]") as a cell ref. Util.getFormulaCellRefs returns an empty list.

SoltauFintel commented 1 year ago

Solution: extend Utl.regexCellRef with + "|[a-zA-Z_]+[a-zA-Z0-9_]*\\[.+\\]". However, many testcases will fail.

leonate commented 1 year ago

Solution: extend Utl.regexCellRef with + "|[a-zA-Z_]+[a-zA-Z0-9_]*\\[.+\\]". However, many testcases will fail.

I added |[a-zA-Z_]+[a-zA-Z0-9_]*\[.+\] to the Util.regexCellRef pattern as you suggested and mvn verify still works fine for me. So I committed the change to the feature-240 branch.

SoltauFintel commented 1 year ago

Formula "FUNC(a[b],c[d])" does not work. I'm going to push a bugfix.

SoltauFintel commented 6 months ago

PR #312 is my 2nd attempt to solve this issue.