poi 导出 实例

  PackagePlanEntity packagePlanEntity = packagePlanDao.selectById(id);
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFFont createFont = workbook.createFont();
        createFont.setFontHeightInPoints((short) 12);// 设置字体

        XSSFCellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setAlignment(HorizontalAlignment.LEFT); // 内容居左
        cellStyle.setFont(createFont);

        XSSFCellStyle cellStyle1 = workbook.createCellStyle();
        cellStyle1.setAlignment(HorizontalAlignment.CENTER);// 水平居中
        cellStyle1.setFont(createFont);
        cellStyle1.setVerticalAlignment(VerticalAlignment.CENTER);	//上下居中
        XSSFSheet sheet = workbook.createSheet("组装计划列表");
        //获取行
        XSSFRow row0 = sheet.createRow(0);
        String[] title = {"组装计划名称","组装计划说明","组装计划创建时间","发送状态","组装计划创建人","组装计划办理人","组装计划抄送人"};
        for (int i = 0; i < title.length; i++) {
            XSSFCell title0 = row0.createCell(i);
            title0.setCellValue(title[i]);
            if(i==7){
                sheet.setColumnWidth(i, 8000);//物料名称一列
            }else{
                sheet.setColumnWidth(i, 4500);
            }
            title0.setCellStyle(cellStyle1);
        }
        XSSFRow row1 = sheet.createRow(1);

        XSSFCell cell0 = row1.createCell(0);
        cell0.setCellValue(packagePlanEntity.getPackagePlanName());
        cell0.setCellStyle(cellStyle1);

        XSSFCell cell1 = row1.createCell(1);
        cell1.setCellValue(packagePlanEntity.getPackagePlanExplain());
        cell1.setCellStyle(cellStyle1);

        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date createAt = packagePlanEntity.getCreateAt();
        String format1 = format.format(createAt);
        XSSFCell cell2 = row1.createCell(2);
        cell2.setCellValue(format1);
        cell2.setCellStyle(cellStyle1);

		//下载
        ServletOutputStream fileOut = null;
        try {
            fileOut = response.getOutputStream();
            String fileName = new String("组装计划列表".getBytes("UTF-8"), "ISO8859-1");
            response.addHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
            fileOut = response.getOutputStream();
            workbook.write(fileOut);
        } catch (Exception e1) {
            e1.printStackTrace();
        } finally {
            if (fileOut != null) {
                try {
                    fileOut.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }



    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值