.
This commit is contained in:
parent
8467006ede
commit
e07d201186
@ -2,6 +2,7 @@ package com.lxyer.excel.poi;
|
|||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
|
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.ss.usermodel.*;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
|
|
||||||
@ -74,6 +75,30 @@ public class ExcelKit {
|
|||||||
return wb;
|
return wb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数说明:
|
||||||
|
* list:list数据集合
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 参数说明:
|
* 参数说明:
|
||||||
* list:list数据集合
|
* list:list数据集合
|
||||||
@ -278,7 +303,7 @@ public class ExcelKit {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cell.getCellTypeEnum() == CellType.NUMERIC) {
|
if (cell.getCellType() == CellType.NUMERIC) {
|
||||||
map.put(fields[j], (long) cell.getNumericCellValue() + "");
|
map.put(fields[j], (long) cell.getNumericCellValue() + "");
|
||||||
} else {
|
} else {
|
||||||
map.put(fields[j], cell.getStringCellValue());
|
map.put(fields[j], cell.getStringCellValue());
|
||||||
@ -320,7 +345,7 @@ public class ExcelKit {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cell.getCellTypeEnum() == CellType.NUMERIC) {
|
if (cell.getCellType() == CellType.NUMERIC) {
|
||||||
map.put(field, (long) cell.getNumericCellValue() + "");
|
map.put(field, (long) cell.getNumericCellValue() + "");
|
||||||
} else {
|
} else {
|
||||||
map.put(field, cell.getStringCellValue());
|
map.put(field, cell.getStringCellValue());
|
||||||
@ -336,9 +361,9 @@ public class ExcelKit {
|
|||||||
for (int i = 0; i < row.getLastCellNum() && i < len; i++) {
|
for (int i = 0; i < row.getLastCellNum() && i < len; i++) {
|
||||||
Cell cell = row.getCell(i);//列
|
Cell cell = row.getCell(i);//列
|
||||||
if (cell != null) {
|
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;
|
return false;
|
||||||
} else if (cell.getCellTypeEnum() == CellType.NUMERIC && cell.getNumericCellValue() != 0) {
|
} else if (cell.getCellType() == CellType.NUMERIC && cell.getNumericCellValue() != 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user