]> source.dussan.org Git - poi.git/commitdiff
Add unit test for bug #45970 - shows that we can read Formulas with URL based referen...
authorNick Burch <nick@apache.org>
Fri, 4 Jun 2010 14:40:01 +0000 (14:40 +0000)
committerNick Burch <nick@apache.org>
Fri, 4 Jun 2010 14:40:01 +0000 (14:40 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@951420 13f79535-47bb-0310-9956-ffa450edef68

src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
test-data/spreadsheet/FormulaRefs.xls [new file with mode: 0644]

index c6b47848f76f90a81d19cb5c948e3ec9a0f28d43..01510b087d8c96fcf81b5da88ef36d1b9e710b6e 100644 (file)
@@ -1588,4 +1588,87 @@ public final class TestBugs extends BaseTestBugzillaIssues {
        wb = writeOutAndReadBack(wb);
        assertEquals(2, wb.getNumberOfSheets());
     }
+    
+    /**
+     * Problems with formula references to 
+     *  sheets via URLs
+     */
+    public void test45970() throws Exception {
+       HSSFWorkbook wb = openSample("FormulaRefs.xls");
+       assertEquals(3, wb.getNumberOfSheets());
+       
+       HSSFSheet s = wb.getSheetAt(0);
+       HSSFRow row;
+       
+       row = s.getRow(0);
+       assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(1).getCellType());
+       assertEquals(112.0, row.getCell(1).getNumericCellValue());
+       
+       row = s.getRow(1);
+       assertEquals(Cell.CELL_TYPE_FORMULA, row.getCell(1).getCellType());
+       assertEquals("B1", row.getCell(1).getCellFormula());
+       assertEquals(112.0, row.getCell(1).getNumericCellValue());
+       
+       row = s.getRow(2);
+       assertEquals(Cell.CELL_TYPE_FORMULA, row.getCell(1).getCellType());
+       assertEquals("Sheet1!B1", row.getCell(1).getCellFormula());
+       assertEquals(112.0, row.getCell(1).getNumericCellValue());
+       
+       row = s.getRow(3);
+       assertEquals(Cell.CELL_TYPE_FORMULA, row.getCell(1).getCellType());
+       assertEquals("[Formulas2.xls]Sheet1!B2", row.getCell(1).getCellFormula());
+       assertEquals(112.0, row.getCell(1).getNumericCellValue());
+       
+       row = s.getRow(4);
+       assertEquals(Cell.CELL_TYPE_FORMULA, row.getCell(1).getCellType());
+       assertEquals("'[\u0005$http://gagravarr.org/FormulaRefs.xls]Sheet1'!B1", row.getCell(1).getCellFormula());
+       assertEquals(112.0, row.getCell(1).getNumericCellValue());
+       
+       // Change 4
+       row.getCell(1).setCellFormula("'[\u0005$http://gagravarr.org/FormulaRefs2.xls]Sheet1'!B2");
+       row.getCell(1).setCellValue(123.0);
+       
+       // Add 5
+       row = s.createRow(5);
+       row.createCell(1, Cell.CELL_TYPE_FORMULA);
+       row.getCell(1).setCellFormula("'[\u0005$http://example.com/FormulaRefs.xls]Sheet1'!B1");
+       row.getCell(1).setCellValue(234.0);
+       
+       
+       // Re-test
+       wb = writeOutAndReadBack(wb);
+       s = wb.getSheetAt(0);
+       
+       row = s.getRow(0);
+       assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(1).getCellType());
+       assertEquals(112.0, row.getCell(1).getNumericCellValue());
+       
+       row = s.getRow(1);
+       assertEquals(Cell.CELL_TYPE_FORMULA, row.getCell(1).getCellType());
+       assertEquals("B1", row.getCell(1).getCellFormula());
+       assertEquals(112.0, row.getCell(1).getNumericCellValue());
+       
+       row = s.getRow(2);
+       assertEquals(Cell.CELL_TYPE_FORMULA, row.getCell(1).getCellType());
+       assertEquals("Sheet1!B1", row.getCell(1).getCellFormula());
+       assertEquals(112.0, row.getCell(1).getNumericCellValue());
+       
+       row = s.getRow(3);
+       assertEquals(Cell.CELL_TYPE_FORMULA, row.getCell(1).getCellType());
+       assertEquals("[Formulas2.xls]Sheet1!B2", row.getCell(1).getCellFormula());
+       assertEquals(112.0, row.getCell(1).getNumericCellValue());
+       
+// TODO - Fix these so they work...
+if(1==2) {
+       row = s.getRow(4);
+       assertEquals(Cell.CELL_TYPE_FORMULA, row.getCell(1).getCellType());
+       assertEquals("'[\u0005$http://gagravarr.org/FormulaRefs2.xls]Sheet1'!B2", row.getCell(1).getCellFormula());
+       assertEquals(123.0, row.getCell(1).getNumericCellValue());
+       
+       row = s.getRow(5);
+       assertEquals(Cell.CELL_TYPE_FORMULA, row.getCell(1).getCellType());
+       assertEquals("'[\u0005$http://example.com/FormulaRefs.xls]Sheet1'!B1", row.getCell(1).getCellFormula());
+       assertEquals(234.0, row.getCell(1).getNumericCellValue());
+}
+    }
 }
diff --git a/test-data/spreadsheet/FormulaRefs.xls b/test-data/spreadsheet/FormulaRefs.xls
new file mode 100644 (file)
index 0000000..72da547
Binary files /dev/null and b/test-data/spreadsheet/FormulaRefs.xls differ