Skip to content

Export "Customer Complaint Handling Ledger" to Excel with Java (Formula & Calculated Reports)

JQuick-ExcelFormula & Calculated Reports

Formula & Calculated ReportsScene 0058

Registers customer complaint tickets, with the last row giving the average handling days and the handling days of overdue complaints marked in red. Implemented declaratively in pure XML — no Java business code required.

Download the Excel fileView raw XML configBack to all demos

Customer Complaint Handling Ledger — Formula & Calculated Reports
Full screenshot of the exported xlsx

About this demo

This demo exports the "Customer Complaint Handling Ledger" workbook: 1 data sheet(s); MAPPING over 7 columns (投诉单号, 客户, 投诉类型, 受理日期, 处理时限(天), 实际处理天数, 是否超期), 2 formula(s), 1 style rule(s). On the Java side it builds 7 data rows and calls exportCustomerComplaintLedger() 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 (75 lines, runnable as-is)
  • The complete XML config (32 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 Customer Complaint Handling Ledger to Excel with Java

Output specs

Scene no.
0058
Group
Formula & Calculated Reports
Config lines
32
Source lines
75

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

    private static final String XML = "jquick/biz/formulas/0058_formulas_customer-complaint-ledger.xml";

    /** 导出:纯 XML 完成平均处理天数汇总、合计行高亮与超期标红。 */
    @Test
    public void exportCustomerComplaintLedger() throws Exception {
        List<JQuickRow> rows = new ArrayList<>();
        rows.add(complaint("TS2601", "恒信商贸", "物流延迟", date(2026, 3, 1), 3, 2.0, "否"));
        rows.add(complaint("TS2602", "华越集团", "质量异议", date(2026, 3, 2), 5, 3.0, "否"));
        rows.add(complaint("TS2603", "广发物流", "服务态度", date(2026, 3, 4), 2, 4.0, "是"));
        rows.add(complaint("TS2604", "中远建材", "交付延期", date(2026, 3, 6), 4, 3.0, "否"));
        rows.add(complaint("TS2605", "蓝天科技", "质量异议", date(2026, 3, 8), 5, 5.0, "否"));
        rows.add(complaint("TS2606", "星辰电子", "物流延迟", date(2026, 3, 10), 3, 6.0, "是"));
        // 合计占位行:平均处理天数留给 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/0058_formulas_customer-complaint-ledger.xlsx");
        try (OutputStream os = new FileOutputStream(out)) {
            JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("pearl", rows, os);
            JQuickFactory factory = new JQuickXmlFactory(parser, XML);
            Formulas0058CustomerComplaintLedgerService service = factory.createApi(Formulas0058CustomerComplaintLedgerService.class);
            service.exportCustomerComplaintLedger("field", "value");
        }

    }

    /** 构造一条投诉记录(a=单号,b=客户,c=类型,d=受理日期,e=时限,f=处理天数,g=是否超期)。 */
    private static JQuickRow complaint(String complaintNo, String customer, String complaintType,
                                       Date acceptDate, int timeLimit, double actualDays, String overdue) {
        JQuickRow row = new JQuickRow();
        row.put("a", complaintNo);
        row.put("b", customer);
        row.put("c", complaintType);
        row.put("d", acceptDate);
        row.put("e", timeLimit);
        row.put("f", actualDays);
        row.put("g", overdue);
        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("pearl", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Formulas0058CustomerComplaintLedgerService service = factory.createApi(Formulas0058CustomerComplaintLedgerService.class);

XML config · 0058_formulas_customer-complaint-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.Formulas0058CustomerComplaintLedgerService">

    <!-- 导出:客户投诉处理台账 -->
    <excel name="exportCustomerComplaintLedger" returnClass="void">
        <![CDATA[
            EXPORT WITH SHEET="客户投诉处理台账", HEADER=true,
                MAPPING={"a":"投诉单号","b":"客户","c":"投诉类型","d":"受理日期","e":"处理时限(天)","f":"实际处理天数","g":"是否超期"},
                FORMAT={"d":"yyyy-MM-dd","e":"0","f":"0.0"},
                FORMULAS={
                    F8:'AVERAGE(F2:F7)'
                },
                STYLE={
                    ROW 8:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center},
                    F4:{color:red,bold:true},
                    F7:{color:red,bold:true}
                }
        ]]>
    </excel>

    <!-- 导入解析:读取导出的客户投诉处理台账 -->
    <excel name="importCustomerComplaintLedger" returnClass="java.util.List">
        <![CDATA[
            IMPORT WITH SHEET="客户投诉处理台账", HEADER=true,
                MAPPING={"投诉单号":"complaintNo","客户":"customer","投诉类型":"complaintType","受理日期":"acceptDate","处理时限(天)":"timeLimit","实际处理天数":"actualDays","是否超期":"overdue"}
        ]]>
    </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.