Export "E-commerce Order Shipping Detail" to Excel with Java (Formula & Calculated Reports)
Formula & Calculated ReportsScene 0046
Registers product detail per order, computing Amount = Quantity × Unit Price per row, with the last row summarizing shipped quantity and order amount, suitable for direct overlay printing as a shipping note. Implemented declaratively in pure XML — no Java business code required.

About this demo
This demo exports the "E-commerce Order Shipping Detail" workbook: 1 data sheet(s); MAPPING over 7 columns (订单号, 商品名称, 数量, 单价, 金额, 收货人, 发货状态), 8 formula(s), 1 style rule(s). On the Java side it builds 6 data rows and calls exportOnlineOrderShipment() 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 (63 lines, runnable as-is)
- The complete XML config (31 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 E-commerce Order Shipping Detail to Excel with Java
Output specs
- Scene no.
- 0046
- Group
- Formula & Calculated Reports
- Config lines
- 31
- Source lines
- 63
Java source · Formulas0046OnlineOrderShipmentDemo.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 Formulas0046OnlineOrderShipmentDemo {
private static final String XML = "jquick/biz/formulas/0046_formulas_online-order-shipment.xml";
/** 导出:纯 XML 完成逐行金额与合计汇总。 */
@Test
public void exportOnlineOrderShipment() throws Exception {
List<JQuickRow> rows = new ArrayList<>();
rows.add(item("SO20260301", "无线鼠标", 2, 129.00, "张伟", "已发货"));
rows.add(item("SO20260302", "机械键盘", 1, 499.00, "李娜", "已发货"));
rows.add(item("SO20260303", "显示器", 2, 1299.00, "王强", "待发货"));
rows.add(item("SO20260304", "移动硬盘", 3, 359.00, "赵敏", "已发货"));
rows.add(item("SO20260305", "蓝牙耳机", 4, 199.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/0046_formulas_online-order-shipment.xlsx");
try (OutputStream os = new FileOutputStream(out)) {
JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("steelBlue", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Formulas0046OnlineOrderShipmentService service = factory.createApi(Formulas0046OnlineOrderShipmentService.class);
service.exportOnlineOrderShipment("field", "value");
}
}
/** 构造一条发货明细(a=订单号,b=商品,c=数量,d=单价,f=收货人,g=状态,e 留空)。 */
private static JQuickRow item(String orderNo, String productName, double quantity, double unitPrice, String receiver, String status) {
JQuickRow row = new JQuickRow();
row.put("a", orderNo);
row.put("b", productName);
row.put("c", quantity);
row.put("d", unitPrice);
row.put("e", null);
row.put("f", receiver);
row.put("g", status);
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("steelBlue", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Formulas0046OnlineOrderShipmentService service = factory.createApi(Formulas0046OnlineOrderShipmentService.class);XML config · 0046_formulas_online-order-shipment.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.Formulas0046OnlineOrderShipmentService">
<!-- 导出:电商订单发货明细 -->
<excel name="exportOnlineOrderShipment" returnClass="void">
<![CDATA[
EXPORT WITH SHEET="电商订单发货明细", HEADER=true,
MAPPING={"a":"订单号","b":"商品名称","c":"数量","d":"单价","e":"金额","f":"收货人","g":"发货状态"},
FORMAT={"c":"#,##0","d":"#,##0.00","e":"#,##0.00"},
FORMULAS={
E2:'C2*D2',E3:'C3*D3',E4:'C4*D4',E5:'C5*D5',E6:'C6*D6',
C7:'SUM(C2:C6)',E7:'SUM(E2:E6)'
},
STYLE={
ROW 7:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center}
}
]]>
</excel>
<!-- 导入解析:读取导出的电商订单发货明细 -->
<excel name="importOnlineOrderShipment" returnClass="java.util.List">
<![CDATA[
IMPORT WITH SHEET="电商订单发货明细", HEADER=true,
MAPPING={"订单号":"orderNo","商品名称":"productName","数量":"quantity","单价":"unitPrice","金额":"amount","收货人":"receiver","发货状态":"shipStatus"}
]]>
</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.