`
omygege
  • 浏览: 1357309 次
文章分类
社区版块
存档分类
最新评论

使用iReport打印报表

 
阅读更多

一、建立iReport项目 mainFrame。


二、用iReport制作打印模板.


1、新建.jrxml
1)把长宽设置成和要打印文件大小相等,各边界值设为0。
2)右键properties把detail的值设为和要打印文件一样,其余的全设为0。(注意:每项设置后鼠标要点击下空白地方,否则设置不会成功。)
3)加图片,并把图片地址改为相对url。
4)在 预览->报表字段 中添加字段。(注意:批量打印在fiels里添加,单独打印在paramenters里添加。)
5)把报表字段里的字段托到图片上。(注意:把所有的字体改为宋体,blank when null勾上。
6)设置编译路径,并编译。


2、修改代码。
1)jsp里修改

(注意:<%@ include file="/lemis/common/lemisjs.jsp"%>的位置)
(1)main.jsp里修改:

(2)edit.jsp里修改

2)配置文件里修改:(注意:要把作用域改为session)
(1)main里加

<set-property property="param(preparePrint)" value="preparePrint" />
<set-property property="param(getPrintResult)" value="getPrintResult" />


(2)edit里加<set-property property="param(getPrintResult)" value="getPrintResult" />


3)action里修改:(注意:main里是QueryActionForm cForm = (QueryActionForm) form;edit里是CommonActionForm cForm = (CommonActionForm) form;)


(1)main里加3个方法
protected String generateReport(BaseActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response,
UserSession us, List list, Map map) throws Exception {
QueryActionForm cForm = (QueryActionForm) form;
DTO dto = cForm.getDtoObject();
WbEmployBpo wbBpo = (WbEmployBpo) us.getService("wbEmployBpo");
List keys = getSelectKeys(cForm);
ArrayList printList = new ArrayList();
for (int i = 0; i < keys.size(); i++) {
Key key = (Key)keys.get(i);
WbemployDomain wbDomain=new WbemployDomain();
wbDomain = (WbemployDomain) wbBpo.getDomainObjectByKey(key);
printList.add(wbDomain);
}
list.addAll(printList);
String file = "";
file = "config/jaspermodelprint/wb/empprint.jasper&config/jaspermodelprint/wb/empprint.jasper";
return file;
}


(2)editAction里加一个方法
public String generateReport(BaseActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response,
UserSession us, List list, Map map) throws Exception {
CommonActionForm cForm = (CommonActionForm) form;
DTO dto = (DTO) cForm.getDtoObject();
map.put("cardid", dto.get("cardid"));
map.put("carddate", CalendarUtil.stringToDate(dto.get("carddate").toString()));
map.put("cardorg", dto.get("cardorg"));
map.put("aac002", dto.get("aac002"));
String file = "";
if ("1".equals(dto.get("viewbackground"))) {
file = "config/jaspermodelprint/wb/empedit.jasper&config/jaspermodelprint/wb/empedit.jasper";
} else {
file = "config/jaspermodelprint/wb/empeditprint.jasper&config/jaspermodelprint/wb/empeditprint.jasper";
}
return file;
}


3.打印位置修改
1)在config/config/jaspermodelprint/position下加mianprint和editprint两文件,像一定素要指定好要与要打印的文件一致。
2)在jsp里加<layout:button value="修改打印位置[F]" accesskey="F" styleClass="button" onclick="open_url('../../common/report/alterPosition.do?reqCode=init&file=ditprint/mainprint',文件的长,文件的宽);" mode="D,D,N" />


三、注意
1、我们采用ireport做的jasper模板文件,有宽度和高度,如果要调整打印位置,则需要在config/jaspermodelprint/position中建一个文件,文件名与打印的jasper模板文件同名,内容为:文件名:宽度:高度。这里的宽度和高度应该与jasper模板的宽度和高度一致。

如果position中的文件的宽度和高度 大于jasper模板的宽度和高度,则调整打印位置时,虽然看起来没有出边界,但实际上已经出了jasper模板的边界,那么就打印不出来,应用服务器CPU资源占用100%,必须重启应用服务器。
2、date处理。要用CalendarUtil.stringToDate。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics