首页 > 代码库 > 导出报表
导出报表
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:\n\tParameter [svg]: The DOM Element to be converted." + "\n\tParameter [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; }
导出报表
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。