很久之前写好的工具类 现分享给大家使用(使用超简单)
首先上工具类代码(代码可自行调整)
public static int DEFAULT_COLOUMN_WIDTH = 17;
static List<String> dutyList = Arrays.asList("请假", "病假", "事假", "上班", "早退", "调休", "婚假", "缺勤");
/**
* @param title
* @param ja
* @param headMap
*/
public static ByteArrayOutputStream exportListExport(String title, JSONArray ja, Map<String, String> headMap, Map<String, Integer> lengthMap) {
int colWidth = 0;
// 声明一个工作薄
SXSSFWorkbook workbook = new SXSSFWorkbook(1000);//缓存
workbook.setCompressTempFiles(true);
//表头样式
CellStyle titleStyle = workbook.createCellStyle();
titleStyle = getCellStyle(workbook, titleStyle);
// 列头样式
CellStyle headerStyle = workbook.createCellStyle();
headerStyle = getCellStyle2(workbook, headerStyle);
// 单元格样式
CellStyle cellStyle = workbook.createCellStyle();
cellStyle = getCellStyle1(workbook, cellStyle);
//带颜色的单元格样式
CellStyle cellStyleColor = workbook.createCellStyle();
cellStyleColor = getCellStyle4(workbook, cellStyleColor);
// 生成一个(带标题)表格
Sheet sheet = workbook.createSheet();
//设置列宽
int minBytes = colWidth < DEFAULT_COLOUMN_WIDTH ? DEFAULT_COLOUMN_WIDTH : colWidth;//至少字节数
int[] arrColWidth = new int[headMap.size()];
// 产生表格标题行,以及设置列宽
String[] properties = new String[headMap.size()];
String[] headers = new String[headMap.size()];
int ii = 0;
for (Iterator<String> iter = headMap.keySet().iterator(); iter.hasNext(); ) {
String fieldName = iter.next();
properties[ii] = fieldName;
headers[ii] = headMap.get(fieldName);
int bytes = 0;
if (lengthMap != null && lengthMap.get(fieldName) != null) {
bytes = lengthMap.get(fieldName);
} else {