Skip to content

Export "Accounts Receivable Aging Ledger" to Excel with Java (Styled & Formatted Reports)

JQuick-ExcelStyled & Formatted Reports

Styled & Formatted ReportsScene 0016

Records receivables, receipts, outstanding balance and aging days per customer, computing Outstanding Balance = Receivable - Received and the outstanding share per row, with a total row at the end; cells of abnormal customers whose aging is excessive are marked in red font to flag priority collection. Implemented declaratively in pure XML — no Java business code required.

Download the Excel fileView raw XML configBack to all demos

Accounts Receivable Aging Ledger — Styled & Formatted Reports
Full screenshot of the exported xlsx

About this demo

This demo exports the "Accounts Receivable Aging Ledger" workbook: 1 data sheet(s); MAPPING over 6 columns (客户名称, 应收金额, 已收金额, 未收余额, 账龄(天), 未收占比), 16 formula(s), 1 style rule(s). On the Java side it builds 6 data rows and calls exportArAgingLedger() 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 (62 lines, runnable as-is)
  • The complete XML config (34 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 Accounts Receivable Aging Ledger to Excel with Java

Output specs

Scene no.
0016
Group
Styled & Formatted Reports
Config lines
34
Source lines
62

Java source · Style0016ArAgingLedgerDemo.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.List;

public class Style0016ArAgingLedgerDemo {

    private static final String XML = "jquick/biz/style/0016_style_ar-aging-ledger.xml";

    /** 导出:纯 XML 完成未收余额、占比、合计与异常标红。 */
    @Test
    public void exportArAgingLedger() throws Exception {
        List<JQuickRow> rows = new ArrayList<>();
        rows.add(customer("华东电子", 500000, 300000, 45));
        rows.add(customer("南方机械", 320000, 320000, 10));
        rows.add(customer("西部建设", 280000, 100000, 75));
        rows.add(customer("北方物流", 150000, 150000, 5));
        // 第 6 行:账龄 120 天、未收 34 万,为异常客户,模板中 D6/E6 标红
        rows.add(customer("东尚科技", 420000, 80000, 120));
        // 合计占位行:金额与占比留给 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/style/0016_style_ar-aging-ledger.xlsx");
        try (OutputStream os = new FileOutputStream(out)) {
            JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("steelBlue", rows, os);
            JQuickFactory factory = new JQuickXmlFactory(parser, XML);
            Style0016ArAgingLedgerService service = factory.createApi(Style0016ArAgingLedgerService.class);
            service.exportArAgingLedger("field", "value");
        }

    }

    /** 构造一条客户应收明细(a=客户,b=应收,c=已收,e=账龄天数)。 */
    private static JQuickRow customer(String name, double receivable, double received, int agingDays) {
        JQuickRow row = new JQuickRow();
        row.put("a", name);
        row.put("b", receivable);
        row.put("c", received);
        row.put("d", null);
        row.put("e", agingDays);
        row.put("f", 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("steelBlue", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Style0016ArAgingLedgerService service = factory.createApi(Style0016ArAgingLedgerService.class);

XML config · 0016_style_ar-aging-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.Style0016ArAgingLedgerService">

    <!-- 导出:应收账款账龄台账 -->
    <excel name="exportArAgingLedger" returnClass="void">
        <![CDATA[
            EXPORT WITH SHEET="应收账款账龄台账", HEADER=true,
                MAPPING={"a":"客户名称","b":"应收金额","c":"已收金额","d":"未收余额","e":"账龄(天)","f":"未收占比"},
                FORMAT={"b":"#,##0.00","c":"#,##0.00","d":"#,##0.00","e":"0","f":"0.00%"},
                FORMULAS={
                    D2:'B2-C2',D3:'B3-C3',D4:'B4-C4',D5:'B5-C5',D6:'B6-C6',
                    F2:'D2/D7',F3:'D3/D7',F4:'D4/D7',F5:'D5/D7',F6:'D6/D7',
                    B7:'SUM(B2:B6)',C7:'SUM(C2:C6)',D7:'SUM(D2:D6)',F7:'SUM(F2:F6)'
                },
                STYLE={
                    ROW 7:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center},
                    D6:{color:red,bold:true},
                    E6:{color:red,bold:true}
                }
        ]]>
    </excel>

    <!-- 导入解析:读取导出的应收账款账龄台账 -->
    <excel name="importArAgingLedger" returnClass="java.util.List">
        <![CDATA[
            IMPORT WITH SHEET="应收账款账龄台账", HEADER=true,
                MAPPING={"客户名称":"customer","应收金额":"receivable","已收金额":"received","未收余额":"unpaid","账龄(天)":"agingDays","未收占比":"unpaidRate"}
        ]]>
    </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.