润乾报表v4-填报分页自动计算页数

来源:互联网 发布:网络翻墙 英文 编辑:程序博客网 时间:2024/05/14 15:02

假分页是针对填报表分页的一种解决方法。

之前的例子是写死的一页显示多少行,有多少页。

有的客户希望自动计算出总共的页数。

方法如下:

计算出数据集所包含的数据量:      

 //第一步,读取报表模板

       String reportFileHome=Context.getInitCtx().getMainDir();

       String reportPath = application.getRealPath(reportFileHome)+”\\跳转表.raq”; 

       ReportDefine rd = (ReportDefine)ReportUtils.read( reportPath );       

       //System.out.println(“reportPath==”+reportPath); 

       

       //第二步,运算报表

       Context context = new Context();        

       Engine enging = new Engine( rd, context);

       IReport iReport = enging.calc();

       

       //第三步,获取数据集记录数

       DataSetConfig dsc = iReport.getDataSetMetaData().getDataSetConfig(0);//得到数据集配置

       String dsName = dsc.getName();//得到数据集的名称

       DataSet dataSet = context.getDataSet(dsName);//得到数据集    

       int dsCount = dataSet.getRowCount();//得到数据集的记录数

然后通过计算把页数计算出来

double ha;

   ha=Math.ceil((double)dsCount/(double)pageCount);

最后作为参数传给报表

<table>

      <tr>

    <%if(nPage>1){%>

            <td><a href=”填报分页.jsp?nPage=<%=nPage-1%>&pageCount=<%=pageCount%>&haha=<%=haha%>”>上一页</a></td><%}%>       

<%if(nPage<haha){%>

<td><a href=”填报分页.jsp?nPage=<%=nPage+1%>&pageCount=<%=pageCount%>&haha=<%=haha%>”>下一页</a></td><%}%>

      </tr> 

</table>

0 0