• 导出报表


    public String export() {
            HttpServletResponse response = ServletActionContext.getResponse();
            filename = filename==null?"chart":filename;
            ServletOutputStream out = null;
            try {
                out = response.getOutputStream();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            if (null != type && null != svg) {
                svg = this.handleSvg(svg);
                String ext = "";
                Transcoder t = null;
                if (type.equals("image/png")) {
                    ext = "png";
                    t = new PNGTranscoder();
                } else if (type.equals("image/jpeg")) {
                    ext = "jpg";
                    t = new JPEGTranscoder();
                } else if (type.equals("application/pdf")) {
                    ext = "pdf";
                    t =(Transcoder) new PDFTranscoder();
                } else if(type.equals("image/svg+xml")) 
                    ext = "svg";   
                response.addHeader("Content-Disposition", "attachment; filename="+ filename + "."+ext);
                response.addHeader("Content-Type", type);
                
                if (null != t) {
                    TranscoderInput input = new TranscoderInput(new StringReader(svg));
                    TranscoderOutput output = new TranscoderOutput(out);
                    try {
                        t.transcode(input, output);
                    } catch (TranscoderException e) {
                        try {
                            out.print("Problem transcoding stream. See the web logs for more details.");
                        } catch (IOException e1) {
                            e1.printStackTrace();
                        }
                        e.printStackTrace();
                    }
                } else if (ext.equals("svg")) {
                    try {
                        OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8");
                        writer.append(svg);
                        writer.close();
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }catch (IOException e1) {
                        e1.printStackTrace();
                    }
                } else
                    try {
                        out.print("Invalid type: " + type);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
            } else {
                response.addHeader("Content-Type", "text/html");
                try {
                    out.println("Usage:
    	Parameter [svg]: The DOM Element to be converted." +
                            "
    	Parameter [type]: The destination MIME type for the elment to be transcoded.");
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            try {
                out.flush();
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
    _____________________________________________________________________________________________________ ***************************************************************************************************************** ===坚持、奋斗***今天的努力只为更好的明天***奋斗、坚持===********************** ==========================================================================================
  • 相关阅读:
    python 各层级目录下的import方法
    Ubuntu更新python3.5到python3.7
    程序员的江湖--个人品牌
    产品经理看哪吒之魔童降世
    Python 相对路径和绝对路径--python实战(九)
    vim 下修改tab键为四个空格
    一个python问题引发的思考
    【python】多进程共享变量
    【python】spark+kafka使用
    【python】kafka在与celery和gevent连用时遇到的问题
  • 原文地址:https://www.cnblogs.com/mlloc-clove/p/3978731.html
Copyright © 2020-2023  润新知