}
}
}
+
+
+ @Override
+ public HSSFEvaluationWorkbook createEvaluationWorkbook() {
+ return HSSFEvaluationWorkbook.create(this);
+ }
}
package org.apache.poi.ss.formula.eval.forked;
-import org.apache.poi.ss.formula.eval.BoolEval;
-import org.apache.poi.ss.formula.eval.ErrorEval;
-import org.apache.poi.ss.formula.eval.NumberEval;
-import org.apache.poi.ss.formula.eval.StringEval;
-import org.apache.poi.ss.formula.eval.ValueEval;
-import org.apache.poi.ss.formula.udf.UDFFinder;
+import java.util.stream.Stream;
-import java.lang.reflect.Method;
-
-import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.formula.CollaboratingWorkbooksEnvironment;
import org.apache.poi.ss.formula.EvaluationCell;
import org.apache.poi.ss.formula.EvaluationWorkbook;
import org.apache.poi.ss.formula.IStabilityClassifier;
import org.apache.poi.ss.formula.WorkbookEvaluator;
+import org.apache.poi.ss.formula.eval.BoolEval;
+import org.apache.poi.ss.formula.eval.ErrorEval;
+import org.apache.poi.ss.formula.eval.NumberEval;
+import org.apache.poi.ss.formula.eval.StringEval;
+import org.apache.poi.ss.formula.eval.ValueEval;
+import org.apache.poi.ss.formula.udf.UDFFinder;
import org.apache.poi.ss.usermodel.Workbook;
/**
*/
public final class ForkedEvaluator {
- private WorkbookEvaluator _evaluator;
- private ForkedEvaluationWorkbook _sewb;
+ private final WorkbookEvaluator _evaluator;
+ private final ForkedEvaluationWorkbook _sewb;
private ForkedEvaluator(EvaluationWorkbook masterWorkbook, IStabilityClassifier stabilityClassifier, UDFFinder udfFinder) {
_sewb = new ForkedEvaluationWorkbook(masterWorkbook);
_evaluator = new WorkbookEvaluator(_sewb, stabilityClassifier, udfFinder);
}
- private static EvaluationWorkbook createEvaluationWorkbook(Workbook wb) {
- if (wb instanceof HSSFWorkbook) {
- return HSSFEvaluationWorkbook.create((HSSFWorkbook) wb);
- } else {
- try {
- // TODO: check if this is Java 9 compatible ...
- Class<?> evalWB = Class.forName("org.apache.poi.xssf.usermodel.XSSFEvaluationWorkbook");
- Class<?> xssfWB = Class.forName("org.apache.poi.xssf.usermodel.XSSFWorkbook");
- Method createM = evalWB.getDeclaredMethod("create", xssfWB);
- return (EvaluationWorkbook)createM.invoke(null, wb);
- } catch (Exception e) {
- throw new IllegalArgumentException("Unexpected workbook type (" + wb.getClass().getName() + ") - check for poi-ooxml and poi-ooxml schemas jar in the classpath", e);
- }
- }
- }
/**
* @param udfFinder pass <code>null</code> for default (AnalysisToolPak only)
*/
public static ForkedEvaluator create(Workbook wb, IStabilityClassifier stabilityClassifier, UDFFinder udfFinder) {
- return new ForkedEvaluator(createEvaluationWorkbook(wb), stabilityClassifier, udfFinder);
+ return new ForkedEvaluator(wb.createEvaluationWorkbook(), stabilityClassifier, udfFinder);
}
/**
* @param evaluators all evaluators for the full set of workbooks required by the formulas.
*/
public static void setupEnvironment(String[] workbookNames, ForkedEvaluator[] evaluators) {
- WorkbookEvaluator[] wbEvals = new WorkbookEvaluator[evaluators.length];
- for (int i = 0; i < wbEvals.length; i++) {
- wbEvals[i] = evaluators[i]._evaluator;
- }
+ WorkbookEvaluator[] wbEvals = Stream.of(evaluators).map(e -> e._evaluator).toArray(WorkbookEvaluator[]::new);
CollaboratingWorkbooksEnvironment.setup(workbookNames, wbEvals);
}
}
import java.util.List;
import org.apache.poi.ss.SpreadsheetVersion;
+import org.apache.poi.ss.formula.EvaluationWorkbook;
import org.apache.poi.ss.formula.udf.UDFFinder;
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
import org.apache.poi.util.Removal;
*/
Sheet cloneSheet(int sheetNum);
-
+
/**
* Returns an iterator of the sheets in the workbook
* in sheet order. Includes hidden and very hidden sheets.
* @return new font object
*/
Font createFont();
-
+
/**
* Finds a font that matches the one with the supplied attributes
*
/**
* Hide or unhide a sheet.
- *
- * Please note that the sheet currently set as active sheet (sheet 0 in a newly
- * created workbook or the one set via setActiveSheet()) cannot be hidden.
+ *
+ * Please note that the sheet currently set as active sheet (sheet 0 in a newly
+ * created workbook or the one set via setActiveSheet()) cannot be hidden.
*
* @param sheetIx the sheet index (0-based)
* @param hidden True to mark the sheet as hidden, false otherwise
/**
* Hide or unhide a sheet.
*
- * Please note that the sheet currently set as active sheet (sheet 0 in a newly
+ * Please note that the sheet currently set as active sheet (sheet 0 in a newly
* created workbook or the one set via setActiveSheet()) cannot be hidden.
- *
+ *
* @param sheetIx the sheet index (0-based)
* @param visibility the sheet visibility to set
* @since POI 3.16 beta 2
* @since 3.8
*/
boolean getForceFormulaRecalculation();
-
+
/**
* Returns the spreadsheet version of this workbook
- *
+ *
* @return SpreadsheetVersion enum
* @since 3.14 beta 2
*/
* @param label the label of the payload
* @param fileName the original filename
* @param command the command to open the payload
- *
+ *
* @return the index of the added ole object, i.e. the storage id
- *
+ *
* @throws IOException if the object can't be embedded
*/
int addOlePackage(byte[] oleData, String label, String fileName, String command) throws IOException;
+
+ /**
+ * @return an evaluation workbook
+ */
+ EvaluationWorkbook createEvaluationWorkbook();
}
import org.apache.poi.openxml4j.util.ZipFileZipEntrySource;
import org.apache.poi.openxml4j.util.ZipSecureFile;
import org.apache.poi.ss.SpreadsheetVersion;
+import org.apache.poi.ss.formula.EvaluationWorkbook;
import org.apache.poi.ss.formula.udf.UDFFinder;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.SheetVisibility;
import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.util.*;
+import org.apache.poi.util.Beta;
+import org.apache.poi.util.IOUtils;
+import org.apache.poi.util.Internal;
+import org.apache.poi.util.NotImplemented;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
+import org.apache.poi.util.Removal;
+import org.apache.poi.util.TempFile;
import org.apache.poi.xssf.model.SharedStringsTable;
import org.apache.poi.xssf.usermodel.XSSFChartSheet;
import org.apache.poi.xssf.usermodel.XSSFSheet;
return _wb.addOlePackage(oleData, label, fileName, command);
}
-//end of interface implementation
+
+ @Override
+ public EvaluationWorkbook createEvaluationWorkbook() {
+ return SXSSFEvaluationWorkbook.create(this);
+ }
}
public boolean getCellFormulaValidation() {
return this.cellFormulaValidation;
}
+
+ @Override
+ public XSSFEvaluationWorkbook createEvaluationWorkbook() {
+ return XSSFEvaluationWorkbook.create(this);
+ }
}