* SXSSF wrapper around the SXSSF and XSSF workbooks
*/
public final class SXSSFEvaluationWorkbook extends BaseXSSFEvaluationWorkbook {
- private SXSSFWorkbook _uBook;
+ private final SXSSFWorkbook _uBook;
public static SXSSFEvaluationWorkbook create(SXSSFWorkbook book) {
if (book == null) {
super(book.getXSSFWorkbook());
_uBook = book;
}
-
+
+ @Override
public int getSheetIndex(EvaluationSheet evalSheet) {
SXSSFSheet sheet = ((SXSSFEvaluationSheet)evalSheet).getSXSSFSheet();
return _uBook.getSheetIndex(sheet);
}
-
+
+ @Override
public EvaluationSheet getSheet(int sheetIndex) {
return new SXSSFEvaluationSheet(_uBook.getSheetAt(sheetIndex));
}
-
+
+ @Override
public Ptg[] getFormulaTokens(EvaluationCell evalCell) {
SXSSFCell cell = ((SXSSFEvaluationCell)evalCell).getSXSSFCell();
SXSSFEvaluationWorkbook frBook = SXSSFEvaluationWorkbook.create(_uBook);
package org.apache.poi.xssf.usermodel;
+import java.util.HashMap;
import java.util.List;
+import java.util.Locale;
+import java.util.Map;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.formula.EvaluationName;
import org.apache.poi.ss.formula.udf.IndexedUDFFinder;
import org.apache.poi.ss.formula.udf.UDFFinder;
import org.apache.poi.ss.usermodel.Table;
+import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.util.NotImplemented;
public XSSFName createName() {
return _uBook.createName();
}
-
- public Table getTable(String name) {
- return _uBook.getTable(name);
+
+ /*
+ * TODO: data tables are stored at the workbook level in XSSF, but are bound to a single sheet.
+ * The current code structure has them hanging off XSSFSheet, but formulas reference them
+ * only by name (names are global, and case insensitive).
+ * This map stores names as lower case for case-insensitive lookups.
+ *
+ * FIXME: Caching tables by name here for fast formula lookup means the map is out of date if
+ * a table is renamed or added/removed to a sheet after the map is created.
+ *
+ * Perhaps tables can be managed similar to PivotTable references above?
+ */
+ private Map<String, XSSFTable> _tableCache = null;
+ private Map<String, XSSFTable> getTableCache() {
+ if ( _tableCache != null ) {
+ return _tableCache;
+ }
+ // FIXME: use org.apache.commons.collections.map.CaseInsensitiveMap
+ _tableCache = new HashMap<String, XSSFTable>();
+
+ for (Sheet sheet : _uBook) {
+ for (XSSFTable tbl : ((XSSFSheet)sheet).getTables()) {
+ String lname = tbl.getName().toLowerCase(Locale.ROOT);
+ _tableCache.put(lname, tbl);
+ }
+ }
+ return _tableCache;
+ }
+
+ /**
+ * Returns the data table with the given name (case insensitive).
+ * Tables are cached for performance (formula evaluation looks them up by name repeatedly).
+ * After the first table lookup, adding or removing a table from the document structure will cause trouble.
+ * This is meant to be used on documents whose structure is essentially static at the point formulas are evaluated.
+ *
+ * @param name the data table name (case-insensitive)
+ * @return The Data table in the workbook named <tt>name</tt>, or <tt>null</tt> if no table is named <tt>name</tt>.
+ * @since 3.15 beta 2
+ */
+ public XSSFTable getTable(String name) {
+ return getTableCache().get(name.toLowerCase(Locale.ROOT));
}
public UDFFinder getUDFFinder(){