View | Details | Raw Unified | Return to bug 60219
Collapse All | Expand All

(-)src/java/org/apache/poi/ss/formula/FormulaParser.java (-10 / +18 lines)
Lines 1119-1124 Link Here
1119
            return sb.toString();
1119
            return sb.toString();
1120
        }
1120
        }
1121
    }
1121
    }
1122
    
1123
    private String getBookName() {
1124
        StringBuilder sb = new StringBuilder();
1125
        // at this point look == '['
1126
        GetChar();
1127
        while (look != ']') {
1128
            sb.append(look);
1129
            GetChar();
1130
        }
1131
        GetChar(); // ignore closing bracket ']'
1132
        return sb.toString();
1133
    }
1122
1134
1123
    /**
1135
    /**
1124
     * Note - caller should reset {@link #_pointer} upon <code>null</code> result
1136
     * Note - caller should reset {@link #_pointer} upon <code>null</code> result
Lines 1127-1148 Link Here
1127
    private SheetIdentifier parseSheetName() {
1139
    private SheetIdentifier parseSheetName() {
1128
        String bookName;
1140
        String bookName;
1129
        if (look == '[') {
1141
        if (look == '[') {
1130
            StringBuilder sb = new StringBuilder();
1142
        	bookName = getBookName();
1131
            GetChar();
1132
            while (look != ']') {
1133
                sb.append(look);
1134
                GetChar();
1135
            }
1136
            GetChar();
1137
            bookName = sb.toString();
1138
        } else {
1143
        } else {
1139
            bookName = null;
1144
            bookName = null;
1140
        }
1145
        }
1141
1146
1142
        if (look == '\'') {
1147
        if (look == '\'') {
1148
            Match('\'');
1149
            
1150
            if (look == '[')
1151
            	bookName = getBookName();
1152
            
1143
            StringBuffer sb = new StringBuffer();
1153
            StringBuffer sb = new StringBuffer();
1144
1145
            Match('\'');
1146
            boolean done = look == '\'';
1154
            boolean done = look == '\'';
1147
            while(!done) {
1155
            while(!done) {
1148
                sb.append(look);
1156
                sb.append(look);
(-)src/ooxml/testcases/org/apache/poi/ss/formula/TestFormulaParser.java (+33 lines)
Lines 28-33 Link Here
28
import org.apache.poi.ss.formula.ptg.AbstractFunctionPtg;
28
import org.apache.poi.ss.formula.ptg.AbstractFunctionPtg;
29
import org.apache.poi.ss.formula.ptg.NameXPxg;
29
import org.apache.poi.ss.formula.ptg.NameXPxg;
30
import org.apache.poi.ss.formula.ptg.Ptg;
30
import org.apache.poi.ss.formula.ptg.Ptg;
31
import org.apache.poi.ss.formula.ptg.Ref3DPxg;
31
import org.apache.poi.ss.formula.ptg.StringPtg;
32
import org.apache.poi.ss.formula.ptg.StringPtg;
32
import org.apache.poi.xssf.XSSFTestDataSamples;
33
import org.apache.poi.xssf.XSSFTestDataSamples;
33
import org.apache.poi.xssf.usermodel.XSSFEvaluationWorkbook;
34
import org.apache.poi.xssf.usermodel.XSSFEvaluationWorkbook;
Lines 169-172 Link Here
169
            assertNotNull(e.getMessage());
170
            assertNotNull(e.getMessage());
170
        }
171
        }
171
    }
172
    }
173
    
174
    @Test
175
    public void testParseExternalReferencesWithUnquotedSheetName() throws Exception {
176
        XSSFWorkbook wb = new XSSFWorkbook();
177
        XSSFEvaluationWorkbook fpwb = XSSFEvaluationWorkbook.create(wb);
178
        Ptg[] ptgs = FormulaParser.parse("[1]Sheet1!A1", fpwb, FormulaType.CELL, -1);
179
        // org.apache.poi.ss.formula.ptg.Ref3DPxg [ [workbook=1] sheet=Sheet 1 ! A1]
180
        assertEquals("Ptgs length", 1, ptgs.length);
181
        assertTrue("Ptg class", ptgs[0] instanceof Ref3DPxg);
182
        Ref3DPxg pxg = (Ref3DPxg) ptgs[0];
183
        assertEquals("External workbook number", 1, pxg.getExternalWorkbookNumber());
184
        assertEquals("Sheet name", "Sheet1", pxg.getSheetName());
185
        assertEquals("Row", 0, pxg.getRow());
186
        assertEquals("Column", 0, pxg.getColumn());
187
        wb.close();
188
    }
189
    
190
    @Test
191
    public void testParseExternalReferencesWithQuotedSheetName() throws Exception {
192
        XSSFWorkbook wb = new XSSFWorkbook();
193
        XSSFEvaluationWorkbook fpwb = XSSFEvaluationWorkbook.create(wb);
194
        Ptg[] ptgs = FormulaParser.parse("'[1]Sheet 1'!A1", fpwb, FormulaType.CELL, -1);
195
        // org.apache.poi.ss.formula.ptg.Ref3DPxg [ [workbook=1] sheet=Sheet 1 ! A1]
196
        assertEquals("Ptgs length", 1, ptgs.length);
197
        assertTrue("Ptg class", ptgs[0] instanceof Ref3DPxg);
198
        Ref3DPxg pxg = (Ref3DPxg) ptgs[0];
199
        assertEquals("External workbook number", 1, pxg.getExternalWorkbookNumber());
200
        assertEquals("Sheet name", "Sheet 1", pxg.getSheetName());
201
        assertEquals("Row", 0, pxg.getRow());
202
        assertEquals("Column", 0, pxg.getColumn());
203
        wb.close();
204
    }
172
}
205
}

Return to bug 60219