Export "Travel Expense Reimbursement Detail" to Excel with Java (Formula & Calculated Reports)
Formula & Calculated ReportsScene 0030
After a business trip, employees register transportation, accommodation and allowance per itinerary leg, computing Subtotal = Transportation + Accommodation + Allowance per row, with the last row summarizing each expense item and the total reimbursement. Implemented declaratively in pure XML — no Java business code required.

About this demo
This demo exports the "Travel Expense Reimbursement Detail" workbook: 1 data sheet(s); MAPPING over 8 columns (出差人, 出差事由, 出发日期, 返回日期, 交通费, 住宿费, 补贴, 小计), 12 formula(s), 1 style rule(s). On the Java side it builds 6 data rows and calls exportTravelExpense() 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 (75 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 Travel Expense Reimbursement Detail to Excel with Java
Output specs
- Scene no.
- 0030
- Group
- Formula & Calculated Reports
- Config lines
- 29
- Source lines
- 75
Java source · Formulas0030TravelExpenseDetailDemo.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 Formulas0030TravelExpenseDetailDemo {
private static final String XML = "jquick/biz/formulas/0030_formulas_travel-expense-detail.xml";
/** 导出:纯 XML 完成逐行小计与合计行汇总。 */
@Test
public void exportTravelExpense() throws Exception {
List<JQuickRow> rows = new ArrayList<>();
rows.add(trip("张伟", "客户拜访", date(2026, 3, 2), date(2026, 3, 5), 1200, 800, 450));
rows.add(trip("李娜", "展会参展", date(2026, 3, 8), date(2026, 3, 11), 2200, 1600, 600));
rows.add(trip("王强", "供应商审核", date(2026, 3, 10), date(2026, 3, 12), 900, 600, 300));
rows.add(trip("赵敏", "技术交流", date(2026, 3, 15), date(2026, 3, 18), 1800, 1200, 500));
rows.add(trip("陈刚", "项目验收", date(2026, 3, 20), date(2026, 3, 22), 700, 400, 200));
// 合计占位行:各费用项与小计留给 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/0030_formulas_travel-expense-detail.xlsx");
try (OutputStream os = new FileOutputStream(out)) {
JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("tropicalTeal", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Formulas0030TravelExpenseDetailService service = factory.createApi(Formulas0030TravelExpenseDetailService.class);
service.exportTravelExpense("field", "value");
}
}
/** 构造一条出差行程(a=出差人,b=事由,c=出发,d=返回,e=交通费,f=住宿费,g=补贴)。 */
private static JQuickRow trip(String traveler, String reason, Date start, Date end, double transport, double hotel, double allowance) {
JQuickRow row = new JQuickRow();
row.put("a", traveler);
row.put("b", reason);
row.put("c", start);
row.put("d", end);
row.put("e", transport);
row.put("f", hotel);
row.put("g", allowance);
row.put("h", 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("tropicalTeal", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Formulas0030TravelExpenseDetailService service = factory.createApi(Formulas0030TravelExpenseDetailService.class);XML config · 0030_formulas_travel-expense-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.Formulas0030TravelExpenseDetailService">
<!-- 导出:差旅费报销明细单 -->
<excel name="exportTravelExpense" returnClass="void">
<![CDATA[
EXPORT WITH SHEET="差旅费用报销明细", HEADER=true,
MAPPING={"a":"出差人","b":"出差事由","c":"出发日期","d":"返回日期","e":"交通费","f":"住宿费","g":"补贴","h":"小计"},
FORMAT={"c":"yyyy-MM-dd","d":"yyyy-MM-dd","e":"#,##0.00","f":"#,##0.00","g":"#,##0.00","h":"#,##0.00"},
FORMULAS={
H2:'E2+F2+G2',H3:'E3+F3+G3',H4:'E4+F4+G4',H5:'E5+F5+G5',H6:'E6+F6+G6',
E7:'SUM(E2:E6)',F7:'SUM(F2:F6)',G7:'SUM(G2:G6)',H7:'SUM(H2:H6)'
},
STYLE={ROW 7:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center}}
]]>
</excel>
<!-- 导入解析:读取导出的差旅费报销明细单 -->
<excel name="importTravelExpense" returnClass="java.util.List">
<![CDATA[
IMPORT WITH SHEET="差旅费用报销明细", HEADER=true,
MAPPING={"出差人":"traveler","出差事由":"reason","出发日期":"startDate","返回日期":"endDate","交通费":"transportFee","住宿费":"hotelFee","补贴":"allowance","小计":"subtotal"}
]]>
</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.