动态隐藏报表组的sheet

报表组是由多张报表组合而成的,在页面上展现时就像excel的多sheet。由于业务需求,报表组中的所有报表并不是每次都展现,根据参数值可以动态的隐藏报表组中某个或者某几个报表。

比如报表组有3张报表,有个参数nSheet,如果这个参数值为report2,则把第二张报表隐藏起来。

代码如下:

String report = request.getParameter( “rpg” );

         String nSheet = request.getParameter(“nSheet”);//不显示的报表源名称,report1、report2

         Context ctx = new Context();

         // 得到报表组对象

         ReportGroup reportGroup = ReportUtils2.readReportGroup(report, ctx);

         if(nSheet != null && !nSheet.equals(“”)) {

                            String[] nShowSheets = nSheet.split(“,”);

                            for(String sheet : nShowSheets) {

                                     // 遍历报表子项,匹配报表源名称

                                     for(int i = 0; i < reportGroup.getItemCount(); i++) {

                                               ReportGroupItem reportGroupItem = reportGroup.getItem(i);

                                               // 找到匹配的sheet

                                               if(reportGroupItem.getName().equals(sheet)) {

                                                        // 删除该子项

                                                        reportGroup.removeItem(i);

                                                        break;

                                               }

                                     }

                            }

                   }

         String rptName = “RPT_”+Double.toString(Math.random());

         request.setAttribute(rptName,reportGroup); //把ReportDefine对象在request中保存

                   srcType=”bean”

                   beanName=”<%=rptName%>”

         />

页面效果:

当参数nSheet参数值为“report2”时,隐藏第二张,显示第一张和第三张报表,如下图

当参数nSheet参数值为“report2,report3”时,只展现第一张报表,隐藏第二张、第三张报表,如下图


转载自:http://www.geezn.com/archives/2772.html/

你可能感兴趣的:(报表,report,string,excel,bean,null)