This commit is contained in:
lxyer 2019-04-24 18:49:46 +08:00
parent 8467006ede
commit e07d201186

View File

@ -2,6 +2,7 @@ package com.lxyer.excel.poi;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
import org.apache.poi.ss.formula.functions.T;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@ -74,6 +75,30 @@ public class ExcelKit {
return wb;
}
/**
* 参数说明
* listlist数据集合
* headMap每一列的字段名和对应的表头名称 {name:"姓名" age:"年龄"}
* 通过数据构建 Workbook 对象
*
* @throws Exception
* @author LiangXianYou
* @date 2015-3-13 上午11:00:30
*/
public static Workbook exportExcel(List<T> list, LinkedHashMap<String, String> headMap) throws Exception {
String[] hdNames = new String[headMap.size()]; //
String[] hds = new String[headMap.size()];
int[] tag = {0};
headMap.forEach((k,v) -> {
hds[tag[0]] = k;
hdNames[tag[0]] = v;
tag[0] ++;
});
return exportExcel(list, hdNames, hds);
}
/**
* 参数说明
* listlist数据集合
@ -278,7 +303,7 @@ public class ExcelKit {
continue;
}
if (cell.getCellTypeEnum() == CellType.NUMERIC) {
if (cell.getCellType() == CellType.NUMERIC) {
map.put(fields[j], (long) cell.getNumericCellValue() + "");
} else {
map.put(fields[j], cell.getStringCellValue());
@ -320,7 +345,7 @@ public class ExcelKit {
continue;
}
if (cell.getCellTypeEnum() == CellType.NUMERIC) {
if (cell.getCellType() == CellType.NUMERIC) {
map.put(field, (long) cell.getNumericCellValue() + "");
} else {
map.put(field, cell.getStringCellValue());
@ -336,9 +361,9 @@ public class ExcelKit {
for (int i = 0; i < row.getLastCellNum() && i < len; i++) {
Cell cell = row.getCell(i);//
if (cell != null) {
if (cell.getCellTypeEnum() != CellType.NUMERIC && cell.getStringCellValue() != null && !cell.getStringCellValue().isEmpty()) {
if (cell.getCellType() != CellType.NUMERIC && cell.getStringCellValue() != null && !cell.getStringCellValue().isEmpty()) {
return false;
} else if (cell.getCellTypeEnum() == CellType.NUMERIC && cell.getNumericCellValue() != 0) {
} else if (cell.getCellType() == CellType.NUMERIC && cell.getNumericCellValue() != 0) {
return false;
}
}