Export "Bill Registration Ledger" to Excel with Java (Formula & Calculated Reports)
Formula & Calculated ReportsScene 0023
Registers notes receivable / payable held by the company, computing Bill Term (in days) = Maturity Date - Issue Date per row, with a summary of the face amount in the last row. Implemented declaratively in pure XML — no Java business code required.

About this demo
This demo exports the "Bill Registration Ledger" workbook: 1 data sheet(s); MAPPING over 6 columns (票据号码, 出票日期, 到期日期, 票面金额, 票据期限(天), 票据类型), 7 formula(s), 1 style rule(s). On the Java side it builds 6 data rows and calls exportBillRegister() 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 (71 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 Bill Registration Ledger to Excel with Java
Output specs
- Scene no.
- 0023
- Group
- Formula & Calculated Reports
- Config lines
- 29
- Source lines
- 71
Java source · Formulas0023BillRegisterLedgerDemo.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 Formulas0023BillRegisterLedgerDemo {
private static final String XML = "jquick/biz/formulas/0023_formulas_bill-register-ledger.xml";
/** 导出:纯 XML 完成票据期限计算与票面金额合计。 */
@Test
public void exportBillRegister() throws Exception {
List<JQuickRow> rows = new ArrayList<>();
rows.add(bill("BIL2026001", date(2026, 1, 5), date(2026, 4, 5), 100000, "银行承兑"));
rows.add(bill("BIL2026002", date(2026, 2, 1), date(2026, 5, 1), 150000, "银行承兑"));
rows.add(bill("BIL2026003", date(2026, 3, 10), date(2026, 6, 10), 80000, "商业承兑"));
rows.add(bill("BIL2026004", date(2026, 4, 1), date(2026, 7, 1), 120000, "银行承兑"));
rows.add(bill("BIL2026005", date(2026, 5, 15), date(2026, 8, 15), 60000, "商业承兑"));
// 合计占位行:票面金额留给 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);
rows.add(total);
File out = new File("D:/test/excel/biz/formulas/0023_formulas_bill-register-ledger.xlsx");
try (OutputStream os = new FileOutputStream(out)) {
JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("crimsonRed", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Formulas0023BillRegisterLedgerService service = factory.createApi(Formulas0023BillRegisterLedgerService.class);
service.exportBillRegister("field", "value");
}
}
/** 构造一条票据明细(a=票据号,b=出票日期,c=到期日期,d=票面金额,f=票据类型)。 */
private static JQuickRow bill(String no, Date issueDate, Date dueDate, double faceValue, String type) {
JQuickRow row = new JQuickRow();
row.put("a", no);
row.put("b", issueDate);
row.put("c", dueDate);
row.put("d", faceValue);
row.put("e", null);
row.put("f", type);
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("crimsonRed", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Formulas0023BillRegisterLedgerService service = factory.createApi(Formulas0023BillRegisterLedgerService.class);XML config · 0023_formulas_bill-register-ledger.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.Formulas0023BillRegisterLedgerService">
<!-- 导出:票据登记台账 -->
<excel name="exportBillRegister" returnClass="void">
<![CDATA[
EXPORT WITH SHEET="票据登记台账", HEADER=true,
MAPPING={"a":"票据号码","b":"出票日期","c":"到期日期","d":"票面金额","e":"票据期限(天)","f":"票据类型"},
FORMAT={"b":"yyyy-MM-dd","c":"yyyy-MM-dd","d":"#,##0.00","e":"0"},
FORMULAS={
E2:'C2-B2',E3:'C3-B3',E4:'C4-B4',E5:'C5-B5',E6:'C6-B6',
D7:'SUM(D2:D6)'
},
STYLE={ROW 7:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center}}
]]>
</excel>
<!-- 导入解析:读取导出的票据登记台账 -->
<excel name="importBillRegister" returnClass="java.util.List">
<![CDATA[
IMPORT WITH SHEET="票据登记台账", HEADER=true,
MAPPING={"票据号码":"billNo","出票日期":"issueDate","到期日期":"dueDate","票面金额":"faceValue","票据期限(天)":"termDays","票据类型":"billType"}
]]>
</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.