潤乾集算報表提供了將多個報表組合到一起顯示的報表組功能。使用報表組可以很方便地將同類報表組合到一起展現、導出及打印。下面來看下報表組的使用。
報表組製作
新建報表組
首先準備要加入報表組中的報表,這裏使用訂單表和訂單明細表,兩表均帶有訂單ID範圍參數bid和eid。新建報表組,編輯報表源:
報表來源URL可以是絕對路徑,也可以是相對路徑(相對於應用資源路徑),這裏我們使用相對路徑。
增加參數
爲報表組設置參數如下:
編輯報表項
分別設置兩個報表項,更改報表項標題並設置參數,將報表組參數傳遞給各報表項:
設置後的報表組(group.rpg)如下:
到這裏報表組的設置已經完成,報表組中的訂單表和訂單明細表製作可參考集算報表相關文檔。
由於報表組中帶有參數,發佈到頁面需要參數輸入界面,所以這裏再製作一個參數模板(group_arg.rpx),聯合報表組發佈:
報表組展現
編輯報表組展現的JSP(showReportGroup.jsp):
<%@ pagecontentType="text/html;charset=GBK" %> <%@ tagliburi="/WEB-INF/raqsoftReport.tld" prefix="report" %> <%@ pageimport="java.io.*"%> <%@ pageimport="java.util.*"%> <%@ pageimport="com.raqsoft.report.usermodel.Context"%> <%@ pageimport="com.raqsoft.report.util.ReportUtils"%> <%@ pageimport="com.raqsoft.report.model.ReportDefine"%> <%@ pageimport="com.raqsoft.report.usermodel.ReportGroup"%> <%@ pageimport="com.raqsoft.report.usermodel.SubReportConfig"%> <html> <link type="text/css"href="css/style.css" rel="stylesheet"/> <body topmargin=0leftmargin=0 rightmargin=0 bottomMargin=0> <% request.setCharacterEncoding("GBK" ); String report = request.getParameter("rpg" ); StringreportFileHome=Context.getInitCtx().getMainDir(); StringBuffer param=new StringBuffer(); //保證報表名稱的完整性 int iTmp = 0; if( (iTmp =report.lastIndexOf(".rpg")) <= 0 ){ report = report +".rpg"; iTmp = 0; } Enumeration paramNames =request.getParameterNames(); if(paramNames!=null){ while(paramNames.hasMoreElements()){ String paramName =(String) paramNames.nextElement(); StringparamValue=request.getParameter(paramName); if(paramValue!=null){ //把參數拼成name=value;name2=value2;.....的形式 param.append(paramName).append("=").append(paramValue).append(";"); } } } //以下代碼是檢測這個報表是否有相應的參數模板 String paramFile =report.substring(0,iTmp)+"_arg.rpx"; File f=newFile(application.getRealPath(reportFileHome+ File.separator +paramFile)); %> <jsp:includepage="grouptoolbar.jsp" flush="false" /> <tableid="rpt" width=100%height=100%><tr><td> <% //如果參數模板存在,則顯示參數模板 if( f.exists() ) { %> <table id=param_tblalign=center><tr><td> <report:paramname="form1" paramFileName="<%=paramFile%>" needSubmit="no" params="<%=param.toString()%>" /> </td> <td><ahref="javascript:_submit( form1 )"><imgsrc="../images/query.jpg" border=nostyle="vertical-align:middle"></a></td> </tr></table> <% } %> <tablealign=center> <tr><td> <report:groupgroupFileName="<%=report%>" funcBarLocation="top" exceptionPage="/reportJsp/myError2.jsp" params="<%=param.toString()%>" appletJarName="raqsoftReportApplet.jar" /> </td></tr> </table> <scriptlanguage="javascript"> //設置分頁顯示值 document.getElementById( "t_page_span").innerHTML=report1_getTotalPage(); document.getElementById("c_page_span" ).innerHTML=report1_getCurrPage(); </script> </body> </html>
將以上報表和報表組放置到報表應用的應用資源路徑,如我這裏的D:\Program Files\raqsoft\report\webapps\demo\reportFiles,啓動應用,訪問發佈報表組頁面,如:http://192.168.1.100:6666/demo/reportJsp/showReportGroup.jsp?rpg=group.rpg可以看到報表組展現效果:
報表組導出
頁面發佈後,報表組可以導出Excel、PDF、WORD等文件,在發佈報表組的頁面<report:group>標籤下加入:
needSaveAsExcel="yes"
needSaveAsWord="yes"
needSaveAsPdf="yes"
即可在頁面中增加相應按鈕,已導出Excel爲例,導出效果如下:
報表組打印
與導出類似,在<report:group>標籤中加入needPrint="yes"屬性即可加入報表打印按鈕,報表組打印時會提示打印組內某個或某些報表,如下圖示:
用戶可以通過“預覽”查看報表打印預覽效果,通過“打印”完成報表組的打印操作。