- 浏览: 980503 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (223)
- JDBC技术 (29)
- Java Base (21)
- SSH框架的集合 (5)
- Javascript部分 (16)
- Sping2.5框架 (6)
- Hibernate框架 (19)
- JDBC中的数据库连接 (5)
- Ajax技术应用 (9)
- Java工具包下载 (3)
- Database (4)
- Java Web (13)
- 我的生活 (4)
- Struts2 (25)
- S2SH (1)
- Prototype (1)
- jfreeChart (5)
- JPA (7)
- JBPM (1)
- JasperReport (6)
- DWR (1)
- freeMark (2)
- IBatis (2)
- FCKeditor (2)
- POI (1)
- JQuery (6)
- JSON (1)
- JavaMail (3)
- Flex (2)
- CSS收藏夹 (1)
- 润乾报表 (2)
- 开源技术 (1)
- Android (2)
- Android_UI (1)
- Android_OS (6)
- Android_OpenLibs (3)
- Volley (1)
- JS_OpenLibs (1)
- Hessian (3)
- OS (1)
最新评论
-
damoluomu:
简单易懂
Java Web开发Session超时设置 -
di1984HIT:
学习了~~~~~~
Java Web开发Session超时设置 -
lord_is_layuping:
...
Java Web开发Session超时设置 -
15111285554:
...
Java Web开发Session超时设置 -
sfg1314:
暂停后重新下载就会报错:ClientAbortExceptio ...
Java Web 文件下载之断点续传
public ActionResult projectPrint() { String[] printValue = null; // 从页面中获得要查询的字段 String reqPrintValue = getRequest().getParameter("printValue"); // 没有选择则默认全打印 if (null == reqPrintValue || StringUtils.isEmpty(reqPrintValue)) { printValue = new String[] { "pnumber", "pname", "pdepart", "pdecision", "pthrow", "plastmonth", "pfund", "ploan" }; } else { printValue = reqPrintValue.split(","); } // 查询统计数据 List<Object[]> projectList = getEntityManager().queryPrintProjectInfo(printValue); // 将数据转换为Map对象,换化成Map对象 List<Map> reportDataList = new ArrayList<Map>(); for (int i = 0; i < projectList.size(); i++) { Object[] personStr = projectList.get(i); Map reportData = new HashMap(); for (int j = 0; j < personStr.length; j++) { reportData.put("field_" + j, String.valueOf(personStr[j])); } reportDataList.add(reportData); } int columCount = 0;// 数据列 int fieldCount = 0;// 字段列数(因为pname比较长所以想让pname比其它的列长些,故设计这个变量) int pnameCount = -1;// 记录下pname的序号 for (int i = 0; i < printValue.length; i++) { // pthrow下面有两列 if ("pthrow".equals(printValue[i])) { columCount = columCount + 2; fieldCount = fieldCount + 2; // ploan下面也有两列 } else if ("ploan".equals(printValue[i])) { columCount = columCount + 2; fieldCount = fieldCount + 2; // 故意让pname也占两列 } else if ("pname".equals(printValue[i])) { pnameCount = i;// 记录下pname的序号 columCount = columCount + 1; fieldCount = fieldCount + 2; } else { // 其它的列都占一个单位 columCount = columCount + 1; fieldCount = fieldCount + 1; } } InputStream is = null; try { // 从资源文件中读取报表 is = this.getClass().getResourceAsStream("/reports/project.jrxml"); JasperDesign jasperDesign = (JasperDesign) JRXmlLoader.load(is); Map styleMap = jasperDesign.getStylesMap(); // column header 对应的样式 JRDesignStyle theaderStyle = (JRDesignStyle) styleMap.get("theader"); // column detail 对应的样式 JRDesignStyle tbodyStyle = (JRDesignStyle) styleMap.get("tboby"); // pagefoot 对应的样式 JRDesignStyle tfootStyle = (JRDesignStyle) styleMap.get("tfoot"); int _START_X_ = 20;// x轴的起始位置 int startX = _START_X_; // x轴的起始位置 // 单列的宽度 // 535是jasepreReport报表column最大的宽度 int columnWidth = 535 / fieldCount; // 20,24,15是报表中已设置的,一定与之相同 final int columnHeadBandHeight = 20; final int detailHeight = 24; final int pagefootHeight = 15; // 设置报表字段 for (int idx = 0; idx < columCount; idx++) { JRDesignField field = new JRDesignField(); field.setName("field_" + idx); field.setValueClass(java.lang.String.class); jasperDesign.addField(field); } JRDesignBand columnHeadBand = (JRDesignBand) jasperDesign.getColumnHeader(); // 绘制表头 for (int idx = 0; idx < printValue.length; idx++) { if ("pnumber".equals(printValue[idx])) { JRDesignStaticText staticText = new JRDesignStaticText(); staticText.setStyle(theaderStyle); staticText.setWidth(columnWidth); staticText.setY(0); staticText.setX(startX); staticText.setHeight(2 * columnHeadBandHeight); staticText.setText("序号"); columnHeadBand.addElement(staticText); startX += columnWidth; } else if ("pname".equals(printValue[idx])) { JRDesignStaticText staticText = new JRDesignStaticText(); staticText.setStyle(theaderStyle); // 项目名称的宽度是其它的宽度的2倍 staticText.setWidth(columnWidth * 2); staticText.setY(0); staticText.setX(startX); staticText.setHeight(2 * columnHeadBandHeight); staticText.setText("项目名称"); columnHeadBand.addElement(staticText); startX += columnWidth * 2; } else if ("pdepart".equals(printValue[idx])) { JRDesignStaticText staticText = new JRDesignStaticText(); staticText.setStyle(theaderStyle); staticText.setWidth(columnWidth); staticText.setY(0); staticText.setX(startX); staticText.setHeight(2 * columnHeadBandHeight); staticText.setText("部门"); columnHeadBand.addElement(staticText); startX += columnWidth; } else if ("pdecision".equals(printValue[idx])) { JRDesignStaticText staticText = new JRDesignStaticText(); staticText.setStyle(theaderStyle); staticText.setWidth(columnWidth); staticText.setY(0); staticText.setX(startX); staticText.setHeight(2 * columnHeadBandHeight); staticText.setText("已决策"); columnHeadBand.addElement(staticText); startX += columnWidth; } else if ("pthrow".equals(printValue[idx])) { // 投审会下面有两列 JRDesignStaticText staticText = new JRDesignStaticText(); staticText.setStyle(theaderStyle); staticText.setWidth(columnWidth * 2); staticText.setY(0); staticText.setX(startX); staticText.setHeight(columnHeadBandHeight); staticText.setText("投审会"); columnHeadBand.addElement(staticText); staticText = new JRDesignStaticText(); staticText.setStyle(theaderStyle); columnHeadBand.addElement(staticText); staticText.setWidth(columnWidth); staticText.setY(columnHeadBandHeight); staticText.setX(startX); staticText.setHeight(columnHeadBandHeight); staticText.setText("12月初"); staticText = new JRDesignStaticText(); staticText.setStyle(theaderStyle); columnHeadBand.addElement(staticText); staticText.setWidth(columnWidth); staticText.setY(columnHeadBandHeight); staticText.setX(startX + columnWidth); staticText.setHeight(columnHeadBandHeight); staticText.setText("12月中"); columnHeadBand.addElement(staticText); startX += 2 * columnWidth; } else if ("plastmonth".equals(printValue[idx])) { // 投决会下面有一列 JRDesignStaticText staticText = new JRDesignStaticText(); staticText.setStyle(theaderStyle); staticText.setWidth(columnWidth); staticText.setY(0); staticText.setX(startX); staticText.setHeight(columnHeadBandHeight); staticText.setText("投决会"); columnHeadBand.addElement(staticText); staticText = new JRDesignStaticText(); staticText.setStyle(theaderStyle); columnHeadBand.addElement(staticText); staticText.setWidth(columnWidth); staticText.setY(columnHeadBandHeight); staticText.setX(startX); staticText.setHeight(columnHeadBandHeight); staticText.setText("12月下"); columnHeadBand.addElement(staticText); startX += columnWidth; } else if ("pfund".equals(printValue[idx])) { JRDesignStaticText staticText = new JRDesignStaticText(); staticText.setStyle(theaderStyle); staticText.setWidth(columnWidth); staticText.setY(0); staticText.setX(startX); staticText.setHeight(2 * columnHeadBandHeight); staticText.setText("基金投资额"); columnHeadBand.addElement(staticText); startX += columnWidth; } else if ("ploan".equals(printValue[idx])) { // 投贷协同额下面有两列 JRDesignStaticText staticText = new JRDesignStaticText(); staticText.setStyle(theaderStyle); staticText.setWidth(columnWidth * 2); staticText.setY(0); staticText.setX(startX); staticText.setHeight(columnHeadBandHeight); staticText.setText("投贷协同额"); columnHeadBand.addElement(staticText); staticText = new JRDesignStaticText(); staticText.setStyle(theaderStyle); columnHeadBand.addElement(staticText); staticText.setWidth(columnWidth); staticText.setY(columnHeadBandHeight); staticText.setX(startX); staticText.setHeight(columnHeadBandHeight); staticText.setText("金额"); staticText = new JRDesignStaticText(); staticText.setStyle(theaderStyle); columnHeadBand.addElement(staticText); staticText.setWidth(columnWidth); staticText.setY(columnHeadBandHeight); staticText.setX(startX + columnWidth); staticText.setHeight(columnHeadBandHeight); staticText.setText("入库情况"); columnHeadBand.addElement(staticText); startX += 2 * columnWidth; } } // 绘制Detail部门 startX = _START_X_; JRDesignBand columnDetailBand = (JRDesignBand) jasperDesign.getDetail(); for (int idx = 0; idx < columCount; idx++) { JRDesignTextField textField = new JRDesignTextField(); textField.setStretchWithOverflow(true); textField.setX(startX); textField.setY(0); if (pnameCount == idx) { textField.setWidth(2 * columnWidth); startX += 2 * columnWidth; } else { textField.setWidth(columnWidth); startX += columnWidth; } textField.setHeight(detailHeight); textField.setPositionType(JRElement.POSITION_TYPE_FLOAT); textField.setStyle(tbodyStyle); textField.setBlankWhenNull(true); JRDesignExpression expression = new JRDesignExpression(); expression.setValueClass(java.lang.String.class); expression.setText("$F{field_" + idx + "}"); textField.setExpression(expression); columnDetailBand.addElement(textField); } JRDesignBand pageFootBand = (JRDesignBand) jasperDesign.getPageFooter(); // 合计数据,本应统计的 List<Object[]> pageCountList = new ArrayList<Object[]>(); Object[] obj = new String[] { "合计", "15299", "", "", "67121", "92420", "155877", }; pageCountList.add(obj); obj = new String[] { "", "", "", "XXX小计", "", "24473", "16470", }; pageCountList.add(obj); obj = new String[] { "", "", "", "WWW小计", "", "7289", "1674", }; pageCountList.add(obj); obj = new String[] { "", "", "", "ZZZ小计", "", "32700", "13000", }; pageCountList.add(obj); obj = new String[] { "", "", "", "YYY小计", "", "12733", "120733", }; pageCountList.add(obj); obj = new String[] { "", "", "", "AAA小计", "", "2225", "120733", }; pageCountList.add(obj); obj = new String[] { "", "", "", "BBB小计", "", "3000", "0", }; pageCountList.add(obj); int footWidth = 535 / 7; for (int p = 0; p < pageCountList.size(); p++) { for (int k = 0; k < 7; k++) { Object[] ob = pageCountList.get(p); JRDesignStaticText staticText = new JRDesignStaticText(); staticText.setStyle(tfootStyle); staticText.setWidth(footWidth); staticText.setY(pagefootHeight * p); staticText.setX(k * footWidth + _START_X_); staticText.setHeight(pagefootHeight); staticText.setText(String.valueOf(ob[k])); pageFootBand.addElement(staticText); } } // 编译报表 JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); String type = this.getRequest().getParameter("type");//pdf格式 JasperUtils.prepareReport(jasperReport, type); // 报表数据源 JRDataSource dataSource = new JRBeanCollectionDataSource(reportDataList); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, dataSource); HttpServletResponse response = this.getResponse(); JasperUtils.export(jasperPrint, response, getRequest(), type); } catch (Exception e) { e.printStackTrace(); } return null; }
public static void export(JasperPrint jasperPrint, HttpServletResponse response, HttpServletRequest request, String type) throws IOException { if (EXCEL_TYPE.equals(type)) { exportExcel(jasperPrint, response, request); } else if (PDF_TYPE.equals(type)) { exportPDF(jasperPrint, response, request); } else if (HTML_TYPE.equals(type)) { exportHTML(jasperPrint, response, request); } else { exportPrint(jasperPrint, response, request); } }
public static void exportExcel(JasperPrint jasperPrint, HttpServletResponse response, HttpServletRequest request) throws IOException { response.setContentType("application/vnd.ms-excel"); String filename = DownloadHelper.encodeFilename("未命名.xls", request); response.setHeader("Content-disposition", "attachment;filename=" + filename); ServletOutputStream ouputStream = response.getOutputStream(); JRXlsExporter exporter = new JRXlsExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream); 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); try { exporter.exportReport(); } catch (JRException e) { e.printStackTrace(); } ouputStream.flush(); ouputStream.close(); } public static void exportPDF(JasperPrint jasperPrint, HttpServletResponse response, HttpServletRequest request) throws IOException { response.setContentType("application/pdf"); String filename = DownloadHelper.encodeFilename("未命名.pdf", request); response.setHeader("Content-disposition", "attachment;filename=" + filename); ServletOutputStream ouputStream = response.getOutputStream(); try { JasperExportManager.exportReportToPdfStream(jasperPrint, ouputStream); } catch (JRException e) { e.printStackTrace(); } ouputStream.flush(); ouputStream.close(); }
发表评论
-
使用JavaBean构造JasperReport子报表
2010-01-27 14:05 10265使用JavaBean作为数据源构造JasperReport子报 ... -
JasperReport + Servlet Web应用之:HTML显示报表内容
2010-01-26 17:18 9958构造我们的JavaBean:(get,set方法省略,属性名称 ... -
JasperReport+Servlet Web应用之:导PDF,Excel,Rtf文件
2010-01-17 19:18 4244第一,二,三,四步请参照:JasperReport+Servl ... -
JasperReport+Servlet Web应用之:打印预览
2010-01-17 18:58 10423打印预览与打印的准备工作是一样的,第一,二,三,四,五步请参照 ... -
JasperReport+Servlet Web应用之:打印
2010-01-17 18:04 9997关于JasperReport的简介大家可以去google上去查 ...
相关推荐
主要介绍了Java 中jasperReport实现动态列打印的实现代码的相关资料,希望通过本文大家能掌握这部分内容,需要的朋友可以参考下
实现了jasperReport进行报表动态列的实现,使用者只需要利用eclipse将工程文件导入,即可查看运行结果的展示,不需要其他的配置和jar包如果想进行动态展示只需要修改构造参数就可以看到动态的展示
jasperreport 6.4.1报表动态列,以及生成导出html,可直接导入到eclipse中进行运行,包含一个完整的demo
Java燗applet+jasperReport 实现web端打印
jasperreport实现动态表头的例子
Jasperreport 客户端打印例子
jasperReport 动态合并单元格示例
使用subreport实现多表分页并动态适应列数,目前还在努力实现中,后续将更新。。。
通过ireport生成模版,使用jasperreport调用模版,通过servlet生成pdf格式的文件,显示于页面以实现本地打印功能
jasperreport列合并,将导出的excel合并列
springboot整合JasperReport实现报表功能文章所需的全部资源
jasperreport+applet客户端打印demo
。。。
。。。
windows下teach1.jasper考到c盘根目录,linux下改变一下路径。
jasperreport、applet 客户端打印 注意:使用程序请导入jasperReport3.0和iReport3.0的包。
JasperReport 打印 导出PDF XLS 这是我们公司架构师搭的一套架构,封装好了打印 导出功能,其他的报表只要实现这个机制就能完成功能了,该抽象的都抽象出来了,只有一个view.jsp页面。
基于Jasperreport动态单元格合并模板,支持多层分组排序,支持多分组动态合并单元格,附件中有两组以及大于两组的模板实例。
本报表在jasperreports-5.6.0基础上增加以下功能; 1、 表头固定 2、 列的隐藏及显示 3、 列的固定 示例代码可正常运行、本代码为非正式版
该工程下有ssh所需jar包,hicharts报表导出功能所需jar包,以及Jasperreport报表导出所需的jar包,主要是利用Jasperreport实现报表导出功能,可以完整跑通