\r
package org.apache.poi.ss.formula;\r
\r
+import java.io.IOException;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
import junit.framework.TestCase;\r
+\r
import org.apache.poi.hssf.HSSFTestDataSamples;\r
-import org.apache.poi.hssf.usermodel.*;\r
import org.apache.poi.ss.usermodel.Cell;\r
import org.apache.poi.ss.usermodel.FormulaEvaluator;\r
-\r
-import java.io.IOException;\r
+import org.apache.poi.ss.usermodel.Row;\r
+import org.apache.poi.ss.usermodel.Sheet;\r
+import org.apache.poi.ss.usermodel.Workbook;\r
\r
public class TestMissingWorkbook extends TestCase {\r
private static final String MAIN_WORKBOOK_FILENAME = "52575_main.xls";\r
private static final String SOURCE_DUMMY_WORKBOOK_FILENAME = "source_dummy.xls";\r
private static final String SOURCE_WORKBOOK_FILENAME = "52575_source.xls";\r
\r
- private HSSFWorkbook mainWorkbook;\r
- private HSSFWorkbook sourceWorkbook;\r
+ private Workbook mainWorkbook;\r
+ private Workbook sourceWorkbook;\r
\r
@Override\r
protected void setUp() throws Exception {\r
public void testMissingWorkbookMissing() throws IOException {\r
FormulaEvaluator evaluator = mainWorkbook.getCreationHelper().createFormulaEvaluator();\r
\r
- HSSFSheet lSheet = mainWorkbook.getSheetAt(0);\r
- HSSFRow lARow = lSheet.getRow(0);\r
- HSSFCell lA1Cell = lARow.getCell(0);\r
+ Sheet lSheet = mainWorkbook.getSheetAt(0);\r
+ Row lARow = lSheet.getRow(0);\r
+ Cell lA1Cell = lARow.getCell(0);\r
\r
assertEquals(Cell.CELL_TYPE_FORMULA, lA1Cell.getCellType());\r
try {\r
}\r
\r
public void testMissingWorkbookMissingOverride() throws IOException {\r
- HSSFSheet lSheet = mainWorkbook.getSheetAt(0);\r
- HSSFCell lA1Cell = lSheet.getRow(0).getCell(0);\r
- HSSFCell lB1Cell = lSheet.getRow(1).getCell(0);\r
- HSSFCell lC1Cell = lSheet.getRow(2).getCell(0);\r
+ Sheet lSheet = mainWorkbook.getSheetAt(0);\r
+ Cell lA1Cell = lSheet.getRow(0).getCell(0);\r
+ Cell lB1Cell = lSheet.getRow(1).getCell(0);\r
+ Cell lC1Cell = lSheet.getRow(2).getCell(0);\r
\r
assertEquals(Cell.CELL_TYPE_FORMULA, lA1Cell.getCellType());\r
assertEquals(Cell.CELL_TYPE_FORMULA, lB1Cell.getCellType());\r
assertEquals(Cell.CELL_TYPE_FORMULA, lC1Cell.getCellType());\r
\r
- HSSFFormulaEvaluator evaluator = mainWorkbook.getCreationHelper().createFormulaEvaluator();\r
+ FormulaEvaluator evaluator = mainWorkbook.getCreationHelper().createFormulaEvaluator();\r
evaluator.setIgnoreMissingWorkbooks(true);\r
\r
assertEquals(Cell.CELL_TYPE_NUMERIC, evaluator.evaluateFormulaCell(lA1Cell));\r
\r
\r
public void testExistingWorkbook() throws IOException {\r
- HSSFSheet lSheet = mainWorkbook.getSheetAt(0);\r
- HSSFCell lA1Cell = lSheet.getRow(0).getCell(0);\r
- HSSFCell lB1Cell = lSheet.getRow(1).getCell(0);\r
- HSSFCell lC1Cell = lSheet.getRow(2).getCell(0);\r
+ Sheet lSheet = mainWorkbook.getSheetAt(0);\r
+ Cell lA1Cell = lSheet.getRow(0).getCell(0);\r
+ Cell lB1Cell = lSheet.getRow(1).getCell(0);\r
+ Cell lC1Cell = lSheet.getRow(2).getCell(0);\r
\r
assertEquals(Cell.CELL_TYPE_FORMULA, lA1Cell.getCellType());\r
assertEquals(Cell.CELL_TYPE_FORMULA, lB1Cell.getCellType());\r
assertEquals(Cell.CELL_TYPE_FORMULA, lC1Cell.getCellType());\r
\r
- HSSFFormulaEvaluator lMainWorkbookEvaluator = new HSSFFormulaEvaluator(mainWorkbook);\r
- HSSFFormulaEvaluator lSourceEvaluator = new HSSFFormulaEvaluator(sourceWorkbook);\r
- HSSFFormulaEvaluator.setupEnvironment(\r
- new String[]{MAIN_WORKBOOK_FILENAME, SOURCE_DUMMY_WORKBOOK_FILENAME}, \r
- new HSSFFormulaEvaluator[] {lMainWorkbookEvaluator, lSourceEvaluator});\r
+ FormulaEvaluator lMainWorkbookEvaluator = mainWorkbook.getCreationHelper().createFormulaEvaluator();\r
+ FormulaEvaluator lSourceEvaluator = sourceWorkbook.getCreationHelper().createFormulaEvaluator();\r
+ Map<String,FormulaEvaluator> workbooks = new HashMap<String, FormulaEvaluator>();\r
+ workbooks.put(MAIN_WORKBOOK_FILENAME, lMainWorkbookEvaluator);\r
+ workbooks.put(SOURCE_DUMMY_WORKBOOK_FILENAME, lSourceEvaluator);\r
+ lMainWorkbookEvaluator.setupReferencedWorkbooks(workbooks);\r
\r
assertEquals(Cell.CELL_TYPE_NUMERIC, lMainWorkbookEvaluator.evaluateFormulaCell(lA1Cell));\r
assertEquals(Cell.CELL_TYPE_STRING, lMainWorkbookEvaluator.evaluateFormulaCell(lB1Cell));\r
assertEquals("Apache rocks!", lB1Cell.getStringCellValue());\r
assertEquals(false, lC1Cell.getBooleanCellValue());\r
}\r
-\r
}\r