表格软件FineReport中如何设置批量打印

2025-10-28 01:10:32

1、批量打印传入的url格式

批量打印多张报表url格式如:http://localhost:8075/WebReport/ReportServer?reportlets=[{reportlet:'reportname1.cpt',paraname:'paravalue'},{reportlet:'reportname2.cpt',paraname:'paravalue'}]。

调用内置的打印方法直接使用完整的url进行批量打印:

var printurl="http://localhost:8075/WebReport/ReportServer?reportlets=[{reportlet:'reportname1.cpt',paraname:'paravalue'},{reportlet:'reportname2.cpt',paraname:'paravalue'}]";

FR.doURLPDFPrint(printurl,true);   //get方式传参

2、如批量打印的模板过多的话,url就很长,而get方式对长度有限制,url过长时会导致打印失败。推荐批量打印的时候用post方式,reportlets参数打包在数据包中传输,不在url中显示,从而缩短url长度,另外安全性较好,如下:

 var printurl="http://localhost:8075/WebReport/ReportServer";     

var reportlets = FR.cjkEncode("[{reportlet: '/doc/Primary/Parameter/Parameter_1.cpt', 地区 : '华东'}, {reportlet: '/doc/Primary/Parameter/Parameter_1.cpt', 地区 : '华北'}]");

var config = {

url : printurl,

isPopUp : false,

data : {

reportlets: reportlets

}

};

FR.doURLPDFPrint(config);

注:调用打印方法中的第二个参数为true表示弹出对话框,为false表示不弹出对话框即静默打印。

3、示例

如需要打印出某个模板所有参数情况对应的结果,如下图,选择希望打印的参数值,点击doPrint按钮批量打印出对应的结果。

表格软件FineReport中如何设置批量打印

4、实现思路

首先通过JS获取复选框的值然后拼凑出正确的url,最后调用打印方法如PDF打印,通过post方法传参(FR.doURLPDFPrint(printurl,true,{data: {reportlets : paravalue}});)或get方法传参(FR.doURLPDFPrint(printurl,true);)进行批量打印。

5、post传参PDF打印完整代码

<html>       

<head>      

<title>FineReport Demo</title>     

<script type="text/javascript" src="/WebReport/ReportServer?op=emb&resource=finereport.js"></script>       

<link rel="stylesheet" type="text/css" href="/WebReport/ReportServer?op=emb&resource=finereport.css"/>       

<script type="text/javascript">            

    function doPrint(){     //通过sessionid打印      

        var printurl="http://localhost:8075/WebReport/ReportServer";   

var p=[];

//获取当前页面选中的参数值,并将值放入数组中

$(":checkbox").each(function(){

if($(this).attr("checked")=="checked")

p.push("{reportlet: '/doc/Primary/Parameter/Parameter_1.cpt', 地区 : " + $(this).val() + "}");

})

if(p.length>0){

//将参数值组成的数组转化为字符串

var rp=p.join(",");

//使用FineReport自带的方法cjkEncode进行转码

var reportlets=FR.cjkEncode("["+rp+"]");

                var config = {  

                url : printurl,  

                isPopUp : false,

data : {  

                    reportlets: reportlets  

                }  

        };  

        FR.doURLPDFPrint(config);  }

else

alert("请选择需要打印的参数");

    }  

</script>       

</head>       

<body>       

<form name="report

    <input id="config1" type="checkbox" value="华东" />华东<br>    

    <input id="config2" type="checkbox" value="华北" />华北<br>    

    <input type="button" onClick="doPrint();" value="doPrint"><br>     

</form>       

<body>       

</html>  

6、效果查看

打开内置服务器,在浏览器中输入http://localhost:8075/WebReport/page_demo/cusprint_batch.html,选中多个复选框,点击doprint按钮,既可以实现批量打印了

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢