excel报表工具FineReport之参数界面及工具栏

  • 原创
  • |
  • 浏览:339
  • |
  • 更新:
  • |
  • 标签:报表 

FineReport本身自带多种可编辑控件,可以实现复杂参数界面的制作。但是有时为了实现与系统界面中控件的一致性,希望不使用FR内置的参数界面和内置工具栏,而是自己定义参数界面以及工具栏,此时要如何设置呢?

工具/原料

  • excel报表工具FineReport

1.解决思路

  • 在自定义参数界面中介绍了自定义参数界面的实现方式,在自定义工具栏章节中介绍了各种按钮的实现方式,那么只需要将这两个实现过程结合起来即可。

    END
  • 本页面未经许可获取自百度经验

2.示例

  • 以自定义参数界面中的最终模板/demo/parameter/number1.cpt模板为例,将其嵌入到页面中去,并且不显示模板参数界面和内置工具栏。

  • 2.1 效果

    效果如下图所示

    excel报表工具FineReport之参数界面及工具栏
  • 输入最小库存量,点击查询,就会提交参数值给number1.cpt模板,并且在该页面显示过滤结果。

  • 2.2网页设计

    网页设计参见自定义参数界面并传参,只需要再添加一个工具栏即可,工具栏添加的详细介绍请查看自定义工具栏按钮。

    在网页中添加如下代码:

  • <body>  

     <!-- 自定义工具栏-->    

        <div id="toolbar">         

        <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.gotoFirstPage()">首页</button>    

        <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.gotoPreviousPage()">上一页</button>         

        <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.gotoNextPage()">下一页</button>         

        <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.gotoLastPage()">末页</button>                

        <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.flashPrint()">客户端FLASH打印</button>            

        <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.exportReportToExcel('page')">导出[Excel](分页)</button>    

        <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.exportReportToWord()">导出[Word]</button>                

        </div>    

  • 完整代码如下:

    <html>  

      <head>    

      <title>FineReport Demo</title>    

      <meta http-equiv="Content-Type" content="text/html; charset=GBK" />    

      <script type="text/javascript">  

        //cjkEncode方法的实现代码,放在网页head中或者用户自己的js文件中  

        function cjkEncode(text) {                                                                            

          if (text == null) {         

            return "";         

          }         

          var newText = "";         

          for (var i = 0; i < text.length; i++) {         

            var code = text.charCodeAt (i);          

            if (code >= 128 || code == 91 || code == 93) {  //91 is "[", 93 is "]".         

              newText += "[" + code.toString(16) + "]";         

            } else {         

              newText += text.charAt(i);         

            }         

          }         

          return newText;         

        }     

      

        function autoSubmit() {  

          var num = document.getElementById('num').value; //获取文本控件的值  

          var row = document.getElementById('row').value; //获取下拉框控件的值  

          //拼接出最终报表访问路径,并对完整的路径进行编码转换,防止乱码问题  

          var reportURL = cjkEncode("/WebReport/ReportServer?reportlet=/demo/parameter/number1.cpt¶=" + num + "&row=" + row);  

          document.paraForm.action = reportURL; //通过form的name获取表单,并将报表访问路径赋给表单的action  

          document.paraForm.submit(); //触发表单提交事件  

        }  

      </script>  

      </head>    

      <body>  

       

        <fieldset>  

        <legend>查询表单:</legend>  

        <form name="paraForm" method="post" target="reportFrame">  

            最小库存量:<input type="text" name="num" id="num" value="1"/>  

            每页显示行数:<select name="row" id="row">    

            <option value="10" select>10    

            <option value="20">20  

            <option value="30">30  

            <input type="button" name="show" value="查询" onclick="autoSubmit()"/>  

        </form> <!-- 自定义工具栏-->    

        <div id="toolbar">         

        <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.gotoFirstPage()">首页</button>    

        <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.gotoPreviousPage()">上一页</button>         

        <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.gotoNextPage()">下一页</button>         

        <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.gotoLastPage()">末页</button>                

        <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.flashPrint()">客户端FLASH打印</button>            

        <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.exportReportToExcel('page')">导出[Excel](分页)</button>    

        <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.exportReportToWord()">导出[Word]</button>                

        </div>    

        </fieldset>  

        <iframe id="reportFrame" name="reportFrame" width="100%" height="100%" ></iframe>    

      </body>    

    </html>  

  • 已完成页面请参照%FR_HOME%\WebReport\page_demo\parameter_toolbar.html.

    END
经验内容仅供参考,如果您需解决具体问题(尤其法律、医学等领域),建议您详细咨询相关领域专业人士。
作者声明:本篇经验系本人依照真实经历原创,未经许可,谢绝转载。
展开阅读全部
相关标签报表