Export "Travel Allowance Disbursement Detail" to Excel with Java (Formula & Calculated Reports)
Formula & Calculated ReportsScene 0091
Registers the days and daily allowance standard for each business-trip record, computing Total Allowance = Trip Days × Daily Allowance Standard + Transportation Allowance, with the last row summarizing days, transportation allowance and total allowance. Implemented declaratively in pure XML — no Java business code required.

About this demo
This demo exports the "Travel Allowance Disbursement Detail" workbook: 1 data sheet(s); MAPPING over 7 columns (姓名, 部门, 出差地点, 出差天数, 日补贴标准, 交通补贴, 补贴合计), 11 formula(s), 1 style rule(s). On the Java side it builds 7 data rows and calls exportTravelAllowanceDetail() 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 (66 lines, runnable as-is)
- The complete XML config (30 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 Travel Allowance Disbursement Detail to Excel with Java
Output specs
- Scene no.
- 0091
- Group
- Formula & Calculated Reports
- Config lines
- 30
- Source lines
- 66
Java source · Formulas0091TravelAllowanceDetailDemo.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.List;
public class Formulas0091TravelAllowanceDetailDemo {
private static final String XML = "jquick/biz/formulas/0091_formulas_travel-allowance-detail.xml";
/** 导出:纯 XML 完成逐行补贴合计、各列汇总与合计行高亮。 */
@Test
public void exportTravelAllowanceDetail() throws Exception {
List<JQuickRow> rows = new ArrayList<>();
// g 留空,由 FORMULAS 计算
rows.add(record("张伟", "研发部", "北京", 5, 300.00, 1500.00));
rows.add(record("李娜", "市场部", "上海", 4, 280.00, 1200.00));
rows.add(record("王强", "生产部", "广州", 6, 260.00, 1800.00));
rows.add(record("赵敏", "财务部", "深圳", 3, 300.00, 900.00));
rows.add(record("孙磊", "研发部", "杭州", 5, 280.00, 1500.00));
rows.add(record("周芳", "客服部", "成都", 4, 240.00, 1200.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/formulas/0091_formulas_travel-allowance-detail.xlsx");
try (OutputStream os = new FileOutputStream(out)) {
JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("champagne", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Formulas0091TravelAllowanceDetailService service = factory.createApi(Formulas0091TravelAllowanceDetailService.class);
service.exportTravelAllowanceDetail("field", "value");
}
}
/** 构造一条差旅记录(a=姓名,b=部门,c=地点,d=天数,e=日标准,f=交通补贴,g 留空)。 */
private static JQuickRow record(String employeeName, String department, String destination,
double travelDays, double dailyAllowance, double transportAllowance) {
JQuickRow row = new JQuickRow();
row.put("a", employeeName);
row.put("b", department);
row.put("c", destination);
row.put("d", travelDays);
row.put("e", dailyAllowance);
row.put("f", transportAllowance);
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);
Formulas0091TravelAllowanceDetailService service = factory.createApi(Formulas0091TravelAllowanceDetailService.class);XML config · 0091_formulas_travel-allowance-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.formulas.Formulas0091TravelAllowanceDetailService">
<!-- 导出:差旅补贴发放明细表 -->
<excel name="exportTravelAllowanceDetail" returnClass="void">
<![CDATA[
EXPORT WITH SHEET="差旅补贴发放明细表", HEADER=true,
MAPPING={"a":"姓名","b":"部门","c":"出差地点","d":"出差天数","e":"日补贴标准","f":"交通补贴","g":"补贴合计"},
FORMAT={"d":"0","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',G7:'D7*E7+F7',
D8:'SUM(D2:D7)',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="importTravelAllowanceDetail" returnClass="java.util.List">
<![CDATA[
IMPORT WITH SHEET="差旅补贴发放明细表", HEADER=true,
MAPPING={"姓名":"employeeName","部门":"department","出差地点":"destination","出差天数":"travelDays","日补贴标准":"dailyAllowance","交通补贴":"transportAllowance","补贴合计":"totalAllowance"}
]]>
</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.