Export "Employee Payroll Disbursement Detail" to Excel with Java (Styled & Formatted Reports)
Styled & Formatted ReportsScene 0057
Registers gross salary, social insurance and housing fund, and personal income tax monthly, computing Net Salary = Gross - Social Insurance and Housing Fund - Income Tax per row, with the last row summarizing each column and the highest income-tax payer marked in red. Implemented declaratively in pure XML — no Java business code required.

About this demo
This demo exports the "Employee Payroll Disbursement Detail" workbook: 1 data sheet(s); MAPPING over 7 columns (工号, 姓名, 部门, 应发工资, 社保公积金, 个人所得税, 实发工资), 12 formula(s), 1 style rule(s). On the Java side it builds 6 data rows and calls exportSalaryPaymentDetail() once — everything else is driven by the config.
It belongs to the "Styled & Formatted Reports" group: STYLE and conditional formatting: themed headers, zebra striping, highlighted total rows and threshold-based colouring of abnormal cells.
What you can copy from this page
- The complete Java test class (64 lines, runnable as-is)
- The complete XML config (32 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 styles, Java Excel header style zebra rows, Apache POI CellStyle export, Java Excel conditional formatting, export Employee Payroll Disbursement Detail to Excel with Java
Output specs
- Scene no.
- 0057
- Group
- Styled & Formatted Reports
- Config lines
- 32
- Source lines
- 64
Java source · Style0057SalaryPaymentDetailDemo.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.style;
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.List;
public class Style0057SalaryPaymentDetailDemo {
private static final String XML = "jquick/biz/style/0057_style_salary-payment-detail.xml";
/** 导出:纯 XML 完成实发工资、各列合计与个税最高者标红。 */
@Test
public void exportSalaryPaymentDetail() throws Exception {
List<JQuickRow> rows = new ArrayList<>();
rows.add(staff("E2601", "张伟", "研发部", 22000.00, 3500.00, 1800.00));
rows.add(staff("E2602", "李娜", "市场部", 18000.00, 3000.00, 1200.00));
rows.add(staff("E2603", "王强", "生产部", 15000.00, 2600.00, 700.00));
rows.add(staff("E2604", "赵敏", "财务部", 26000.00, 3800.00, 2600.00));
rows.add(staff("E2605", "陈杰", "研发部", 20000.00, 3300.00, 1400.00));
// 合计占位行:各列合计与实发工资合计留给 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/style/0057_style_salary-payment-detail.xlsx");
try (OutputStream os = new FileOutputStream(out)) {
JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("champagne", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Style0057SalaryPaymentDetailService service = factory.createApi(Style0057SalaryPaymentDetailService.class);
service.exportSalaryPaymentDetail("field", "value");
}
}
/** 构造一条薪资明细(a=工号,b=姓名,c=部门,d=应发,e=社保,f=个税,g 留空由 FORMULAS 计算)。 */
private static JQuickRow staff(String employeeNo, String name, String department,
double grossPay, double socialSecurity, double incomeTax) {
JQuickRow row = new JQuickRow();
row.put("a", employeeNo);
row.put("b", name);
row.put("c", department);
row.put("d", grossPay);
row.put("e", socialSecurity);
row.put("f", incomeTax);
row.put("g", null);
return row;
}
}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("champagne", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Style0057SalaryPaymentDetailService service = factory.createApi(Style0057SalaryPaymentDetailService.class);XML config · 0057_style_salary-payment-detail.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.style.Style0057SalaryPaymentDetailService">
<!-- 导出:员工薪资发放明细 -->
<excel name="exportSalaryPaymentDetail" returnClass="void">
<![CDATA[
EXPORT WITH SHEET="员工薪资发放明细", HEADER=true,
MAPPING={"a":"工号","b":"姓名","c":"部门","d":"应发工资","e":"社保公积金","f":"个人所得税","g":"实发工资"},
FORMAT={"d":"#,##0.00","e":"#,##0.00","f":"#,##0.00","g":"#,##0.00"},
FORMULAS={
G2:'D2-E2-F2',G3:'D3-E3-F3',G4:'D4-E4-F4',G5:'D5-E5-F5',G6:'D6-E6-F6',
D7:'SUM(D2:D6)',E7:'SUM(E2:E6)',F7:'SUM(F2:F6)',G7:'D7-E7-F7'
},
STYLE={
ROW 7:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center},
F4:{color:red,bold:true}
}
]]>
</excel>
<!-- 导入解析:读取导出的员工薪资发放明细 -->
<excel name="importSalaryPaymentDetail" returnClass="java.util.List">
<![CDATA[
IMPORT WITH SHEET="员工薪资发放明细", HEADER=true,
MAPPING={"工号":"employeeNo","姓名":"name","部门":"department","应发工资":"grossPay","社保公积金":"socialSecurity","个人所得税":"incomeTax","实发工资":"netPay"}
]]>
</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.