You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2009/04/18 09:12:39 UTC
svn commit: r766251 - in /poi/trunk/src: documentation/content/xdocs/
java/org/apache/poi/hssf/record/formula/function/
java/org/apache/poi/hssf/usermodel/ java/org/apache/poi/ss/formula/
ooxml/java/org/apache/poi/xssf/usermodel/ testcases/org/apache/p...
Author: yegor
Date: Sat Apr 18 07:12:38 2009
New Revision: 766251
URL: http://svn.apache.org/viewvc?rev=766251&view=rev
Log:
Allow 255 arguments for excel functions in XSSF, see bugzilla 46279
Modified:
poi/trunk/src/documentation/content/xdocs/changes.xml
poi/trunk/src/documentation/content/xdocs/status.xml
poi/trunk/src/java/org/apache/poi/hssf/record/formula/function/FunctionMetadataRegistry.java
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java
poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParser.java
poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParsingWorkbook.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
poi/trunk/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java
poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
Modified: poi/trunk/src/documentation/content/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/changes.xml?rev=766251&r1=766250&r2=766251&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/changes.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/changes.xml Sat Apr 18 07:12:38 2009
@@ -37,6 +37,7 @@
<!-- Don't forget to update status.xml too! -->
<release version="3.5-beta6" date="2009-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">46279 - Allow 255 arguments for excel functions in XSSF </action>
<action dev="POI-DEVELOPERS" type="fix">47028 - Fixed XSSFCell to preserve cell style when cell value is set to blank</action>
<action dev="POI-DEVELOPERS" type="fix">47026 - Avoid NPE in XSSFCell.setCellType() when workbook does not have SST</action>
<action dev="POI-DEVELOPERS" type="fix">46987 - Allow RecordFactory to handle non-zero padding at the end of the workbook stream</action>
Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=766251&r1=766250&r2=766251&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Sat Apr 18 07:12:38 2009
@@ -34,6 +34,7 @@
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.5-beta6" date="2009-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">46279 - Allow 255 arguments for excel functions in XSSF </action>
<action dev="POI-DEVELOPERS" type="fix">47028 - Fixed XSSFCell to preserve cell style when cell value is set to blank</action>
<action dev="POI-DEVELOPERS" type="fix">47026 - Avoid NPE in XSSFCell.setCellType() when workbook does not have SST</action>
<action dev="POI-DEVELOPERS" type="fix">46987 - Allow RecordFactory to handle non-zero padding at the end of the workbook stream</action>
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/function/FunctionMetadataRegistry.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/function/FunctionMetadataRegistry.java?rev=766251&r1=766250&r2=766251&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/function/FunctionMetadataRegistry.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/function/FunctionMetadataRegistry.java Sat Apr 18 07:12:38 2009
@@ -30,7 +30,15 @@
*/
public static final String FUNCTION_NAME_IF = "IF";
- public static final short FUNCTION_INDEX_SUM = 4;
+ /**
+ * maxParams=30 in functionMetadata.txt means the maximum number arguments supported
+ * by the given version of Excel. Validation routines should take the actual limit (Excel 97 or 2007)
+ * from the SpreadsheetVersion enum.
+ * @see org.apache.poi.ss.formula.FormulaParser#validateNumArgs(int, FunctionMetadata)
+ */
+ public static final short FUNCTION_MAX_PARAMS = 30;
+
+ public static final short FUNCTION_INDEX_SUM = 4;
public static final short FUNCTION_INDEX_EXTERNAL = 255;
private static FunctionMetadataRegistry _instance;
Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java?rev=766251&r1=766250&r2=766251&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java Sat Apr 18 07:12:38 2009
@@ -25,6 +25,7 @@
import org.apache.poi.hssf.record.formula.NameXPtg;
import org.apache.poi.hssf.record.formula.Ptg;
import org.apache.poi.ss.formula.*;
+import org.apache.poi.ss.SpreadsheetVersion;
/**
* Internal POI use only
@@ -154,4 +155,8 @@
return new NamePtg(_index);
}
}
+
+ public SpreadsheetVersion getSpreadsheetVersion(){
+ return SpreadsheetVersion.EXCEL97;
+ }
}
Modified: poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParser.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParser.java?rev=766251&r1=766250&r2=766251&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParser.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParser.java Sat Apr 18 07:12:38 2009
@@ -31,6 +31,7 @@
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.ss.util.CellReference.NameType;
+import org.apache.poi.ss.SpreadsheetVersion;
/**
* This class parses a formula string into a List of tokens in RPN order.
@@ -982,13 +983,20 @@
}
msg += " but got " + numArgs + ".";
throw new FormulaParseException(msg);
- }
- if(numArgs > fm.getMaxParams()) {
+ }
+ //the maximum number of arguments depends on the Excel version
+ int maxArgs = fm.getMaxParams();
+ if( maxArgs == FunctionMetadataRegistry.FUNCTION_MAX_PARAMS) {
+ //_book can be omitted by test cases
+ if(_book != null) maxArgs = _book.getSpreadsheetVersion().getMaxFunctionArgs();
+ }
+
+ if(numArgs > maxArgs) {
String msg = "Too many arguments to function '" + fm.getName() + "'. ";
if(fm.hasFixedArgsLength()) {
- msg += "Expected " + fm.getMaxParams();
+ msg += "Expected " + maxArgs;
} else {
- msg += "At most " + fm.getMaxParams() + " were expected";
+ msg += "At most " + maxArgs + " were expected";
}
msg += " but got " + numArgs + ".";
throw new FormulaParseException(msg);
Modified: poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParsingWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParsingWorkbook.java?rev=766251&r1=766250&r2=766251&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParsingWorkbook.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParsingWorkbook.java Sat Apr 18 07:12:38 2009
@@ -18,6 +18,7 @@
package org.apache.poi.ss.formula;
import org.apache.poi.hssf.record.formula.NameXPtg;
+import org.apache.poi.ss.SpreadsheetVersion;
/**
* Abstracts a workbook for the purpose of formula parsing.<br/>
@@ -44,4 +45,11 @@
* @param sheetName a name of a sheet in that workbook
*/
int getExternalSheetIndex(String workbookName, String sheetName);
+
+ /**
+ * Returns an enum holding spreadhseet properties specific to an Excel version (
+ * max column and row numbers, max arguments to a function, etc.)
+ */
+ SpreadsheetVersion getSpreadsheetVersion();
+
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java?rev=766251&r1=766250&r2=766251&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java Sat Apr 18 07:12:38 2009
@@ -366,14 +366,8 @@
}
XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb);
- try {
- Ptg[] ptgs = FormulaParser.parse(formula, fpb, FormulaType.CELL, wb.getSheetIndex(getSheet()));
- } catch (RuntimeException e) {
- if (e.getClass().getName().startsWith(FormulaParser.class.getName())) {
- throw new IllegalArgumentException("Unparsable formula '" + formula + "'", e);
- }
- throw e;
- }
+ //validate through the FormulaParser
+ FormulaParser.parse(formula, fpb, FormulaType.CELL, wb.getSheetIndex(getSheet()));
CTCellFormula f = CTCellFormula.Factory.newInstance();
f.setStringValue(formula);
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java?rev=766251&r1=766250&r2=766251&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java Sat Apr 18 07:12:38 2009
@@ -21,6 +21,7 @@
import org.apache.poi.hssf.record.formula.NameXPtg;
import org.apache.poi.hssf.record.formula.Ptg;
import org.apache.poi.ss.formula.*;
+import org.apache.poi.ss.SpreadsheetVersion;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName;
/**
@@ -172,4 +173,8 @@
return new NamePtg(_index);
}
}
+
+ public SpreadsheetVersion getSpreadsheetVersion(){
+ return SpreadsheetVersion.EXCEL2007;
+ }
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java?rev=766251&r1=766250&r2=766251&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java Sat Apr 18 07:12:38 2009
@@ -191,14 +191,9 @@
public void setRefersToFormula(String formulaText) {
XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(workbook);
- try {
- FormulaParser.parse(formulaText, fpb, FormulaType.NAMEDRANGE, getSheetIndex());
- } catch (RuntimeException e) {
- if (e.getClass().getName().startsWith(FormulaParser.class.getName())) {
- throw new IllegalArgumentException("Unparsable formula '" + formulaText + "'", e);
- }
- throw e;
- }
+ //validate through the FormulaParser
+ FormulaParser.parse(formulaText, fpb, FormulaType.NAMEDRANGE, getSheetIndex());
+
ctName.setStringValue(formulaText);
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java?rev=766251&r1=766250&r2=766251&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java Sat Apr 18 07:12:38 2009
@@ -22,19 +22,12 @@
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.util.CellReference;
-import org.apache.poi.ss.formula.FormulaParser;
-import org.apache.poi.ss.formula.FormulaType;
-import org.apache.poi.ss.formula.FormulaRenderer;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.xssf.model.CalculationChain;
-import org.apache.poi.hssf.record.formula.Ptg;
-import org.apache.poi.hssf.record.formula.FormulaShifter;
-import org.apache.poi.hssf.record.SharedFormulaRecord;
import org.apache.poi.util.POILogger;
import org.apache.poi.util.POILogFactory;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula;
/**
* High level representation of a row of a spreadsheet.
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=766251&r1=766250&r2=766251&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Sat Apr 18 07:12:38 2009
@@ -24,19 +24,12 @@
import javax.xml.namespace.QName;
import org.apache.poi.hssf.util.PaneInformation;
-import org.apache.poi.hssf.record.formula.Ptg;
import org.apache.poi.hssf.record.formula.FormulaShifter;
-import org.apache.poi.hssf.record.SharedFormulaRecord;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellReference;
-import org.apache.poi.ss.util.AreaReference;
-import org.apache.poi.ss.formula.FormulaParser;
-import org.apache.poi.ss.formula.FormulaType;
-import org.apache.poi.ss.formula.FormulaRenderer;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.xssf.model.CommentsTable;
-import org.apache.poi.xssf.model.CalculationChain;
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
import org.apache.poi.xssf.usermodel.helpers.XSSFRowShifter;
import org.apache.poi.POIXMLDocumentPart;
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java?rev=766251&r1=766250&r2=766251&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java Sat Apr 18 07:12:38 2009
@@ -48,7 +48,7 @@
}
public SpreadsheetVersion getSpreadsheetVersion(){
- return SpreadsheetVersion.EXCEL2007;
+ return SpreadsheetVersion.EXCEL97;
}
private HSSFITestDataProvider(){}
Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java?rev=766251&r1=766250&r2=766251&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java Sat Apr 18 07:12:38 2009
@@ -19,7 +19,9 @@
import junit.framework.TestCase;
import junit.framework.AssertionFailedError;
import org.apache.poi.ss.ITestDataProvider;
+import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
* A base class for bugzilla issues that can be described in terms of common ss interfaces.
@@ -295,4 +297,42 @@
assertEquals(d, (311+312+321+322), 0.0000001);
}
+
+ public void testMaxFunctionArguments_bug46729(){
+ String[] func = {"COUNT", "AVERAGE", "MAX", "MIN", "OR", "SUBTOTAL", "SKEW"};
+
+ SpreadsheetVersion ssVersion = getTestDataProvider().getSpreadsheetVersion();
+ Workbook wb = getTestDataProvider().createWorkbook();
+ Cell cell = wb.createSheet().createRow(0).createCell(0);
+
+ String fmla;
+ for (String name : func) {
+
+ fmla = createFunction(name, 5);
+ cell.setCellFormula(fmla);
+
+ fmla = createFunction(name, ssVersion.getMaxFunctionArgs());
+ cell.setCellFormula(fmla);
+
+ try {
+ fmla = createFunction(name, ssVersion.getMaxFunctionArgs() + 1);
+ cell.setCellFormula(fmla);
+ fail("Expected FormulaParseException");
+ } catch (RuntimeException e){
+ assertTrue(e.getMessage().startsWith("Too many arguments to function '"+name+"'"));
+ }
+ }
+ }
+
+ private String createFunction(String name, int maxArgs){
+ StringBuffer fmla = new StringBuffer();
+ fmla.append(name);
+ fmla.append("(");
+ for(int i=0; i < maxArgs; i++){
+ if(i > 0) fmla.append(',');
+ fmla.append("A1");
+ }
+ fmla.append(")");
+ return fmla.toString();
+ }
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org