| @@ -4,12 +4,8 @@ import java.awt.image.BufferedImage; | |||
| import java.io.ByteArrayOutputStream; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import java.lang.reflect.Method; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.ArrayList; | |||
| import java.util.Collection; | |||
| import java.util.Collections; | |||
| import java.util.Date; | |||
| import java.util.HashMap; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| @@ -32,7 +28,6 @@ import org.apache.poi.ss.usermodel.Workbook; | |||
| import org.apache.poi.ss.util.CellRangeAddress; | |||
| import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; | |||
| import org.jeecgframework.poi.excel.entity.params.MergeEntity; | |||
| import org.jeecgframework.poi.handler.inter.IExcelDataHandler; | |||
| import org.jeecgframework.poi.util.POIPublicUtil; | |||
| /** | |||
| @@ -22,6 +22,12 @@ public class ExcelListEntity extends ExcelBaseParams { | |||
| this.clazz = clazz; | |||
| } | |||
| public ExcelListEntity(List<?> list, Class<?> clazz, int headRows) { | |||
| this.list = list; | |||
| this.clazz = clazz; | |||
| this.headRows = headRows; | |||
| } | |||
| public ExcelListEntity(List<?> list, Class<?> clazz, | |||
| IExcelDataHandler dataHanlder) { | |||
| this.list = list; | |||
| @@ -29,6 +35,14 @@ public class ExcelListEntity extends ExcelBaseParams { | |||
| setDataHanlder(dataHanlder); | |||
| } | |||
| public ExcelListEntity(List<?> list, Class<?> clazz, | |||
| IExcelDataHandler dataHanlder, int headRows) { | |||
| this.list = list; | |||
| this.clazz = clazz; | |||
| this.headRows = headRows; | |||
| setDataHanlder(dataHanlder); | |||
| } | |||
| /** | |||
| * 数据源 | |||
| */ | |||
| @@ -38,9 +52,9 @@ public class ExcelListEntity extends ExcelBaseParams { | |||
| */ | |||
| private Class<?> clazz; | |||
| /** | |||
| * 过滤的属性 | |||
| * 表头行数 | |||
| */ | |||
| private String[] exclusions; | |||
| private int headRows = 1; | |||
| public List<?> getList() { | |||
| return list; | |||
| @@ -58,12 +72,12 @@ public class ExcelListEntity extends ExcelBaseParams { | |||
| this.clazz = clazz; | |||
| } | |||
| public String[] getExclusions() { | |||
| return exclusions; | |||
| public int getHeadRows() { | |||
| return headRows; | |||
| } | |||
| public void setExclusions(String[] exclusions) { | |||
| this.exclusions = exclusions; | |||
| public void setHeadRows(int headRows) { | |||
| this.headRows = headRows; | |||
| } | |||
| } | |||
| @@ -39,7 +39,8 @@ public class ExcelEntityParse extends ExportBase { | |||
| ExcelListEntity entity) { | |||
| checkExcelParams(entity); | |||
| // 获取表头数据 | |||
| Map<String, Integer> titlemap = getTitleMap(table, index); | |||
| Map<String, Integer> titlemap = getTitleMap(table, index, | |||
| entity.getHeadRows()); | |||
| try { | |||
| // 得到所有字段 | |||
| Field fileds[] = POIPublicUtil.getClassFields(entity.getClazz()); | |||
| @@ -180,20 +181,24 @@ public class ExcelEntityParse extends ExportBase { | |||
| * @param index | |||
| * @return | |||
| */ | |||
| private Map<String, Integer> getTitleMap(XWPFTable table, int index) { | |||
| if (index == 0) { | |||
| private Map<String, Integer> getTitleMap(XWPFTable table, int index, | |||
| int headRows) { | |||
| if (index < headRows) { | |||
| throw new WordExportException(WordExportEnum.EXCEL_NO_HEAD); | |||
| } | |||
| List<XWPFTableCell> cells = table.getRow(index - 1).getTableCells(); | |||
| Map<String, Integer> map = new HashMap<String, Integer>(cells.size()); | |||
| Map<String, Integer> map = new HashMap<String, Integer>(); | |||
| String text; | |||
| for (int i = 0; i < cells.size(); i++) { | |||
| text = cells.get(i).getText(); | |||
| if (StringUtils.isEmpty(text)) { | |||
| throw new WordExportException( | |||
| WordExportEnum.EXCEL_HEAD_HAVA_NULL); | |||
| for (int j = 0; j < headRows; j++) { | |||
| List<XWPFTableCell> cells = table.getRow(index - j - 1) | |||
| .getTableCells(); | |||
| for (int i = 0; i < cells.size(); i++) { | |||
| text = cells.get(i).getText(); | |||
| if (StringUtils.isEmpty(text)) { | |||
| throw new WordExportException( | |||
| WordExportEnum.EXCEL_HEAD_HAVA_NULL); | |||
| } | |||
| map.put(text, i); | |||
| } | |||
| map.put(text, i); | |||
| } | |||
| return map; | |||
| } | |||