예제 #1
0
  private void validateNumArgs(int numArgs, FunctionMetadata fm) {
    if (numArgs < fm.getMinParams()) {
      String msg = "Too few arguments to function '" + fm.getName() + "'. ";
      if (fm.hasFixedArgsLength()) {
        msg += "Expected " + fm.getMinParams();
      } else {
        msg += "At least " + fm.getMinParams() + " were expected";
      }
      msg += " but got " + numArgs + ".";
      throw new FormulaParseException(msg);
    }
    // the maximum number of arguments depends on the Excel version
    int maxArgs;
    if (fm.hasUnlimitedVarags()) {
      if (_book != null) {
        maxArgs = _book.getSpreadsheetVersion().getMaxFunctionArgs();
      } else {
        // _book can be omitted by test cases
        maxArgs = fm.getMaxParams(); // just use BIFF8
      }
    } else {
      maxArgs = fm.getMaxParams();
    }

    if (numArgs > maxArgs) {
      String msg = "Too many arguments to function '" + fm.getName() + "'. ";
      if (fm.hasFixedArgsLength()) {
        msg += "Expected " + maxArgs;
      } else {
        msg += "At most " + maxArgs + " were expected";
      }
      msg += " but got " + numArgs + ".";
      throw new FormulaParseException(msg);
    }
  }
예제 #2
0
 /**
  * Create the formula parser, with the string that is to be parsed against the supplied workbook.
  * A later call the parse() method to return ptg list in rpn order, then call the getRPNPtg() to
  * retrieve the parse results. This class is recommended only for single threaded use.
  *
  * <p>If you only have a usermodel.HSSFWorkbook, and not a model.Workbook, then use the
  * convenience method on usermodel.HSSFFormulaEvaluator
  */
 private FormulaParser(String formula, FormulaParsingWorkbook book, int sheetIndex) {
   _formulaString = formula;
   _pointer = 0;
   _book = book;
   _ssVersion = book == null ? SpreadsheetVersion.EXCEL97 : book.getSpreadsheetVersion();
   _formulaLength = _formulaString.length();
   _sheetIndex = sheetIndex;
 }