ireport开发报表实现金额大写

开发环境:ireport 5.6.0 ; java 1.7 ;脚本放在eclipse的项目目录(包)下,否则会无效(注意)

                <dependency>
			<groupId>net.sf.jasperreports</groupId>
			<artifactId>jasperreports</artifactId>
			<version>6.5.1</version>
		</dependency>
                <dependency>
			<groupId>com.itextpdf</groupId>
			<artifactId>itext-asian</artifactId>
			<version>5.1.0</version>
		</dependency>
		<dependency>
			<groupId>com.itextpdf</groupId>
			<artifactId>itextpdf</artifactId>
			<version>5.5.6</version>
		</dependency>
		<dependency>
			<groupId>com.lowagie</groupId>
			<artifactId>itext</artifactId>
			<version>4.2.0</version>
		</dependency>

1、工具--选项--ClassPath--Add Folder ,加入TransChineseMoneyScriptlet.class(脚本程序)所在项目的class文件的classes路径,如C:\workspaces\privilege\target\classes\com\cn\report\TransChineseMoneyScriptlet.class,加入的路径为C:\workspaces\privilege\target\classes 。

2、在ireport自己的模板中,选中Scriptlets下的REPORT(Scriptlets通常在Variables下面),在右边REPORT - 属性 中的Scriptlet Class后面,写上TransChineseMoneyScriptlet.class的包名+类名,如(com.cn.report.TransChineseMoneyScriptlet),不用修改上面的Name属性。

3、在模板的Variables下创建两个变量(sumTaxMoney和cnMoney),sumTaxMoney只修改Variable Class为Double类型(就是要和脚本中sumTaxMoney变量的类型保持一致即可),其他属性不用修改;cnMoney也只需要将Variable Class改为String即可。

4、在属性面板中,拖拽出一个Text Field到模板界面,选中Text Feild框,然后在右边的属性中,设置Text field properties下的Text field Expression的值,格式为((脚本的包名+类名)$P{REPORT_SCRIPTLET}).getChineseMoney(要转化的字段或变量.toString()),(说明一下:前面的(脚本的包名+类名)是要强转类型)举个栗子:需转化$V(amount_total)的话,应写为((com.cn.report.TransChineseMoneyScriptlet)$P{REPORT_SCRIPTLET}).getChineseMoney($V{amount_total}.toString())即可,然后将紧挨着的Expression Class属性,设为String,其他属性不用修改。

5、使用:在模板界面中,将已设置好的Text Field,拖动到合适位置即可。Text Field里的内容不要动,自动显示属性Text field Expression里的值就行。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值