Could not resolve external workbook name. Workbook environment has not been set up

阅读 114

2023-07-02


https://issues.apache.org/bugzilla/show_bug.cgi?id=47358

You need to tell POI about all workbooks involved in the evaluation.  This is done with the method HSSFFormulaEvaluator.setupEnvironment()

You can get away with not doing this if the cell you are evaluation does not depend on the other workbook(s).  However, in your case the other workbook is required (hence the error).

----    ----
 Here is some sample code:String dirName = "c:/somedir/";
 String bookNameA = "test.xls";
 String bookNameB = "rm0509.xls"; HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(dirName + bookNameA));
 HSSFWorkbook wbB = new HSSFWorkbook(new FileInputStream(dirName + bookNameB));HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(wb);
 HSSFFormulaEvaluator feB = new HSSFFormulaEvaluator(wbB);// Set up the workbook environment for evaluation
 String[] workbookNames = { bookNameA, bookNameB, };
 HSSFFormulaEvaluator[] evaluators = { evaluator, feB, };
 HSSFFormulaEvaluator.setupEnvironment(workbookNames, evaluators);// do an evaluation
 HSSFCell cell = wb.getSheetAt(0).getRow(0).getCell(0);
 evaluator.evaluateFormulaCell(cell);----    ----
This feature is currently only implemented for HSSF.
==============
 for POI API, those files should be exposed,  that is to  say, POI can read them

精彩评论(0)

0 0 举报