jasperreports制作报表(导出pdf excel html)
来源:互联网 发布:淘宝卖家注册流程 编辑:程序博客网 时间:2024/04/30 04:53
jasperreport生成报表的各种格式
关键代码:
- Connection conn = null;
- String type = request.getParameter("type");
- try
- {
- Class.forName("oracle.jdbc.driver.OracleDriver");
- conn = DriverManager.getConnection(
- "jdbc:oracle:thin:@127.0.0.1:1521:orcl","mutouyihao","xx");
- ServletContext servletContext = this.getServletContext();
- File reportFile = new File(servletContext.getRealPath("/")+"/WEB-INF/report/Untitled_report_1.jasper");
- Map parameters = new HashMap();
- if("pdf".equals(type)){
- byte[] bytes = JasperRunManager.runReportToPdf(reportFile.getPath(), parameters, conn);
- response.setContentType("application/pdf");
- response.addHeader("Content-Disposition", "attachment; filename=report.pdf");
- response.setContentLength(bytes.length);
- ServletOutputStream ouputStream = response.getOutputStream();
- ouputStream.write(bytes, 0, bytes.length);
- ouputStream.flush();
- ouputStream.close();
- } else if ("excel".equals(type)){
- JRXlsExporter exporter = new JRXlsExporter();
- ByteArrayOutputStream oStream = new ByteArrayOutputStream();
- JasperPrint jasperPrint = JasperFillManager.fillReport(reportFile.getPath(), parameters, conn);
- exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
- exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, oStream);
- exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
- exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
- exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
- exporter.exportReport();
- byte[] bytes = oStream.toByteArray();
- response.setContentType("application/vnd.ms-excel");
- response.addHeader("Content-Disposition", "attachment; filename=report.xls");
- response.setContentLength(bytes.length);
- ServletOutputStream ouputStream = response.getOutputStream();
- ouputStream.write(bytes, 0, bytes.length);
- ouputStream.flush();
- ouputStream.close();
- }
- }
- catch (JRException jre)
- {
- System.out.println("JRException:" + jre.getMessage());
- }
- catch (Exception e)
- {
- System.out.println("Exception:" + e.getMessage());
- }
- finally{
- try
- {
- conn.close();
- }
- catch (SQLException ex)
- {
- // TODO Auto-generated catch block
- ex.printStackTrace();
- }
- }
生成html的参考
- //生成html
- JRHtmlExporter exporter = new JRHtmlExporter();
- ByteArrayOutputStream oStream = new ByteArrayOutputStream();
- JasperPrint jasperPrint = JasperFillManager.fillReport(rpt.getPath(), map, con);
- exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
- exporter.setParameter(JRHtmlExporterParameter.JASPER_PRINT, jasperPrint);
- exporter.setParameter(JRHtmlExporterParameter.CHARACTER_ENCODING, "utf-8");
- exporter.setParameter(JRHtmlExporterParameter.OUTPUT_STREAM, oStream);
- exporter.exportReport();
- byte[] bytes = oStream.toByteArray();
- response.setContentType("text/html");
- response.setContentLength(bytes.length);
- response.setCharacterEncoding("utf-8");
- ServletOutputStream ouputStream = response.getOutputStream();
- ouputStream.write(bytes, 0, bytes.length);
- ouputStream.flush();
- ouputStream.close();
- con.close();
- out.clear();
- out = pageContext.pushBody();
0 0
- jasperreports制作报表(导出pdf excel html)
- jasperreports制作报表(导出pdf excel html)
- 使用jasperreports制作报表(导出pdf excel html)
- 借助于jasperreports与jfreechart以xls,html,pdf格式导出报表
- jasperreport实现Html、Pdf、Rtf、Excel、Xml报表导出
- jasperreport实现Html、Pdf、Rtf、Excel、Xml报表导出
- jasperreport实现Html、Pdf、Rtf、 Excel、Xml报表导出
- Jasperreports以及iReport4.5报表PDF导出字体完美解决方案
- Excel PDF报表的导出
- iBATIS和JasperReports制作报表(一)
- jasperreports导出PDF相关
- iRport+jasperreports 制作 Excel 报表开发过程中问题解决办法
- Jasperreports导出PDF、web上html的几个实用连接
- Ireport 报表导出 Poi + ireport 导出pdf, word ,excel ,html 格式
- iReport+jasperReports制作WEB报表
- iReport+jasperReports制作WEB报表
- jasperReports+ireport 报表制作流程
- iReport+jasperReports制作WEB报表
- 表达式
- fckeidtor出现右箭头问题
- java poi excel操作示例
- Java大纲
- hdu 1069 Monkey and Banana
- jasperreports制作报表(导出pdf excel html)
- 多态
- 用Jakarta POI操作Excel文件
- Wince当作U盘识别时间长的解决方式
- 反射
- 使用share SDK实现QQ空间授权登录、分享(1.x版本)
- 封装
- Sql Server 2005 怎么就不能用Windows身份验证方式登录呢?
- 集合