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.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;
/**


+ 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;
}
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;
}
}

+ 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) {
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;
}


Loading…
Cancel
Save