Skip to content

Commit 3b4a96b

Browse files
committed
Some more XSSF testing for #57184
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1636750 13f79535-47bb-0310-9956-ffa450edef68
1 parent 0fdd7a1 commit 3b4a96b

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,16 +1705,16 @@ public MapInfo getMapInfo(){
17051705
}
17061706

17071707
/**
1708-
* Adds the LinkTable records required to allow formulas referencing
1709-
* the specified external workbook to be added to this one. Allows
1708+
* Adds the External Link Table part and relations required to allow formulas
1709+
* referencing the specified external workbook to be added to this one. Allows
17101710
* formulas such as "[MyOtherWorkbook.xlsx]Sheet3!$A$5" to be added to the
1711-
* file, for workbooks not already referenced.
1711+
* file, for workbooks not already linked / referenced.
17121712
*
17131713
* @param name The name the workbook will be referenced as in formulas
17141714
* @param workbook The open workbook to fetch the link required information from
17151715
*/
17161716
public int linkExternalWorkbook(String name, Workbook workbook) {
1717-
throw new RuntimeException("NotImplemented");
1717+
throw new RuntimeException("Not Implemented - see bug #57184");
17181718
}
17191719

17201720
/**

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,32 @@ public void testReferencesToOtherWorkbooks() throws Exception {
167167
assertEquals("\"Test A1\"", evaluator.evaluate(cXSL_sNR).formatAsString());
168168
assertEquals("142.0", evaluator.evaluate(cXSL_gNR).formatAsString());
169169

170-
/**
170+
171+
// Add another formula referencing these workbooks
172+
Cell cXSL_cell2 = rXSL.createCell(40);
173+
cXSL_cell2.setCellFormula("[56737.xls]Uses!$C$1");
174+
// TODO Shouldn't it become [2] like the others?
175+
assertEquals("[56737.xls]Uses!$C$1", cXSL_cell2.getCellFormula());
176+
assertEquals("\"Hello!\"", evaluator.evaluate(cXSL_cell2).formatAsString());
177+
178+
171179
// Now add a formula that refers to yet another (different) workbook
180+
// Won't work without the workbook being linked
172181
Cell cXSLX_nw_cell = rXSLX.createCell(42);
173-
cXSLX_nw_cell.setCellFormula("[alt.xlsx]Sheet1!$A$1");
182+
try {
183+
cXSLX_nw_cell.setCellFormula("[alt.xlsx]Sheet1!$A$1");
184+
fail("New workbook not linked, shouldn't be able to add");
185+
} catch (Exception e) {}
174186

175-
// Check it - TODO Is this correct? Or should it become [2]Sheet1!$A$1 ?
187+
// Link and re-try
188+
Workbook alt = new XSSFWorkbook();
189+
alt.createSheet().createRow(0).createCell(0).setCellValue("In another workbook");
190+
// TODO Implement the rest of this, see bug #57184
191+
/*
192+
wb.linkExternalWorkbook("alt.xlsx", alt);
193+
194+
cXSLX_nw_cell.setCellFormula("[alt.xlsx]Sheet1!$A$1");
195+
// Check it - TODO Is this correct? Or should it become [3]Sheet1!$A$1 ?
176196
assertEquals("[alt.xlsx]Sheet1!$A$1", cXSLX_nw_cell.getCellFormula());
177197
178198
// Evaluate it, without a link to that workbook
@@ -182,8 +202,6 @@ public void testReferencesToOtherWorkbooks() throws Exception {
182202
} catch(Exception e) {}
183203
184204
// Add a link, check it does
185-
Workbook alt = new XSSFWorkbook();
186-
alt.createSheet().createRow(0).createCell(0).setCellValue("In another workbook");
187205
evaluators.put("alt.xlsx", alt.getCreationHelper().createFormulaEvaluator());
188206
evaluator.setupReferencedWorkbooks(evaluators);
189207

0 commit comments

Comments
 (0)