iReport:结合EOS实现报表打印
1. 新建---选择A4纸---open this template--输入ireport名
2. 导入数据库连接包jar文件: 工具-->选项-->classpassth-->add jar
其实这就是jdbc的jar文件嘛,有oracle的,有db2的。
3. 编辑数据源,连接数据库(点大圆柱体)
4. 把SQL语句放到小圆柱体中。
先加查询语句,点击"Read field" 把查询出的字段显示在下面 select cust_id, cust_name from scms_cust
再加上输入值的where判断条件,点ok。报错别管它。 where cust_id = $P{procinstid}
5. 到左边 Parameters下面增加要传的参数添加进去(procinstid)
这里注意参数的名字包括大小写什么的都要和$P{procinstid},还有EOS中传进来的参数拼写一致。
6. 这里只保留 title detail 其他删掉
7. 添加 Style,以下三个必须设对(为毛?反正不设置不会显示)
Font name: 宋体
Pdf Font name: STSong-Light
Pdf Encoding: UniGB-UCS2-H (Chinese Simplified)
8. Static text(常量) Text feild(变量)
选中变量参数的那个框框,右键,第一个(Edit expression),可以编辑要输入的东西 $F{CUST_NAME} ,
这些都是查询来的字段相对应的东东
表格设置:右键这些框框,选Paddinig and borders,可以设置边框的粗细等情况,line width :0.5
日期转换:选中变量区-- 右键-- 编辑-- 输入日期转换的语句 new SimpleDateFormat("yyyy-MM-dd").format($F{EVALDT})
变量为空:如果传到页面上的值为null,则可以勾上BLANK WHEN NULL
9. 点preview 就算是编译了,然后输入参数 查看测试结果
有提示the document has no page,说明查询语句查询的结果为空哦
如果还是跳回界面,那就是没编译通过,下面有报错的信息
生成的PDF空白一片,没问题的,到EOS中会出来
EOS 中的情况.......
1. 先导入构建包
选中自己所在的包(com.sunline.serm.creditflow)右键---属性---构建包---依赖---选中com.sunline.scms.report这个包
(引进之后,就可以用它里面的东东,java的包的知识。ireport编译后的东东放在这个包里。)
2. 把jasper文件放到EOSZ中
Jrxml文件得编译(点preview)后才能使japer文件更新。
把jasper文件复制粘贴到 com.sunline.scms.report --> 展现 --> 页面资源 --> scms --> jasper下
3. 拖逻辑控件com.sunline.scms.util.report.ReportUtil.getReportFileName
(jasperName 包装导入的jasper文件的名字,parameters包装传入的参数名字,fileType写PDF,out0写reportFileName)
4. 显示页面地址:/report/reportx.jsp(可自己新建)
/reportx.jsp 是新建的,建在com.sunline.scms.report包中,如果之前那个步骤我们没有导入report包,这个页面就打不开哦。这个页面就是现实页面
1 <%@page pageEncoding="UTF-8"%> 2 <%@include file="/common.jsp"%> 3 <html> 4 <%-- 5 - Author(s): Administrator 6 - Date: 2010-03-27 15:26:09 7 - Description: 8 --%> 9 <head> 10 <title>Title</title> 11 </head> 12 <% 13 String reportFileName = (String) com.eos.foundation.data.DataContextUtil 14 .getString("reportFileName"); 15 %> 16 <body> 17 <h:form name="form1" 18 action="" checkType="blur" 19 target="_self" method="post" onsubmit="return checkForm(this);"> 20 <input type="hidden" name="_eosFlowAction" value="reportQuery"> 21 <w:panel id="panel1" width="100%" title="文件打印"> 22 <table align="center" border="0" width="100%" class="form_table"> 23 <l:notEmpty property="reportFileName"> 24 <tr> 25 26 <td colspan="6"><!-- 工具栏区域 --> 27 <h:hiddendata property="query"/> 28 <h:hidden property="query/flag"/> 29 <h:hidden property="actionx"/> 30 <!-- <a href="#" onclick="beforeQuery('xls');"> <img 31 src="http://www.cnblogs.com/../common/images/icons/ico_file_excel.png" border="0" 32 alt="Excel格式下载"> Excel格式下载</a></td> --> 33 </tr> 34 <tr> 35 <td colspan="6"> 36 <% 37 if (reportFileName == "notpage") { 38 %> <font size="4" color="red"><B>报表查询失败,没有生成报表文件!</B></font> <% 39 } else { 40 %> <!-- 报表数据展示区域 --> <iframe id="rptViewFrame" 41 name="rptViewFrame" width="100%" height="800" 42 onload="waitClose();" scrolling=no frameborder=0 43 src="http://www.cnblogs.com/../<%= reportFileName %>"></iframe> <% 44 } 45 %> 46 </td> 47 </tr> 48 </l:notEmpty> 49 </table> 50 </w:panel> 51 </h:form> 52 </body> 53 </html> 54 <script language="javascript"> 55 function beforeQuery(str){ 56 if(str=='xls'){ 57 $name("query/flag").value='xls'; 58 } 59 var frm = $name("form1"); 60 frm.action=$name("actionx").value; 61 frm.submit(); 62 } 63 </script>