Browse Source

Some more XSSF testing for #57184

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1636750 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_3_11_BETA3
Nick Burch 9 years ago
parent
commit
bc64486226

+ 4
- 4
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java View 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");
}

/**

+ 23
- 5
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java View 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);

Loading…
Cancel
Save