Sheet sheet1 = wb.createSheet("Sheet1");
Sheet sheet2 = wb.createSheet("Sheet2");
Sheet sheet3 = wb.createSheet("Sheet 3");
+ Sheet sheet4 = wb.createSheet("Sheet4>");
Row tempRow = sheet1.createRow(0);
tempRow.createCell(0).setCellValue(1);
tempRow.createCell(0).setCellValue(5);
tempRow.createCell(1).setCellValue(6);
+ tempRow = sheet4.createRow(0);
+ tempRow.createCell(0).setCellValue(5);
+ tempRow.createCell(1).setCellValue(6);
+
Cell cell = tempRow.createCell(2);
// unquoted sheet names
cell.setCellFormula(formula);
cellFormula = cell.getCellFormula();
assertEquals(formula, cellFormula);
+
+ // quoted sheet names with special character
+ cell = tempRow.createCell(5);
+ formula = "SUM('Sheet1:Sheet4>'!A1:B1)";
+ cell.setCellFormula(formula);
+ cellFormula = cell.getCellFormula();
+ assertEquals(formula, cellFormula);
+
+ // quoted sheet names with special character #2
+// cell = tempRow.createCell(6);
+// formula = "SUM('Sheet 3:Sheet4>'!A1:B1)";
+// cell.setCellFormula(formula);
+// cellFormula = cell.getCellFormula();
+// assertEquals(formula, cellFormula);
}
}
private ParseNode parseRangeable() {
SkipWhite();
int savePointer = _pointer;
- SheetIdentifier sheetIden = parseSheetName();
+ SheetIdentifier sheetIden = parseSheetName(false);
if (sheetIden == null) {
resetPointer(savePointer);
* Note - caller should reset {@link #_pointer} upon {@code null} result
* @return The sheet name as an identifier {@code null} if '!' is not found in the right place
*/
- private SheetIdentifier parseSheetName() {
+ private SheetIdentifier parseSheetName(boolean isSndPartOfQuotedRange) {
String bookName;
if (look == '[') {
bookName = getBookName();
bookName = null;
}
- if (look == '\'') {
- Match('\'');
+ if (look == '\'' || isSndPartOfQuotedRange) {
+ if (!isSndPartOfQuotedRange) {
+ Match('\'');
+ }
if (look == '[')
bookName = getBookName();
}
// See if it's a multi-sheet range, eg Sheet1:Sheet3!A1
if (look == ':') {
- return parseSheetRange(bookName, iden);
+ return parseSheetRange(bookName, iden, true);
}
return null;
}
}
// See if it's a multi-sheet range, eg Sheet1:Sheet3!A1
if (look == ':') {
- return parseSheetRange(bookName, iden);
+ return parseSheetRange(bookName, iden, false);
}
return null;
}
* If we have something that looks like [book]Sheet1: or
* Sheet1, see if it's actually a range eg Sheet1:Sheet2!
*/
- private SheetIdentifier parseSheetRange(String bookname, NameIdentifier sheet1Name) {
+ private SheetIdentifier parseSheetRange(String bookname, NameIdentifier sheet1Name, boolean isSndPartOfQuotedRange) {
GetChar();
- SheetIdentifier sheet2 = parseSheetName();
+ SheetIdentifier sheet2 = parseSheetName(isSndPartOfQuotedRange);
if (sheet2 != null) {
return new SheetRangeIdentifier(bookname, sheet1Name, sheet2.getSheetIdentifier());
}
wb.createSheet("Cash_Flow");
wb.createSheet("Test Sheet");
+ wb.createSheet("Sheet 3>");
HSSFSheet sheet = wb.createSheet("Test");
HSSFRow row = sheet.createRow(0);
formula = cell.getCellFormula();
assertEquals("'Cash_Flow:Test Sheet'!A1", formula);
+ // special character
+ cell.setCellFormula("'Cash_Flow:Sheet 3>'!A1");
+ formula = cell.getCellFormula();
+ assertEquals("'Cash_Flow:Sheet 3>'!A1", formula);
// References to a range (area) of cells: