@@ -167,12 +167,32 @@ public void testReferencesToOtherWorkbooks() throws Exception {
167
167
assertEquals ("\" Test A1\" " , evaluator .evaluate (cXSL_sNR ).formatAsString ());
168
168
assertEquals ("142.0" , evaluator .evaluate (cXSL_gNR ).formatAsString ());
169
169
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
+
171
179
// Now add a formula that refers to yet another (different) workbook
180
+ // Won't work without the workbook being linked
172
181
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 ) {}
174
186
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 ?
176
196
assertEquals("[alt.xlsx]Sheet1!$A$1", cXSLX_nw_cell.getCellFormula());
177
197
178
198
// Evaluate it, without a link to that workbook
@@ -182,8 +202,6 @@ public void testReferencesToOtherWorkbooks() throws Exception {
182
202
} catch(Exception e) {}
183
203
184
204
// Add a link, check it does
185
- Workbook alt = new XSSFWorkbook();
186
- alt.createSheet().createRow(0).createCell(0).setCellValue("In another workbook");
187
205
evaluators.put("alt.xlsx", alt.getCreationHelper().createFormulaEvaluator());
188
206
evaluator.setupReferencedWorkbooks(evaluators);
189
207
0 commit comments