package com.adc.da.common; import org.apache.commons.beanutils.BeanUtils; import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.xssf.streaming.SXSSFWorkbook; import java.util.*; public class TableToExcel { public static Workbook createExcel(Map columnMap, List dataList, String sheelName, String fileName) { if(sheelName==null)sheelName="sheet1"; int sheetRow=500; sheetRow=sheetRow<0?200:sheetRow; //第一步,创建一个webbook,对应一个excel文件,内存中sheetRow条记录后提交。 Workbook wb=new SXSSFWorkbook(sheetRow); if(columnMap!=null&&dataList!=null) { //获取需要生成的sheet数,以防数据量过大报错 int sheetCount=getSheetCount(sheetRow,dataList.size()); //循环生成sheet for(int i=0;i keys=columnMap.keySet(); //第一行(标题行)合并并设置标题 //创建表头行 Row headRow=sheet.createRow(0); //生成表头行 int j=0; for(String key:keys) { Cell hCell=headRow.createCell(j++); hCell.setCellValue(columnMap.get(key)); } //从第二行开始填充数据 int c=1; for(int k=i*sheetRow;k columnMap) { if(sheet!=null&&columnMap!=null) { List list=new ArrayList(columnMap.keySet()); for(int i=0;i0?total/sheelRow+1:total/sheelRow; } }