导出excel---Demo

/**
 * 导出/入料件与企业版本号关系表
 * @param request
 * @param response
 * @param doExportCopyRightExcel
 */
@Override
public void getDoExportCopyRightExcelInformationApi(HttpServletRequest request, HttpServletResponse response, DoExportCopyRightExcel doExportCopyRightExcel) {
    InputStream is=null;
    ByteArrayOutputStream os=null;
    ServletOutputStream out1=null;
    try{
        List<DoExportCopyFeignDTO> data = exportDomainSecortDevelopOra8FeignClient.doExportCopyRightExcelInformationApi(doExportCopyRightExcel).getData();
        HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
        HSSFSheet hssfSheet = hssfWorkbook.createSheet();
        HSSFRow row = hssfSheet.createRow(0);
        row.createCell(0).setCellValue("账套编号");
        row.createCell(1).setCellValue("成品内部货号编号");
        row.createCell(2).setCellValue("成品内部货号");
        row.createCell(3).setCellValue("成品货号描述");
        row.createCell(4).setCellValue("料件货号编号");


        hssfSheet.setColumnWidth(0,20*256);
        hssfSheet.setColumnWidth(1,20*256);
        hssfSheet.setColumnWidth(2,20*256);
        hssfSheet.setColumnWidth(3,20*256);
        hssfSheet.setColumnWidth(4,20*256);
int i = 1;
        for(DoExportCopyFeignDTO cdfListDto:data){
            HSSFRow hssfRow = hssfSheet.createRow(i++);

            hssfRow.createCell(0).setCellValue(cdfListDto.getIncn());
            if (cdfListDto.getSitm()==null){
                hssfRow.createCell(1).setCellValue(cdfListDto.getSitm());
            }else {
                hssfRow.createCell(1).setCellValue(cdfListDto.getSitm().trim());
            }
            if (cdfListDto.getVern()==null){
                hssfRow.createCell(2).setCellValue(cdfListDto.getVern());
            }else {
                hssfRow.createCell(2).setCellValue(cdfListDto.getVern().trim());
            }
            if (cdfListDto.getLogn1()==null){
                hssfRow.createCell(3).setCellValue(cdfListDto.getLogn1());
            }else {
                hssfRow.createCell(3).setCellValue(cdfListDto.getLogn1().trim());
            }
            if (cdfListDto.getDate1()==null){
                hssfRow.createCell(4).setCellValue(cdfListDto.getDate1());
            }else {
                hssfRow.createCell(4).setCellValue(cdfListDto.getDate1().trim());
            }
            }
        os = new ByteArrayOutputStream();
        hssfWorkbook.write(os);
        byte[] content = os.toByteArray();
        is = new ByteArrayInputStream(content);
        response.reset();
        response.setContentType("application/vnd.ms-excel;charset=utf-8");
        response.setHeader("Content-Disposition", "attachment;filename="+ new String(("货号料件企业版本号.xls").getBytes(), "UTF-8"));
        response.setHeader("Access-Control-Allow-Origin","*");
        out1 = response.getOutputStream();
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        try {
            bis = new BufferedInputStream(is);
            bos = new BufferedOutputStream(out1);
            byte[] buff = new byte[2048];
            int bytesRead;
            // Simple read/write loop.
            while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
                bos.write(buff, 0, bytesRead);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (bis != null) {
                bis.close();
            }
            if (bos != null) {
                bos.close();
            }
        }
        catch (Exception e){
        e.printStackTrace();
    }finally {
        try {
            if (is != null) {
                is.close();
            }
            if (os != null) {
                os.close();
            }
            if (out1 != null) {
                out1.close();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值