JXLS
2020/1/25 11:37:10
本文主要是介绍JXLS,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
http://jxls.sourceforge.net/images/grouping_template.png
http://jxls.sourceforge.net/samples/grouping_example.html
Grouping Sample
Introduction
This sample shows how to use grouping with Each-Command .
The Employee class looks like this.
public class Employee { private String name; private int age; private Double payment; private Double bonus; // getters/setters ...}
Report template
The report template for this example uses groupBy attribute of Each-Command
to define the grouping.
jx:each(items="employees" groupBy="name" groupOrder="asc" lastCell="D6")
Since the var attribute is missing the default group name _group is used to refer to the grouped collection items
Java code
The Java code is listed below
List<Employee> employees = generateSampleEmployeeData(); try(InputStream is = GroupingDemo.class.getResourceAsStream("grouping_template.xlsx")) { try (OutputStream os = new FileOutputStream("target/grouping_output.xlsx")) { Context context = new Context(); context.putVar("employees", employees); JxlsHelper.getInstance().processTemplate(is, os, context); } }public static List<Employee> generateSampleEmployeeData() throws ParseException { List<Employee> employees = new ArrayList<Employee>(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MMM-dd", Locale.US); employees.add( new Employee("Elsa", dateFormat.parse("1970-Jul-10"), 1500, 0.15) ); employees.add( new Employee("Oleg", dateFormat.parse("1973-Apr-30"), 2300, 0.25) ); employees.add( new Employee("John", dateFormat.parse("1970-Jul-10"), 3500, 0.10) ); employees.add( new Employee("Neil", dateFormat.parse("1975-Oct-05"), 2500, 0.00) ); employees.add( new Employee("Maria", dateFormat.parse("1978-Jan-07"), 1700, 0.15) ); employees.add( new Employee("John", dateFormat.parse("1969-May-30"), 2800, 0.20) ); employees.add( new Employee("Oleg", dateFormat.parse("1988-Apr-30"), 1500, 0.15) ); employees.add( new Employee("Maria", dateFormat.parse("1970-Jul-10"), 3000, 0.10) ); employees.add( new Employee("John", dateFormat.parse("1973-Apr-30"), 1000, 0.05) ); return employees;}
Excel output
Final report for this example is shown on the following screenshot
这篇关于JXLS的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-30INFINI Labs 产品更新 | Easysearch 1.8.0 发布数据写入限流功能
- 2024-05-09都2024年了,你还不知道git worktree么?
- 2024-05-09Budibase:低代码平台的革新者
- 2024-05-09edu邮箱注册免费申请认证matlab教育版1年使用资格
- 2024-05-091Panel - 现代化、开源的 Linux 服务器运维管理面板
- 2024-02-08使用uBlock Origin将知乎网页版表情显示为纯文字标签
- 2024-02-07联想LXH-JME2209U键盘Linux下解锁F1-F12
- 2024-02-07配置DDNS使得移动设备KDEConnect自动相互识别
- 2024-01-16AI 图像自动补全 Uncrop 工具介绍
- 2024-01-16独立开发者碎碎念 1115