Skip to content

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

JQuick-ExcelStyled & Formatted Reports

Styled & Formatted ReportsScene 0084

Splits receivables aging by customer (within 30 days / 31-60 days / over 61 days), computing Overdue Amount = 31-60 days + over 61 days and Overdue Share = Overdue Amount / Receivable Amount, with the last row summarizing each aging bucket and the overall overdue share; the customer with the highest overdue share is marked in red. Implemented declaratively in pure XML — no Java business code required.

Download the Excel fileView raw XML configBack to all demos

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

About this demo

This demo exports the "Accounts Receivable Aging Analysis" workbook: 1 data sheet(s); MAPPING over 7 columns (客户名称, 应收金额, 30天内, 31-60天, 61天以上, 逾期金额, 逾期占比), 20 formula(s), 1 style rule(s). On the Java side it builds 6 data rows and calls exportAccountsReceivableAging() 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 (65 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 Analysis to Excel with Java

Output specs

Scene no.
0084
Group
Styled & Formatted Reports
Config lines
34
Source lines
65

Java source · Style0084AccountsReceivableAgingDemo.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 Style0084AccountsReceivableAgingDemo {

    private static final String XML = "jquick/biz/style/0084_style_accounts-receivable-aging.xml";

    /** 导出:纯 XML 完成逐行逾期金额、占比、合计与最高占比标红。 */
    @Test
    public void exportAccountsReceivableAging() throws Exception {
        List<JQuickRow> rows = new ArrayList<>();
        // f/g 留空,由 FORMULAS 计算
        rows.add(customer("华宇集团", 500000.00, 400000.00, 60000.00, 40000.00));
        rows.add(customer("东方贸易", 320000.00, 320000.00, 0.00, 0.00));
        rows.add(customer("金泰实业", 280000.00, 180000.00, 50000.00, 50000.00));
        rows.add(customer("恒信科技", 150000.00, 150000.00, 0.00, 0.00));
        rows.add(customer("瑞丰商贸", 260000.00, 100000.00, 90000.00, 70000.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/style/0084_style_accounts-receivable-aging.xlsx");
        try (OutputStream os = new FileOutputStream(out)) {
            JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("turquoise", rows, os);
            JQuickFactory factory = new JQuickXmlFactory(parser, XML);
            Style0084AccountsReceivableAgingService service = factory.createApi(Style0084AccountsReceivableAgingService.class);
            service.exportAccountsReceivableAging("field", "value");
        }

    }

    /** 构造一个客户(a=客户名称,b=应收金额,c=30天内,d=31-60天,e=61天以上,f/g 留空)。 */
    private static JQuickRow customer(String customer, double receivableAmount, double within30,
                                      double days31to60, double over60) {
        JQuickRow row = new JQuickRow();
        row.put("a", customer);
        row.put("b", receivableAmount);
        row.put("c", within30);
        row.put("d", days31to60);
        row.put("e", over60);
        row.put("f", null);
        row.put("g", 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("turquoise", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Style0084AccountsReceivableAgingService service = factory.createApi(Style0084AccountsReceivableAgingService.class);

XML config · 0084_style_accounts-receivable-aging.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.Style0084AccountsReceivableAgingService">

    <!-- 导出:应收账款账龄分析表 -->
    <excel name="exportAccountsReceivableAging" returnClass="void">
        <![CDATA[
            EXPORT WITH SHEET="应收账款账龄分析表", HEADER=true,
                MAPPING={"a":"客户名称","b":"应收金额","c":"30天内","d":"31-60天","e":"61天以上","f":"逾期金额","g":"逾期占比"},
                FORMAT={"b":"#,##0.00","c":"#,##0.00","d":"#,##0.00","e":"#,##0.00","f":"#,##0.00","g":"0.00%"},
                FORMULAS={
                    F2:'D2+E2',G2:'F2/B2',F3:'D3+E3',G3:'F3/B3',F4:'D4+E4',G4:'F4/B4',
                    F5:'D5+E5',G5:'F5/B5',F6:'D6+E6',G6:'F6/B6',
                    B7:'SUM(B2:B6)',C7:'SUM(C2:C6)',D7:'SUM(D2:D6)',E7:'SUM(E2:E6)',
                    F7:'D7+E7',G7:'F7/B7'
                },
                STYLE={
                    ROW 7:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center},
                    G6:{color:red,bold:true}
                }
        ]]>
    </excel>

    <!-- 导入解析:读取导出的应收账款账龄分析表 -->
    <excel name="importAccountsReceivableAging" returnClass="java.util.List">
        <![CDATA[
            IMPORT WITH SHEET="应收账款账龄分析表", HEADER=true,
                MAPPING={"客户名称":"customer","应收金额":"receivableAmount","30天内":"within30","31-60天":"days31to60","61天以上":"over60","逾期金额":"overdueAmount","逾期占比":"overdueRatio"}
        ]]>
    </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.