Browse Source

添加了表头的行数,来支持双行数据

4.1.3.A
jueyue 10 years ago
parent
commit
0f4e6f941f
3 changed files with 36 additions and 22 deletions
  1. +0
    -5
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/base/ExcelExportBase.java
  2. +20
    -6
      easypoi-base/src/main/java/org/jeecgframework/poi/word/entity/params/ExcelListEntity.java
  3. +16
    -11
      easypoi-base/src/main/java/org/jeecgframework/poi/word/parse/excel/ExcelEntityParse.java

+ 0
- 5
easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/base/ExcelExportBase.java View File

@@ -4,12 +4,8 @@ import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -32,7 +28,6 @@ import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity;
import org.jeecgframework.poi.excel.entity.params.MergeEntity; import org.jeecgframework.poi.excel.entity.params.MergeEntity;
import org.jeecgframework.poi.handler.inter.IExcelDataHandler;
import org.jeecgframework.poi.util.POIPublicUtil; import org.jeecgframework.poi.util.POIPublicUtil;
/** /**


+ 20
- 6
easypoi-base/src/main/java/org/jeecgframework/poi/word/entity/params/ExcelListEntity.java View File

@@ -22,6 +22,12 @@ public class ExcelListEntity extends ExcelBaseParams {
this.clazz = clazz; 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, public ExcelListEntity(List<?> list, Class<?> clazz,
IExcelDataHandler dataHanlder) { IExcelDataHandler dataHanlder) {
this.list = list; this.list = list;
@@ -29,6 +35,14 @@ public class ExcelListEntity extends ExcelBaseParams {
setDataHanlder(dataHanlder); 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 Class<?> clazz;
/** /**
* 过滤的属性
* 表头行数
*/ */
private String[] exclusions;
private int headRows = 1;
public List<?> getList() { public List<?> getList() {
return list; return list;
@@ -58,12 +72,12 @@ public class ExcelListEntity extends ExcelBaseParams {
this.clazz = clazz; 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;
} }
} }

+ 16
- 11
easypoi-base/src/main/java/org/jeecgframework/poi/word/parse/excel/ExcelEntityParse.java View File

@@ -39,7 +39,8 @@ public class ExcelEntityParse extends ExportBase {
ExcelListEntity entity) { ExcelListEntity entity) {
checkExcelParams(entity); checkExcelParams(entity);
// 获取表头数据 // 获取表头数据
Map<String, Integer> titlemap = getTitleMap(table, index);
Map<String, Integer> titlemap = getTitleMap(table, index,
entity.getHeadRows());
try { try {
// 得到所有字段 // 得到所有字段
Field fileds[] = POIPublicUtil.getClassFields(entity.getClazz()); Field fileds[] = POIPublicUtil.getClassFields(entity.getClazz());
@@ -180,20 +181,24 @@ public class ExcelEntityParse extends ExportBase {
* @param index * @param index
* @return * @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); 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; 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; return map;
} }


Loading…
Cancel
Save