帆软报表
下载软件
最新版本10
https://www.finereport.com/product/download
版本9要到百度搜索下载
教程
https://bbs.fanruan.com/edu/guide/finereport/3.html
自定义函数
1.把finereport的WEB-INF内的lib拷贝到本项目中
C:\FineReport_10.0\webapps\webroot\WEB-INF\lib
2.lib添加到library
3.写自定义函数,继承AbstractFunction
接受字符串最好用{}括起来,然后传递进来。可能是finereport的bug
4.编辑后,.class文件复制到WEB-INF\classes目录
C:\FineReport_10.0\webapps\webroot\WEB-INF\classes\com\fr\function
例如
package com.fr.function;
import com.fr.script.AbstractFunction;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
/**
* 计算日期差多少天
* @author lipo
* @date 2020/9/29 15:56
*/
public class UsedDays extends AbstractFunction {
@Override
public Object run(Object[] args) {
String str = args[0].toString();
str = str.replace("{", "");
str = str.replace("}", "");
String[] split = str.split(",");
int length = split.length;
if (length < 2) {
return "";
}
for (String s : split) {
if ("".equals(s)) {
return "";
}
}
LocalDate beginDate = parseDate(split[0]);
LocalDate endDate = parseDate(split[1]);
return endDate.toEpochDay() - beginDate.toEpochDay();
}
private LocalDate parseDate(String text) {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
return LocalDate.parse(text, dateTimeFormatter);
}
public static void main(String[] args) {
UsedDays remark = new UsedDays();
System.out.println(remark.run(new Object[]{12}));
System.out.println(remark.run(new String[]{"2020-04-27,"}));
System.out.println(remark.run(new String[]{"2020-04-27,2020-04-27"}));
System.out.println(remark.run(new String[]{"2020-04-27,2020-04-28"}));
System.out.println(remark.run(new String[]{"2020-04-27,2020-05-28"}));
System.out.println(remark.run(new String[]{"2020-04-27,2021-05-28"}));
}
}
还没有评论,来说两句吧...