Export "Employee Records Roster" to Excel with Java (Formula & Calculated Reports)
Formula & Calculated ReportsScene 0025
An employee-record roster maintained by HR, registering employee ID, name, department, position, hire date and salary standard, computing Annual Salary = Monthly Salary × 12 per row, with the last row summarizing total monthly and annual salary. Implemented declaratively in pure XML — no Java business code required.

About this demo
This demo exports the "Employee Records Roster" workbook: 1 data sheet(s); MAPPING over 7 columns (工号, 姓名, 部门, 职位, 入职日期, 月薪, 年薪), 9 formula(s), 1 style rule(s). On the Java side it builds 7 data rows and calls exportEmployeeProfile() 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 (74 lines, runnable as-is)
- The complete XML config (29 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 Records Roster to Excel with Java
Output specs
- Scene no.
- 0025
- Group
- Formula & Calculated Reports
- Config lines
- 29
- Source lines
- 74
Java source · Formulas0025EmployeeProfileRosterDemo.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 Formulas0025EmployeeProfileRosterDemo {
private static final String XML = "jquick/biz/formulas/0025_formulas_employee-profile-roster.xml";
/** 导出:纯 XML 完成年薪计算与月薪 / 年薪汇总。 */
@Test
public void exportEmployeeProfile() throws Exception {
List<JQuickRow> rows = new ArrayList<>();
rows.add(employee("E1001", "张伟", "研发部", "高级工程师", date(2020, 3, 15), 32000));
rows.add(employee("E1002", "李娜", "市场部", "市场专员", date(2021, 7, 1), 18000));
rows.add(employee("E1003", "王强", "财务部", "会计", date(2019, 5, 20), 15000));
rows.add(employee("E1004", "赵敏", "研发部", "技术专家", date(2018, 9, 10), 45000));
rows.add(employee("E1005", "陈刚", "生产部", "车间主管", date(2022, 2, 8), 12000));
rows.add(employee("E1006", "孙丽", "人力部", "招聘专员", date(2023, 6, 12), 11000));
// 合计占位行:薪酬留给 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);
rows.add(total);
File out = new File("D:/test/excel/biz/formulas/0025_formulas_employee-profile-roster.xlsx");
try (OutputStream os = new FileOutputStream(out)) {
JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("coral", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Formulas0025EmployeeProfileRosterService service = factory.createApi(Formulas0025EmployeeProfileRosterService.class);
service.exportEmployeeProfile("field", "value");
}
}
/** 构造一条员工档案(a=工号,b=姓名,c=部门,d=职位,e=入职日期,f=月薪)。 */
private static JQuickRow employee(String no, String name, String dept, String position, Date hireDate, double salary) {
JQuickRow row = new JQuickRow();
row.put("a", no);
row.put("b", name);
row.put("c", dept);
row.put("d", position);
row.put("e", hireDate);
row.put("f", salary);
row.put("g", null);
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("coral", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Formulas0025EmployeeProfileRosterService service = factory.createApi(Formulas0025EmployeeProfileRosterService.class);XML config · 0025_formulas_employee-profile-roster.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.Formulas0025EmployeeProfileRosterService">
<!-- 导出:员工档案名册 -->
<excel name="exportEmployeeProfile" returnClass="void">
<![CDATA[
EXPORT WITH SHEET="员工档案名册", HEADER=true,
MAPPING={"a":"工号","b":"姓名","c":"部门","d":"职位","e":"入职日期","f":"月薪","g":"年薪"},
FORMAT={"e":"yyyy-MM-dd","f":"#,##0.00","g":"#,##0.00"},
FORMULAS={
G2:'F2*12',G3:'F3*12',G4:'F4*12',G5:'F5*12',G6:'F6*12',G7:'F7*12',
F8:'SUM(F2:F7)',G8:'SUM(G2:G7)'
},
STYLE={ROW 8:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center}}
]]>
</excel>
<!-- 导入解析:读取导出的员工档案名册 -->
<excel name="importEmployeeProfile" returnClass="java.util.List">
<![CDATA[
IMPORT WITH SHEET="员工档案名册", HEADER=true,
MAPPING={"工号":"empNo","姓名":"name","部门":"dept","职位":"position","入职日期":"hireDate","月薪":"monthlySalary","年薪":"annualSalary"}
]]>
</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.