Excel导出

String fileName = “导出Excel.xlsx”; //创建名称
String rpath = null;
ClassLoader cldr=getClass().getClassLoader();
if(null!=cldr){
rpath = cldr.getResource("/").getPath();
}else{
rpath="###";
}
String os = System.getProperty(“os.name”);//获取当前操作系统
if (os != null && os.startsWith(“Windows”)) {
if (rpath.startsWith("/")) {
rpath = rpath.substring(1, rpath.length());
}
}
if (rpath.contains(“WEB-INF”)) {
rpath = rpath.substring(0, rpath.indexOf(“WEB-INF”)) + “excel”;
}
String rpathfinal = rpath +"/"+ fileName;//路径

    SXSSFWorkbook wb = new SXSSFWorkbook(1024); // 这里1024是在内存中的数量,如果大于此数量时,会写到硬盘,以避免在内存导致内存溢出  
    Sheet sh = wb.createSheet();

for (int i = 0; i < List.size()+1; i++) {
sh.setColumnWidth(i,4500);
Row row = sh.createRow(i);
if (i==0) {
row.createCell(0).setCellValue(“xxxx”);
row.createCell(1).setCellValue(“aaaa”);
row.createCell(2).setCellValue(“bbbb”);
row.createCell(3).setCellValue(“cccc”);
}else{
row.createCell(0).setCellValue(StringUtil.isNullOrEmpty(List.get(i-1).get(“belong”)));
row.createCell(1).setCellValue(StringUtil.isNullOrEmpty(List.get(i-1).get(“dqbj”)));
row.createCell(2).setCellValue(StringUtil.isNullOrEmpty(List.get(i-1).get(“datasource”)));
row.createCell(3).setCellValue(StringUtil.isNullOrEmpty(List.get(i-1).get(“tablename”)));
}
}
FileOutputStream output=new FileOutputStream(rpathfinal);
wb.write(output);
output.close();
try {
//发送邮件给指定人
String EmailMessage = “这是您需要的excel文档,截止时间为:”+ today;
SendMailUtil.createFileMail(Email, “标题”, rpathfinal, EmailMessage);
} catch (Exception e) {
e.printStackTrace();
}
//删除存在文件夹中的文档
LOGGER.info("<------------------开始删除文件:"+fileName);
boolean deleteFile = DeleteFile(rpathfinal);//删除文件
LOGGER.info("<------------------删除生成的文件:"+fileName +" 删除结果:"+ deleteFile);
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值