]> source.dussan.org Git - poi.git/commitdiff
Some more XSSF testing for #57184
authorNick Burch <nick@apache.org>
Tue, 4 Nov 2014 22:00:09 +0000 (22:00 +0000)
committerNick Burch <nick@apache.org>
Tue, 4 Nov 2014 22:00:09 +0000 (22:00 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1636750 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java

index 7164534d3b206f02e4f0fc899490b9f4b5867a34..119f77507e5d659931e7e628b8f6e5e47e3a4ecc 100644 (file)
@@ -1705,16 +1705,16 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
     }
 
     /**
-     * Adds the LinkTable records required to allow formulas referencing
-     *  the specified external workbook to be added to this one. Allows
+     * Adds the External Link Table part and relations required to allow formulas 
+     *  referencing the specified external workbook to be added to this one. Allows
      *  formulas such as "[MyOtherWorkbook.xlsx]Sheet3!$A$5" to be added to the 
-     *  file, for workbooks not already referenced.
+     *  file, for workbooks not already linked / referenced.
      *
      * @param name The name the workbook will be referenced as in formulas
      * @param workbook The open workbook to fetch the link required information from
      */
     public int linkExternalWorkbook(String name, Workbook workbook) {
-        throw new RuntimeException("NotImplemented");
+        throw new RuntimeException("Not Implemented - see bug #57184");
     }
 
        /**
index 508844fdd11aead60b1042937e369d55ca479470..c2a7597d388c8e76ec2f013e0f210ae40491f0d9 100644 (file)
@@ -167,12 +167,32 @@ public final class TestXSSFFormulaEvaluation extends BaseTestFormulaEvaluator {
         assertEquals("\"Test A1\"", evaluator.evaluate(cXSL_sNR).formatAsString());
         assertEquals("142.0",   evaluator.evaluate(cXSL_gNR).formatAsString());
         
-/**        
+        
+        // Add another formula referencing these workbooks
+        Cell cXSL_cell2 = rXSL.createCell(40);
+        cXSL_cell2.setCellFormula("[56737.xls]Uses!$C$1");
+        // TODO Shouldn't it become [2] like the others?
+        assertEquals("[56737.xls]Uses!$C$1", cXSL_cell2.getCellFormula());
+        assertEquals("\"Hello!\"",  evaluator.evaluate(cXSL_cell2).formatAsString());
+        
+        
         // Now add a formula that refers to yet another (different) workbook
+        // Won't work without the workbook being linked
         Cell cXSLX_nw_cell = rXSLX.createCell(42);
-        cXSLX_nw_cell.setCellFormula("[alt.xlsx]Sheet1!$A$1");
+        try {
+            cXSLX_nw_cell.setCellFormula("[alt.xlsx]Sheet1!$A$1");
+            fail("New workbook not linked, shouldn't be able to add");
+        } catch (Exception e) {}
         
-        // Check it - TODO Is this correct? Or should it become [2]Sheet1!$A$1 ?
+        // Link and re-try
+        Workbook alt = new XSSFWorkbook();
+        alt.createSheet().createRow(0).createCell(0).setCellValue("In another workbook");
+        // TODO Implement the rest of this, see bug #57184
+/*
+        wb.linkExternalWorkbook("alt.xlsx", alt);
+                
+        cXSLX_nw_cell.setCellFormula("[alt.xlsx]Sheet1!$A$1");
+        // Check it - TODO Is this correct? Or should it become [3]Sheet1!$A$1 ?
         assertEquals("[alt.xlsx]Sheet1!$A$1", cXSLX_nw_cell.getCellFormula());
         
         // Evaluate it, without a link to that workbook
@@ -182,8 +202,6 @@ public final class TestXSSFFormulaEvaluation extends BaseTestFormulaEvaluator {
         } catch(Exception e) {}
         
         // Add a link, check it does
-        Workbook alt = new XSSFWorkbook();
-        alt.createSheet().createRow(0).createCell(0).setCellValue("In another workbook");
         evaluators.put("alt.xlsx", alt.getCreationHelper().createFormulaEvaluator());
         evaluator.setupReferencedWorkbooks(evaluators);