帆软报表

拼搏现实的明天。 2022-12-13 01:28 311阅读 0赞

下载软件

最新版本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

例如

  1. package com.fr.function;
  2. import com.fr.script.AbstractFunction;
  3. import java.time.LocalDate;
  4. import java.time.format.DateTimeFormatter;
  5. /**
  6. * 计算日期差多少天
  7. * @author lipo
  8. * @date 2020/9/29 15:56
  9. */
  10. public class UsedDays extends AbstractFunction {
  11. @Override
  12. public Object run(Object[] args) {
  13. String str = args[0].toString();
  14. str = str.replace("{", "");
  15. str = str.replace("}", "");
  16. String[] split = str.split(",");
  17. int length = split.length;
  18. if (length < 2) {
  19. return "";
  20. }
  21. for (String s : split) {
  22. if ("".equals(s)) {
  23. return "";
  24. }
  25. }
  26. LocalDate beginDate = parseDate(split[0]);
  27. LocalDate endDate = parseDate(split[1]);
  28. return endDate.toEpochDay() - beginDate.toEpochDay();
  29. }
  30. private LocalDate parseDate(String text) {
  31. DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  32. return LocalDate.parse(text, dateTimeFormatter);
  33. }
  34. public static void main(String[] args) {
  35. UsedDays remark = new UsedDays();
  36. System.out.println(remark.run(new Object[]{12}));
  37. System.out.println(remark.run(new String[]{"2020-04-27,"}));
  38. System.out.println(remark.run(new String[]{"2020-04-27,2020-04-27"}));
  39. System.out.println(remark.run(new String[]{"2020-04-27,2020-04-28"}));
  40. System.out.println(remark.run(new String[]{"2020-04-27,2020-05-28"}));
  41. System.out.println(remark.run(new String[]{"2020-04-27,2021-05-28"}));
  42. }
  43. }

发表评论

表情:
评论列表 (有 0 条评论,311人围观)

还没有评论,来说两句吧...

相关阅读