return sheetIndex;
}
- public int getExternalSheetIndex(String sheetName) {
- int sheetIndex = _uBook.getSheetIndex(sheetName);
- return convertToExternalSheetIndex(sheetIndex);
- }
-
- private int resolveBookIndex(String bookName) {
- // Is it already in numeric form?
- if (bookName.startsWith("[") && bookName.endsWith("]")) {
- bookName = bookName.substring(1, bookName.length()-2);
- try {
- return Integer.parseInt(bookName);
- } catch (NumberFormatException e) {}
- }
-
- // Look up an External Link Table for this name
- throw new RuntimeException("Not implemented yet"); // TODO
- }
+ public int getExternalSheetIndex(String sheetName) {
+ int sheetIndex = _uBook.getSheetIndex(sheetName);
+ return convertToExternalSheetIndex(sheetIndex);
+ }
+
+ private int resolveBookIndex(String bookName) {
+ // Strip the [] wrapper, if still present
+ if (bookName.startsWith("[") && bookName.endsWith("]")) {
+ bookName = bookName.substring(1, bookName.length()-2);
+ }
+
+ // Is it already in numeric form?
+ try {
+ return Integer.parseInt(bookName);
+ } catch (NumberFormatException e) {}
+
+ // Look up an External Link Table for this name
+ throw new RuntimeException("Not implemented yet for book " + bookName); // TODO
+ }
public EvaluationName getName(String name, int sheetIndex) {
for (int i = 0; i < _uBook.getNumberOfNames(); i++) {
}
// Otherwise, try it as a named range
+ if (sheet._sheetIdentifier == null) {
+ // Workbook + Named Range only
+ int bookIndex = resolveBookIndex(sheet._bookName);
+ return new NameXPxg(bookIndex, null, name);
+ }
+
+ // Use the sheetname and process
String sheetName = sheet._sheetIdentifier.getName();
if (sheet._bookName != null) {
import org.apache.poi.ss.formula.FormulaType;
import org.apache.poi.ss.formula.ptg.FuncPtg;
import org.apache.poi.ss.formula.ptg.IntPtg;
+import org.apache.poi.ss.formula.ptg.NameXPxg;
import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.ss.formula.ptg.Ref3DPxg;
import org.apache.poi.ss.formula.ptg.RefPtg;
assertTrue("", ptgs[1] instanceof FuncPtg);
}
+ @Test
+ public void formaulReferncesSameWorkbook() {
+ // Use a test file with "other workbook" style references
+ // to itself
+ XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56737.xlsx");
+ XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb);
+ Ptg[] ptgs;
+
+ // Reference to a named range in our own workbook, as if it
+ // were defined in a different workbook
+ ptgs = parse(fpb, "[0]!NR_Global_B2");
+ assertEquals(1, ptgs.length);
+ assertEquals(NameXPxg.class, ptgs[0].getClass());
+ assertEquals(null, ((NameXPxg)ptgs[0]).getSheetName());
+ assertEquals("NR_Global_B2",((NameXPxg)ptgs[0]).getNameName());
+ assertEquals("[0]!NR_Global_B2",((NameXPxg)ptgs[0]).toFormulaString());
+ }
+
@Test
- @Ignore("Work in progress, see bug #56737")
+ @Ignore("Work in progress, see bug #56737")
public void formulaReferencesOtherSheets() {
// Use a test file with the named ranges in place
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("ref-56737.xlsx");
// Reference to a sheet scoped named range from another sheet
ptgs = parse(fpb, "Defines!NR_To_A1");
assertEquals(1, ptgs.length);
- // TODO assert
+ assertEquals(NameXPxg.class, ptgs[0].getClass());
+ assertEquals("Defines", ((NameXPxg)ptgs[0]).getSheetName());
+ assertEquals("NR_To_A1",((NameXPxg)ptgs[0]).getNameName());
+ assertEquals("Defines!NR_To_A1",((NameXPxg)ptgs[0]).toFormulaString());
// Reference to a workbook scoped named range
ptgs = parse(fpb, "NR_Global_B2");
// TODO assert
}
- @Test
- @Ignore("Work in progress, see bug #56737")
- public void fFormaulReferncesSameWorkbook() {
- // Use a test file with "other workbook" style references
- // to itself
- XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56737.xlsx");
- XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb);
- Ptg[] ptgs;
-
- // Reference to a named range in our own workbook, as if it
- // were defined in a different workbook
- ptgs = parse(fpb, "[0]!NR_Global_B2");
- assertEquals(1, ptgs.length);
- // TODO assert
- }
-
@Test
@Ignore("Work in progress, see bug #56737")
public void formulaReferencesOtherWorkbook() {