Skip to content

Export "Bank Acceptance Bill Ledger" to Excel with Java (Styled & Formatted Reports)

JQuick-ExcelStyled & Formatted Reports

Styled & Formatted ReportsScene 0048

Registers bank acceptance bills held by the company, using SUM in the last row to total the face amount, with the remaining days of overdue bills marked in red. Implemented declaratively in pure XML — no Java business code required.

Download the Excel fileView raw XML configBack to all demos

Bank Acceptance Bill Ledger — Styled & Formatted Reports
Full screenshot of the exported xlsx

About this demo

This demo exports the "Bank Acceptance Bill Ledger" workbook: 1 data sheet(s); MAPPING over 8 columns (汇票号, 出票人, 承兑银行, 票面金额, 出票日, 到期日, 剩余天数, 票据状态), 2 formula(s), 1 style rule(s). On the Java side it builds 6 data rows and calls exportBankAcceptanceLedger() 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 (76 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 styles, Java Excel header style zebra rows, Apache POI CellStyle export, Java Excel conditional formatting, export Bank Acceptance Bill Ledger to Excel with Java

Output specs

Scene no.
0048
Group
Styled & Formatted Reports
Config lines
31
Source lines
76

Java source · Style0048BankAcceptanceLedgerDemo.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.Calendar;
import java.util.Date;
import java.util.List;

public class Style0048BankAcceptanceLedgerDemo {

    private static final String XML = "jquick/biz/style/0048_style_bank-acceptance-ledger.xml";

    /** 导出:纯 XML 完成票面金额合计、合计行高亮与逾期剩余天数标红。 */
    @Test
    public void exportBankAcceptanceLedger() throws Exception {
        List<JQuickRow> rows = new ArrayList<>();
        rows.add(bill("BA2601", "恒信商贸", "工商银行", 500000.00, date(2025, 12, 1), date(2026, 6, 1), 245, "正常"));
        rows.add(bill("BA2602", "华越集团", "建设银行", 320000.00, date(2026, 1, 15), date(2026, 7, 15), 150, "正常"));
        rows.add(bill("BA2603", "广发物流", "中国银行", 180000.00, date(2025, 6, 20), date(2026, 1, 10), -12, "逾期"));
        rows.add(bill("BA2604", "中远建材", "农业银行", 260000.00, date(2026, 2, 1), date(2026, 8, 1), 210, "正常"));
        rows.add(bill("BA2605", "蓝天科技", "交通银行", 150000.00, date(2026, 3, 10), date(2026, 9, 10), 280, "正常"));
        // 合计占位行:票面金额合计留给 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/style/0048_style_bank-acceptance-ledger.xlsx");
        try (OutputStream os = new FileOutputStream(out)) {
            JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("wineRed", rows, os);
            JQuickFactory factory = new JQuickXmlFactory(parser, XML);
            Style0048BankAcceptanceLedgerService service = factory.createApi(Style0048BankAcceptanceLedgerService.class);
            service.exportBankAcceptanceLedger("field", "value");
        }

    }

    /** 构造一张汇票(a=汇票号,b=出票人,c=承兑银行,d=票面金额,e=出票日,f=到期日,g=剩余天数,h=状态)。 */
    private static JQuickRow bill(String billNo, String drawer, String acceptorBank, double faceAmount,
                                  Date issueDate, Date maturityDate, int remainingDays, String billStatus) {
        JQuickRow row = new JQuickRow();
        row.put("a", billNo);
        row.put("b", drawer);
        row.put("c", acceptorBank);
        row.put("d", faceAmount);
        row.put("e", issueDate);
        row.put("f", maturityDate);
        row.put("g", remainingDays);
        row.put("h", billStatus);
        return row;
    }

    /** 构造日期(月份按自然月 1-12 传入)。 */
    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("wineRed", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Style0048BankAcceptanceLedgerService service = factory.createApi(Style0048BankAcceptanceLedgerService.class);

XML config · 0048_style_bank-acceptance-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.style.Style0048BankAcceptanceLedgerService">

    <!-- 导出:银行承兑汇票台账 -->
    <excel name="exportBankAcceptanceLedger" returnClass="void">
        <![CDATA[
            EXPORT WITH SHEET="银行承兑汇票台账", HEADER=true,
                MAPPING={"a":"汇票号","b":"出票人","c":"承兑银行","d":"票面金额","e":"出票日","f":"到期日","g":"剩余天数","h":"票据状态"},
                FORMAT={"d":"#,##0.00","e":"yyyy-MM-dd","f":"yyyy-MM-dd","g":"0"},
                FORMULAS={
                    D7:'SUM(D2:D6)'
                },
                STYLE={
                    ROW 7:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center},
                    G4:{color:red,bold:true}
                }
        ]]>
    </excel>

    <!-- 导入解析:读取导出的银行承兑汇票台账 -->
    <excel name="importBankAcceptanceLedger" returnClass="java.util.List">
        <![CDATA[
            IMPORT WITH SHEET="银行承兑汇票台账", HEADER=true,
                MAPPING={"汇票号":"billNo","出票人":"drawer","承兑银行":"acceptorBank","票面金额":"faceAmount","出票日":"issueDate","到期日":"maturityDate","剩余天数":"remainingDays","票据状态":"billStatus"}
        ]]>
    </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.