mirror of https://github.com/apache/poi.git
encapsulated hasUnlimitedVarags() logic into FunctionMetadata
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@775575 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2c2948ca65
commit
f5b2085652
|
@ -16,12 +16,24 @@
|
|||
==================================================================== */
|
||||
|
||||
package org.apache.poi.hssf.record.formula.function;
|
||||
|
||||
import org.apache.poi.ss.SpreadsheetVersion;
|
||||
|
||||
/**
|
||||
* Holds information about Excel built-in functions.
|
||||
*
|
||||
* @author Josh Micich
|
||||
*/
|
||||
public final class FunctionMetadata {
|
||||
/**
|
||||
* 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.
|
||||
* Perhaps a value like 'M' should be used instead of '30' in functionMetadata.txt
|
||||
* to make that file more version neutral.
|
||||
* @see org.apache.poi.ss.formula.FormulaParser#validateNumArgs(int, FunctionMetadata)
|
||||
*/
|
||||
private static final short FUNCTION_MAX_PARAMS = 30;
|
||||
|
||||
private final int _index;
|
||||
private final String _name;
|
||||
|
@ -58,7 +70,17 @@ public final class FunctionMetadata {
|
|||
return _returnClassCode;
|
||||
}
|
||||
public byte[] getParameterClassCodes() {
|
||||
return (byte[]) _parameterClassCodes.clone();
|
||||
return _parameterClassCodes.clone();
|
||||
}
|
||||
/**
|
||||
* Some varags functions (like VLOOKUP) have a specific limit to the number of arguments that
|
||||
* can be passed. Other functions (like SUM) don't have such a limit. For those functions,
|
||||
* the spreadsheet version determines the maximum number of arguments that can be passed.
|
||||
* @return <code>true</code> if this function can the maximum number of arguments allowable by
|
||||
* the {@link SpreadsheetVersion}
|
||||
*/
|
||||
public boolean hasUnlimitedVarags() {
|
||||
return FUNCTION_MAX_PARAMS == _maxParams;
|
||||
}
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer(64);
|
||||
|
|
|
@ -20,7 +20,7 @@ package org.apache.poi.hssf.record.formula.function;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
/**
|
||||
* Allows clients to get <tt>FunctionMetadata</tt> instances for any built-in function of Excel.
|
||||
* Allows clients to get {@link FunctionMetadata} instances for any built-in function of Excel.
|
||||
*
|
||||
* @author Josh Micich
|
||||
*/
|
||||
|
@ -30,14 +30,6 @@ public final class FunctionMetadataRegistry {
|
|||
*/
|
||||
public static final String FUNCTION_NAME_IF = "IF";
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
|
|
@ -31,7 +31,6 @@ import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
|
|||
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.
|
||||
|
@ -985,10 +984,16 @@ public final class FormulaParser {
|
|||
throw new FormulaParseException(msg);
|
||||
}
|
||||
//the maximum number of arguments depends on the Excel version
|
||||
int maxArgs = fm.getMaxParams();
|
||||
if( maxArgs == FunctionMetadataRegistry.FUNCTION_MAX_PARAMS) {
|
||||
int maxArgs;
|
||||
if (fm.hasUnlimitedVarags()) {
|
||||
if(_book != null) {
|
||||
maxArgs = _book.getSpreadsheetVersion().getMaxFunctionArgs();
|
||||
} else {
|
||||
//_book can be omitted by test cases
|
||||
if(_book != null) maxArgs = _book.getSpreadsheetVersion().getMaxFunctionArgs();
|
||||
maxArgs = fm.getMaxParams(); // just use BIFF8
|
||||
}
|
||||
} else {
|
||||
maxArgs = fm.getMaxParams();
|
||||
}
|
||||
|
||||
if(numArgs > maxArgs) {
|
||||
|
|
Loading…
Reference in New Issue