POI导出

String filePath = ResourceUtils.getURL(“classpath:”).getPath() + “exportExcel/problemsList.xls”;
HSSFWorkbook workbook = null;
try {
workbook = new HSSFWorkbook(new FileInputStream(filePath));
// 获取准备好的样式
HSSFCellStyle cellStyle = workbook.getSheetAt(0).getRow(1).getCell(0).getCellStyle();
// workbook有内容的工作簿
HSSFSheet sheet = workbook.getSheetAt(0);
// 行数(从0开始,0是列名,模板里已经写好了,所以从第二行那个开始)
int rowIndex = 1;
// list是存放的数据
for (NationalProblems hs : list) {
// 创建行
HSSFRow row = sheet.createRow(rowIndex);
// 创建列
HSSFCell cell = row.createCell(0);
// 往第一列添加内容
// 序号
cell.setCellValue(rowIndex);
// 使用的样式
cell.setCellStyle(cellStyle);

//            审计年度
            cell = row.createCell(1);
            cell.setCellValue(hs.getEnd()+'年');
            cell.setCellStyle(cellStyle);
//            问题标题
            cell = row.createCell(2);
            cell.setCellValue(hs.getTitle());
            cell.setCellStyle(cellStyle);
//            问题类别
            cell = row.createCell(3);
            cell.setCellValue(hs.getType());
            cell.setCellStyle(cellStyle);
//            问题描述
            cell = row.createCell(4);
            cell.setCellValue(hs.getDescribe());
            cell.setCellStyle(cellStyle);
//            整改状态
            cell = row.createCell(5);
            LVResults lvs = getZgztResult();
            for (LVResult lvResult : lvs) {
                if (hs.getStatus().equals(lvResult.getValue().toString())) {
                    hs.setStatus(lvResult.label);
                    break;
                }
            }
            cell.setCellValue(hs.getStatus());
            cell.setCellStyle(cellStyle);

//            行数
            rowIndex++;
        }

// 相当与下载Excel
// 输出流
ServletOutputStream outputStream = response.getOutputStream();
// 一个流 两个头
response.setHeader(“Content-Disposition”, “attachment; filename=” + URLEncoder.encode(“整改问题统计列表.xls”, “UTF-8”));
workbook.write(outputStream);
outputStream.close();
workbook.close();

    } catch (IOException e) {
        e.printStackTrace();
	}finally {
        if (workbook != null) {
            workbook.close();
        }
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值