Export "Employee Leave Request Summary" to Excel with Java (Data Validation)
Data ValidationScene 0061
Summarizes employee leave requests, with the last row totaling the total leave days; submitted content is rule-validated on import (employee ID / name length, department and leave-type dictionaries, leave-days value range). Implemented declaratively in pure XML — no Java business code required.

About this demo
This demo exports the "Employee Leave Request Summary" workbook: 1 data sheet(s); MAPPING over 8 columns (工号, 姓名, 部门, 请假类型, 开始日期, 结束日期, 请假天数, 审批状态), 2 formula(s), 1 style rule(s). On the Java side it builds 7 data rows and calls exportLeaveApplicationSummary() once — everything else is driven by the config.
It belongs to the "Data Validation" group: VALIDATION form validation: an input template is exported and every field is validated when it is imported back.
What you can copy from this page
- The complete Java test class (77 lines, runnable as-is)
- The complete XML config (39 lines: mapping, formulas, styles, charts and every other rule)
- The exported xlsx file (real output, comparable with the preview above)
Related searches: Java Excel export validation, Java validate imported Excel, Java Excel form template validation, export Employee Leave Request Summary to Excel with Java
Output specs
- Scene no.
- 0061
- Group
- Data Validation
- Config lines
- 39
- Source lines
- 77
Java source · Validation0061LeaveApplicationSummaryDemo.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.validation;
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 Validation0061LeaveApplicationSummaryDemo {
private static final String XML = "jquick/biz/validation/0061_validation_leave-application-summary.xml";
/** 导出:纯 XML 完成请假总天数汇总与合计行高亮。 */
@Test
public void exportLeaveApplicationSummary() throws Exception {
List<JQuickRow> rows = new ArrayList<>();
rows.add(leave("E2601", "张伟", "研发部", "年假", date(2026, 3, 2), date(2026, 3, 4), 3, "已批准"));
rows.add(leave("E2602", "李娜", "市场部", "事假", date(2026, 3, 5), date(2026, 3, 5), 1, "已批准"));
rows.add(leave("E2603", "王强", "生产部", "病假", date(2026, 3, 9), date(2026, 3, 11), 3, "已批准"));
rows.add(leave("E2604", "赵敏", "财务部", "年假", date(2026, 3, 12), date(2026, 3, 16), 5, "待审批"));
rows.add(leave("E2605", "陈杰", "研发部", "调休", date(2026, 3, 18), date(2026, 3, 19), 2, "已批准"));
rows.add(leave("E2606", "周涛", "市场部", "事假", date(2026, 3, 23), date(2026, 3, 23), 1, "已批准"));
// 合计占位行:请假总天数留给 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/validation/0061_validation_leave-application-summary.xlsx");
try (OutputStream os = new FileOutputStream(out)) {
JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("coral", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Validation0061LeaveApplicationSummaryService service = factory.createApi(Validation0061LeaveApplicationSummaryService.class);
service.exportLeaveApplicationSummary("field", "value");
}
}
/** 构造一条请假申请(a=工号,b=姓名,c=部门,d=类型,e=开始,f=结束,g=天数,h=状态)。 */
private static JQuickRow leave(String employeeNo, String name, String department, String leaveType,
Date startDate, Date endDate, int leaveDays, String approvalStatus) {
JQuickRow row = new JQuickRow();
row.put("a", employeeNo);
row.put("b", name);
row.put("c", department);
row.put("d", leaveType);
row.put("e", startDate);
row.put("f", endDate);
row.put("g", leaveDays);
row.put("h", approvalStatus);
return row;
}
/** 构造日期(月份按自然月 1-12 传入)。 */
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);
Validation0061LeaveApplicationSummaryService service = factory.createApi(Validation0061LeaveApplicationSummaryService.class);XML config · 0061_validation_leave-application-summary.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.validation.Validation0061LeaveApplicationSummaryService">
<!-- 导出:员工请假申请汇总表 -->
<excel name="exportLeaveApplicationSummary" returnClass="void">
<![CDATA[
EXPORT WITH SHEET="员工请假申请汇总表", HEADER=true,
MAPPING={"a":"工号","b":"姓名","c":"部门","d":"请假类型","e":"开始日期","f":"结束日期","g":"请假天数","h":"审批状态"},
FORMAT={"e":"yyyy-MM-dd","f":"yyyy-MM-dd","g":"0"},
FORMULAS={
G8:'SUM(G2:G7)'
},
STYLE={
ROW 8:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center}
}
]]>
</excel>
<!-- 导入解析:读取填报的请假申请并逐项校验(校验不通过时抛出异常,异常信息即规则 msg) -->
<excel name="importLeaveApplicationSummary" returnClass="java.util.List">
<![CDATA[
IMPORT WITH SHEET="员工请假申请汇总表", HEADER=true,
MAPPING={"工号":"employeeNo","姓名":"name","部门":"department","请假类型":"leaveType","开始日期":"startDate","结束日期":"endDate","请假天数":"leaveDays","审批状态":"approvalStatus"},
VALIDATION={
A2:A7:{min_length{required:true,msg:'工号至少4位',map:{minLength:4}}},
B2:B7:{min_length{required:true,msg:'姓名至少2个字',map:{minLength:2}}},
C2:C7:{dict{required:true,msg:'部门必须在字典内',map:{'研发部':'研发部','市场部':'市场部','生产部':'生产部','财务部':'财务部'}}},
D2:D7:{dict{required:true,msg:'请假类型必须在字典内',map:{'年假':'年假','事假':'事假','病假':'病假','调休':'调休'}}},
G2:G7:{integer{required:true,msg:'请假天数必须是整数'}},
G2:G7:{min_value{required:true,msg:'请假天数不能小于1',map:{minValue:1}}},
G2:G7:{max_value{required:true,msg:'请假天数不能超过30',map:{maxValue:30}}}
}
]]>
</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.