1 原理
lczPlugin 插件连接乐创者服务器后,对参数进行组合轮询,把生成的报表结果缓存在事先指定的目录中(模式0是缓存在内存中),一个轮询组合对应一个结果文件(所以目录下会出现很多个文件),整个过程批量进行。
然后,lczPlugin 能够针对缓存中的结果文件进行批量打印。
通过把 lczPlugin 插件集成到代码中的方式,可以实现各种场合的批量打印功能。
2 准备报表
制作一张含参数年份和月份的清单报表,因为模板的内部名称是自动生成的,我们可以修改为一个比较容易辨别的名称,例如修改为“hte_bulk_print_demo”:
我们的目标是:批量打印 2018年7月 至 2019年1月 的该张报表。
3 代码中集成lczPlugin插件
可以在C/S软件中集成,亦可以在网页中集成。
假设用网页来集成,效果目标是:
我们的意图是,当点击浏览器界面中的“批量打印”按钮后,在上图红框区域会出现打印过程的进度条等信息。
源码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>批量打印示例</title>
</head>
<body>
<script language=javascript>
function onBatchPrintReports()
{
//以下请设置为您自己的环境信息
demo.ServerAddr = "127.0.0.1";
demo.ServerPort = "80";
demo.ServerContextPath = "your_server_name";
demo.TargetVolume = "your_app_name";
demo.AuthId = "anonymous_admin";
demo.FolderPath = "D://my_caches";
var BatchXml = document.getElementById("batchxml").value;
demo.PrintReports(BatchXml, 0);
}
</script>
<table>
<tbody>
<tr height="0">
<td>
<textarea id="batchxml" style="display: none" >
<?xml version="1.0" encoding="UTF-8"?>
<BatchReport>
<CustomReports>
<Report Name="hte_bulk_print_demo" Alias="回款流水(2018年07月)">
<Type>hte</Type>
<Variants>年份=2018;月份=7</Variants>
</Report>
<Report Name="hte_bulk_print_demo" Alias="回款流水(2018年08月)">
<Type>hte</Type>
<Variants>年份=2018;月份=8</Variants>
</Report>
<Report Name="hte_bulk_print_demo" Alias="回款流水(2018年09月)">
<Type>hte</Type>
<Variants>年份=2018;月份=9</Variants>
</Report>
<Report Name="hte_bulk_print_demo" Alias="回款流水(2018年10月)">
<Type>hte</Type>
<Variants>年份=2018;月份=10</Variants>
</Report>
<Report Name="hte_bulk_print_demo" Alias="回款流水(2018年11月)">
<Type>hte</Type>
<Variants>年份=2018;月份=11</Variants>
</Report>
<Report Name="hte_bulk_print_demo" Alias="回款流水(2018年12月)">
<Type>hte</Type>
<Variants>年份=2018;月份=12</Variants>
</Report>
<Report Name="hte_bulk_print_demo" Alias="回款流水(2019年01月)">
<Type>hte</Type>
<Variants>年份=2019;月份=1</Variants>
</Report>
</CustomReports>
</BatchReport>
</textarea>
</td>
</tr>
<tr height="30">
<td>
<input type="button" onclick="onBatchPrintReports()" value="批量打印" />
</td>
</tr>
<tr height="300">
<td>
<object classid="clsid:FA279D01-EDAB-429E-8E0C-274BB7EFF8E7" id="demo"
width="500" height="300" >
</object>
</td>
</tr>
</tbody>
</table>
</body>
</html>
二次开发接口,可参考:http://help.lczyun.com/developer.html#/4.240
源码分析:
1)点击“批量打印”按钮后触发的功能
主要是配置了与乐创者服务器的连接信息;指定了缓存目录;最后调用 PrintReports 方法。
2)代码中放置 lczPlugin 插件
3)为 PrintReports 方法提供所需要的第一个参数
PrintReports方法需要两个参数:第一个参数是一个文本串,是XML格式的,提供了参数组合等信息。关于第二个参数,我们接下来会讲解。
4 操作示范
我们针对 PrintReports 方法的第二个参数的不同来演示对应的操作。
1)如果 PritReports 方法的第二个参数为0:
点击“批量打印”按钮,界面显示进入生成环节,如下图示范:
生成环节结束后,紧跟着进入打印环节,如下图示范:
2)如果 PritReports 方法的第二个参数为1:
点击“批量打印”按钮,界面显示进入生成环节,并在生成完毕后出现提示框询问用户是否要进行打印?
3)如果 PritReports 方法的第二个参数为2:
点击“批量打印”按钮,界面首先是要用户选择缓存目录:
填写目录后,点击“下一步”:
这个时候点击“打印”按钮就可以开始批量打印了。
最后编辑:fancy 更新时间:2024-10-31 17:13
