package com.artfess.poi; import com.artfess.poi.editor.listener.CellValueListener; import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFFont; import org.apache.poi.hssf.usermodel.HSSFPatriarch; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 存放公共变量,内部使用 * @author zxh * */ public final class ExcelContext { /** * 缓存style对象 */ private Map styleCache = new HashMap(); private Map fontCache = new HashMap(); private Map patriarchCache = new HashMap(); private HSSFWorkbook workBook; private HSSFCellStyle tempCellStyle;// 临时的样式 private HSSFFont tempFont;// 临时的字体 private com.artfess.poi.Excel excel; /** * 处于工作状态的工作表 */ private HSSFSheet workingSheet; /** * 默认样式 */ private com.artfess.poi.DefaultExcelStyle defaultStyle; /** * 当前选择的工作簿 */ private int workingSheetIndex = 0; /** * 监听器列表 */ private Map> cellValueListener; protected ExcelContext(com.artfess.poi.Excel excel, HSSFWorkbook workBook){ this.workBook = workBook; short numStyle = (short) workBook.getNumCellStyles(); for(short i=0; i styleCache) { this.styleCache = styleCache; } public Map getStyleCache() { return styleCache; } public void setFontCache(Map fontCache) { this.fontCache = fontCache; } public Map getFontCache() { return fontCache; } private Map> getCellValueListener() { if(cellValueListener == null){ cellValueListener = new HashMap>(); } return cellValueListener; } /** * 获取指定表单的监听器 * @param sheetIndex * @return */ public List getListenerList(int sheetIndex){ Map> map = getCellValueListener(); List listenerList = map.get(sheetIndex); if(listenerList == null){ listenerList = new ArrayList(); map.put(sheetIndex, listenerList); } return listenerList; } public com.artfess.poi.Excel getExcel() { return excel; } }