* Tracks whether the run of whitespace preceding "look" could be an
* intersection operator. See GetChar.
*/
- private boolean _inIntersection = false;
+ private boolean _inIntersection;
private final FormulaParsingWorkbook _book;
private final SpreadsheetVersion _ssVersion;
* This class is recommended only for single threaded use.
*
* If you have a {@link org.apache.poi.hssf.usermodel.HSSFWorkbook}, and not a
- * {@link org.apache.poi.hssf.model.Workbook}, then use the convenience method on
+ * {@link org.apache.poi.ss.usermodel.Workbook}, then use the convenience method on
* {@link org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator}
*/
private FormulaParser(String formula, FormulaParsingWorkbook book, int sheetIndex, int rowIndex) {
/** Get a Number */
private String GetNum() {
- StringBuffer value = new StringBuffer();
+ StringBuilder value = new StringBuilder();
while (IsDigit(this.look)){
value.append(this.look);
GetChar();
}
// parse column quantifier
- String startColumnName = null;
+ String startColumnName;
String endColumnName = null;
int nColQuantifiers = 0;
int savePtr1 = _pointer;
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(64);
- sb.append(getClass().getName()).append(" [");
- sb.append(_rep);
- sb.append("]");
- return sb.toString();
+ return getClass().getName() + " [" + _rep + "]";
}
}
+
+ private String getBookName() {
+ StringBuilder sb = new StringBuilder();
+ GetChar();
+ while (look != ']') {
+ sb.append(look);
+ GetChar();
+ }
+ GetChar();
+ return sb.toString();
+ }
/**
* Note - caller should reset {@link #_pointer} upon <code>null</code> result
private SheetIdentifier parseSheetName() {
String bookName;
if (look == '[') {
- StringBuilder sb = new StringBuilder();
- GetChar();
- while (look != ']') {
- sb.append(look);
- GetChar();
- }
- GetChar();
- bookName = sb.toString();
+ bookName = getBookName();
} else {
bookName = null;
}
if (look == '\'') {
- StringBuffer sb = new StringBuffer();
-
Match('\'');
+
+ if (look == '[')
+ bookName = getBookName();
+
+ StringBuilder sb = new StringBuilder();
boolean done = look == '\'';
while(!done) {
sb.append(look);
boolean result = CellReference.classifyCellReference(str, _ssVersion) == NameType.CELL;
if(result){
- /**
+ /*
* Check if the argument is a function. Certain names can be either a cell reference or a function name
* depending on the contenxt. Compare the following examples in Excel 2007:
* (a) LOG10(100) + 1
* Adds a name (named range or user defined function) to underlying workbook's names table
* @param functionName
*/
- private final void addName(String functionName) {
+ private void addName(String functionName) {
final Name name = _book.createName();
name.setFunction(true);
name.setNameName(functionName);
* return Int or Number Ptg based on size of input
*/
private static Ptg getNumberPtgFromString(String number1, String number2, String exponent) {
- StringBuffer number = new StringBuffer();
+ StringBuilder number = new StringBuilder();
if (number2 == null) {
number.append(number1);
private String parseStringLiteral() {
Match('"');
- StringBuffer token = new StringBuffer();
+ StringBuilder token = new StringBuilder();
while (true) {
if (look == '"') {
GetChar();
//{--------------------------------------------------------------}
//{ Parse and Translate an Assignment Statement }
- /**
+ /*
procedure Assignment;
var Name: string[8];
begin
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.usermodel.XSSFEvaluationWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.junit.Ignore;
import org.junit.Test;
/**
}
// bug 60219: FormulaParser can't parse external references when sheet name is quoted
- @Ignore
@Test
public void testParseExternalReferencesWithQuotedSheetName() throws Exception {
XSSFWorkbook wb = new XSSFWorkbook();
}
}
- private final static void assertEqualsIgnoreCase(String expected, String actual) {
+ private static void assertEqualsIgnoreCase(String expected, String actual) {
assertEquals(expected.toLowerCase(Locale.ROOT), actual.toLowerCase(Locale.ROOT));
}
HSSFSheet sheet = wb.createSheet("Test");
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0);
- String formula = null;
+ String formula;
cell.setCellFormula("1.3E21/3");
formula = cell.getCellFormula();
HSSFSheet sheet = wb.createSheet("Test");
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0);
- String formula = null;
+ String formula;
// starts from decimal point
HSSFSheet sheet = wb.createSheet("Test");
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0);
- String formula = null;
+ String formula;
cell.setCellFormula("A1.A2");
formula = cell.getCellFormula();
HSSFSheet sheet = wb.createSheet("Test");
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0);
- String formula = null;
+ String formula;
// References to a single cell:
assertEquals(65534.6, np.getValue(), 0);
}
+ @Test
public void testMissingArgs() {
-
confirmTokenClasses("if(A1, ,C1)",
RefPtg.class,
AttrPtg.class, // tAttrIf
}
/**
- * TODO - delete equiv test:
- * {@link BaseTestBugzillaIssues#test42448()}
+ * See the related/similar test: {@link BaseTestBugzillaIssues#bug42448()}
*/
@Test
public void testParseAbnormalSheetNamesAndRanges_bug42448() throws IOException {
@Test
public void testUnionOfFullCollFullRowRef() throws IOException {
- Ptg[] ptgs;
- ptgs = parseFormula("3:4");
- ptgs = parseFormula("$Z:$AC");
+ parseFormula("3:4");
+ Ptg[] ptgs = parseFormula("$Z:$AC");
confirmTokenClasses(ptgs, AreaPtg.class);
- ptgs = parseFormula("B:B");
+ parseFormula("B:B");
ptgs = parseFormula("$11:$13");
confirmTokenClasses(ptgs, AreaPtg.class);
}
};
- /**
+ /*
* register the two test UDFs in a UDF finder, to be passed to the evaluator
*/
UDFFinder udff1 = new DefaultUDFFinder(new String[] { "myFunc", },
assertEquals("'[$http://gagravarr.org/FormulaRefs.xls]Sheet1'!B1", row.getCell(1).getCellFormula());
assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0);
+ // Link our new workbook
+ Workbook externalWb1 = new HSSFWorkbook();
+ externalWb1.createSheet("Sheet1");
+ wb1.linkExternalWorkbook("$http://gagravarr.org/FormulaRefs2.xls", externalWb1);
+
// Change 4
row.getCell(1).setCellFormula("'[$http://gagravarr.org/FormulaRefs2.xls]Sheet1'!B2");
row.getCell(1).setCellValue(123.0);
+ // Link our new workbook
+ Workbook externalWb2 = new HSSFWorkbook();
+ externalWb2.createSheet("Sheet1");
+ wb1.linkExternalWorkbook("$http://example.com/FormulaRefs.xls", externalWb2);
+
// Add 5
row = s.createRow(5);
row.createCell(1, CellType.FORMULA);
row.getCell(1).setCellFormula("'[$http://example.com/FormulaRefs.xls]Sheet1'!B1");
row.getCell(1).setCellValue(234.0);
-
// Re-test
HSSFWorkbook wb2 = writeOutAndReadBack(wb1);
wb1.close();
assertEquals("[Formulas2.xls]Sheet1!B2", row.getCell(1).getCellFormula());
assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0);
- // TODO - Fix these so they work...
- /*row = s.getRow(4);
+ row = s.getRow(4);
assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum());
assertEquals("'[$http://gagravarr.org/FormulaRefs2.xls]Sheet1'!B2", row.getCell(1).getCellFormula());
assertEquals(123.0, row.getCell(1).getNumericCellValue(), 0);
row = s.getRow(5);
assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum());
assertEquals("'[$http://example.com/FormulaRefs.xls]Sheet1'!B1", row.getCell(1).getCellFormula());
- assertEquals(234.0, row.getCell(1).getNumericCellValue(), 0);*/
+ assertEquals(234.0, row.getCell(1).getNumericCellValue(), 0);
wb2.close();
}