import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
-import java.util.regex.Pattern;
//import PTGs .. since we need everything, import *
import org.apache.poi.hssf.record.formula.*;
/** Report What Was Expected */
private RuntimeException expected(String s) {
- String msg = "Parse error near char " + (pointer-1) + " '" + look + "'"
- + " in specified formula '" + formulaString + "'. Expected "
- + s;
+ String msg;
+
+ if (look == '=' && formulaString.substring(0, pointer-1).trim().length() < 1) {
+ msg = "The specified formula '" + formulaString
+ + "' starts with an equals sign which is not allowed.";
+ } else {
+ msg = "Parse error near char " + (pointer-1) + " '" + look + "'"
+ + " in specified formula '" + formulaString + "'. Expected "
+ + s;
+ }
return new FormulaParseException(msg);
}
HSSFRow row = sheet.createRow(0);
HSSFCell cell;
- cell = row.createCell((short)0);
+ cell = row.createCell(0);
cell.setCellFormula("NoQuotesNeeded!A1");
- cell = row.createCell((short)1);
+ cell = row.createCell(1);
cell.setCellFormula("'Quotes Needed Here &#$@'!A1");
}
HSSFRow row = sheet.createRow(0);
HSSFCell cell;
- cell = row.createCell((short)0);
+ cell = row.createCell(0);
cell.setCellFormula("Cash_Flow!A1");
}
HSSFSheet sheet = wb.createSheet("Test");
HSSFRow row = sheet.createRow(0);
- HSSFCell cell = row.createCell((short)0);
+ HSSFCell cell = row.createCell(0);
String formula = null;
cell.setCellFormula("1.3E21/3");
HSSFSheet sheet = wb.createSheet("Test");
HSSFRow row = sheet.createRow(0);
- HSSFCell cell = row.createCell((short)0);
+ HSSFCell cell = row.createCell(0);
String formula = null;
// starts from decimal point
HSSFSheet sheet = wb.createSheet("Test");
HSSFRow row = sheet.createRow(0);
- HSSFCell cell = row.createCell((short)0);
+ HSSFCell cell = row.createCell(0);
String formula = null;
cell.setCellFormula("A1.A2");
confirmParseErrorLiteral(ErrPtg.NAME_INVALID, "#NAME?");
confirmParseErrorLiteral(ErrPtg.NUM_ERROR, "#NUM!");
confirmParseErrorLiteral(ErrPtg.N_A, "#N/A");
+ parseFormula("HLOOKUP(F7,#REF!,G7,#REF!)");
}
private static void confirmParseErrorLiteral(ErrPtg expectedToken, String formula) {
wb.setSheetName(0, "Sheet1");
HSSFRow row = sheet.createRow(0);
- HSSFCell cell = row.createCell((short)0);
+ HSSFCell cell = row.createCell(0);
cell.setCellFormula("right(\"test\"\"ing\", 3)");
String actualCellFormula = cell.getCellFormula();
if("RIGHT(\"test\"ing\",3)".equals(actualCellFormula)) {
wb.setSheetName(0, "Sheet1");
HSSFRow row = sheet.createRow(0);
- HSSFCell cell = row.createCell((short)0);
+ HSSFCell cell = row.createCell(0);
cell.setCellFormula("SUM(A32769:A32770)");
if("SUM(A-32767:A-32766)".equals(cell.getCellFormula())) {
fail("Identified bug 44539");
} catch (FormulaParseException e) {
assertEquals("Parse error near char 10 ';' in specified formula 'round(3.14;2)'. Expected ',' or ')'", e.getMessage());
}
+
+ try {
+ parseFormula(" =2+2");
+ throw new AssertionFailedError("Didn't get parse exception as expected");
+ } catch (FormulaParseException e) {
+ assertEquals("The specified formula ' =2+2' starts with an equals sign which is not allowed.", e.getMessage());
+ }
}
/**
assertEquals(2, ptgs.length);
assertEquals(NamePtg.class, ptgs[0].getClass());
- HSSFCell cell = sheet.createRow(0).createCell((short)0);
+ HSSFCell cell = sheet.createRow(0).createCell(0);
cell.setCellFormula("count(pfy1)");
assertEquals("COUNT(pfy1)", cell.getCellFormula());
try {
}
}
cell.setCellFormula("count(fp1)"); // plain cell ref, col is in range
-
}
}