欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

图片下载JAVA 博客分类: 技术应用 JavaExcelFlex工作 

程序员文章站 2024-02-28 21:14:22
...
// 页面form
        OptActListNewForm actListForm = (OptActListNewForm)form;
        // 转换为Flex转换数据类型
        List<OptActListNew> optList = optActMonitorService.getDownLoadData(actListForm, user);
        OptActListNew optAct = (OptActListNew)optList.get(0);
        List listData = this.buildExcelData(optList);
        response.setHeader("Content-Type", "application/force-download");
        response.setHeader("Content-Type", "application/vnd.ms-excel");
        String fileName = new String("xxx_xx".getBytes("GBK"),
                "ISO-8859-1");
        response.setHeader("Content-Disposition", "attachment;filename="
                + fileName + ".xls");
        ServletOutputStream out = response.getOutputStream();
        //创建excel工作薄
        WritableWorkbook wwb = Workbook.createWorkbook(out);
        //创建excel工作表
        WritableSheet ws = wwb.createSheet("xxxx", 0);
        //给出标题
        WritableFont titleWF = new WritableFont(WritableFont.ARIAL, 20,
                WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,
                Colour.BLACK);
        WritableCellFormat titleWCF = new WritableCellFormat(titleWF);
        Label tileLab = new Label(5, 0, "xxxx", titleWCF);//加入标题
        ws.addCell(tileLab);
        //添加图片对象
        ByteArrayOutputStream bos = null;
        BufferedImage chart = null;
        try
        {
            bos = new ByteArrayOutputStream();
            chart = ImageIO.read(request.getInputStream());
            ImageIO.write(chart, "jpeg", bos);
            WritableImage img = new WritableImage(0, ws.getRows() + 1, 15, 26,
                    bos.toByteArray());
            ws.addImage(img);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        finally
        {
            bos.close();
        }
        wwb.write();
        wwb.close();