Export "Employee Training Record Registration" to Excel with Java (Formula & Calculated Reports)
Formula & Calculated ReportsScene 0043
Registers employee training records, logging course, training date, credit hours and assessment score per row, with records that failed the assessment marked in red and the last row summarizing total credit hours and average score. Implemented declaratively in pure XML — no Java business code required.

About this demo
This demo exports the "Employee Training Record Registration" workbook: 1 data sheet(s); MAPPING over 8 columns (工号, 姓名, 部门, 培训课程, 培训日期, 学时, 考核成绩, 是否通过), 4 formula(s), 1 style rule(s). On the Java side it builds 6 data rows and calls exportTrainingRecord() once — everything else is driven by the config.
It belongs to the "Formula & Calculated Reports" group: FORMULAS — inline expressions and aggregate functions such as Quantity × Unit Price or Balance = Receivable − Received, with SUM totals on the last row.
What you can copy from this page
- The complete Java test class (76 lines, runnable as-is)
- The complete XML config (31 lines: mapping, formulas, styles, charts and every other rule)
- The exported xlsx file (real output, comparable with the preview above)
Related searches: Java export Excel formulas, Java Excel SUM formula export, Apache POI write formula example, Java computed column export, export Employee Training Record Registration to Excel with Java
Output specs
- Scene no.
- 0043
- Group
- Formula & Calculated Reports
- Config lines
- 31
- Source lines
- 76
Java source · Formulas0043TrainingRecordDemo.java
This is the complete test class that produced the Excel file above — copy it and run as-is. Java only builds the data rows; all statistics and styling live in the XML config.
package com.github.paohaijiao.biz.formulas;
import com.github.paohaijiao.statement.JQuickRow;
import com.github.paohaijiao.xml.ex.JQuickExcelExportXmlParseFactory;
import com.github.paohaijiao.xml.factory.JQuickFactory;
import com.github.paohaijiao.xml.factory.JQuickXmlFactory;
import com.github.paohaijiao.xml.handler.JQuickParseHandler;
import org.junit.Test;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
public class Formulas0043TrainingRecordDemo {
private static final String XML = "jquick/biz/formulas/0043_formulas_training-record.xml";
/** 导出:纯 XML 完成学时汇总、平均成绩与不及格标红。 */
@Test
public void exportTrainingRecord() throws Exception {
List<JQuickRow> rows = new ArrayList<>();
rows.add(record("E1001", "张伟", "研发部", "安全生产", date(2026, 3, 5), 8, 92, "通过"));
rows.add(record("E1002", "李娜", "市场部", "客户沟通", date(2026, 3, 8), 6, 85, "通过"));
rows.add(record("E1003", "王强", "生产部", "设备操作", date(2026, 3, 10), 12, 58, "未通过"));
rows.add(record("E1004", "赵敏", "财务部", "税务合规", date(2026, 3, 12), 10, 88, "通过"));
rows.add(record("E1005", "陈刚", "研发部", "项目管理", date(2026, 3, 15), 16, 79, "通过"));
// 合计占位行:总学时与平均成绩留给 FORMULAS
JQuickRow total = new JQuickRow();
total.put("a", "合计");
total.put("b", null);
total.put("c", null);
total.put("d", null);
total.put("e", null);
total.put("f", null);
total.put("g", null);
total.put("h", null);
rows.add(total);
File out = new File("D:/test/excel/biz/formulas/0043_formulas_training-record.xlsx");
try (OutputStream os = new FileOutputStream(out)) {
JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("forestGreen", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Formulas0043TrainingRecordService service = factory.createApi(Formulas0043TrainingRecordService.class);
service.exportTrainingRecord("field", "value");
}
}
/** 构造一条培训记录(a=工号,b=姓名,c=部门,d=课程,e=日期,f=学时,g=成绩,h=是否通过)。 */
private static JQuickRow record(String empNo, String name, String dept, String course, Date trainDate,
double hours, double score, String passed) {
JQuickRow row = new JQuickRow();
row.put("a", empNo);
row.put("b", name);
row.put("c", dept);
row.put("d", course);
row.put("e", trainDate);
row.put("f", hours);
row.put("g", score);
row.put("h", passed);
return row;
}
/** 构造一个「年-月-日」日期(月份从 1 开始)。 */
private static Date date(int year, int month, int day) {
Calendar c = Calendar.getInstance();
c.clear();
c.set(year, month - 1, day);
return c.getTime();
}
}Minimal invocation (4 lines)
The core is these four lines: hand the rows to the parser, the parser to the factory, get a typed Service and call it. Copy them straight into your project.
// rows 由业务代码构造(List<JQuickRow>),os 为输出流,见下方完整源码
JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("forestGreen", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Formulas0043TrainingRecordService service = factory.createApi(Formulas0043TrainingRecordService.class);XML config · 0043_formulas_training-record.xml
Formats (FORMAT), formulas (FORMULAS) and styles (STYLE) are all declared in this XML, fully decoupled from the Java code. The full config is below — copy it as-is.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE excels PUBLIC "-//PAOHAIJIAO//DTD API EXCEL 1.0//EN"
"classpath:paohaijiao/dtd/Jquick-excel.dtd">
<excels namespace="com.github.paohaijiao.biz.formulas.Formulas0043TrainingRecordService">
<!-- 导出:员工培训档案登记 -->
<excel name="exportTrainingRecord" returnClass="void">
<![CDATA[
EXPORT WITH SHEET="员工培训档案登记", HEADER=true,
MAPPING={"a":"工号","b":"姓名","c":"部门","d":"培训课程","e":"培训日期","f":"学时","g":"考核成绩","h":"是否通过"},
FORMAT={"e":"yyyy-MM-dd","f":"0","g":"0"},
FORMULAS={
F7:'SUM(F2:F6)',G7:'AVERAGE(G2:G6)'
},
STYLE={
ROW 7:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center},
G4:{color:red,bold:true}
}
]]>
</excel>
<!-- 导入解析:读取导出的员工培训档案登记 -->
<excel name="importTrainingRecord" returnClass="java.util.List">
<![CDATA[
IMPORT WITH SHEET="员工培训档案登记", HEADER=true,
MAPPING={"工号":"empNo","姓名":"name","部门":"dept","培训课程":"course","培训日期":"trainDate","学时":"hours","考核成绩":"score","是否通过":"passed"}
]]>
</excel>
</excels>More demos in this group
The Excel file, preview image, XML config and source code on this page were all produced by a real JQuick-Excel run and are free to copy into your own project.