Skip to content

Export "Customer Visit Record Ledger" to Excel with Java (Styled & Formatted Reports)

JQuick-ExcelStyled & Formatted Reports

Styled & Formatted ReportsScene 0052

Registers customer visit records, with the last row summarizing total visit duration, and customers in "To Follow Up" status marked in red. Implemented declaratively in pure XML — no Java business code required.

Download the Excel fileView raw XML configBack to all demos

Customer Visit Record Ledger — Styled & Formatted Reports
Full screenshot of the exported xlsx

About this demo

This demo exports the "Customer Visit Record Ledger" workbook: 1 data sheet(s); MAPPING over 7 columns (拜访日期, 客户名称, 拜访人, 拜访方式, 拜访时长(h), 客户等级, 跟进状态), 2 formula(s), 1 style rule(s). On the Java side it builds 7 data rows and calls exportCustomerVisitRecord() 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 (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 styles, Java Excel header style zebra rows, Apache POI CellStyle export, Java Excel conditional formatting, export Customer Visit Record Ledger to Excel with Java

Output specs

Scene no.
0052
Group
Styled & Formatted Reports
Config lines
32
Source lines
75

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

    private static final String XML = "jquick/biz/style/0052_style_customer-visit-record.xml";

    /** 导出:纯 XML 完成拜访时长汇总、合计行高亮与待跟进标红。 */
    @Test
    public void exportCustomerVisitRecord() throws Exception {
        List<JQuickRow> rows = new ArrayList<>();
        rows.add(visit(date(2026, 3, 1), "恒信商贸", "张伟", "上门", 1.5, "A", "已成交"));
        rows.add(visit(date(2026, 3, 3), "华越集团", "张伟", "电话", 0.5, "B", "跟进中"));
        rows.add(visit(date(2026, 3, 5), "广发物流", "李娜", "上门", 2.0, "A", "已成交"));
        rows.add(visit(date(2026, 3, 8), "中远建材", "李娜", "视频", 1.0, "C", "待跟进"));
        rows.add(visit(date(2026, 3, 12), "蓝天科技", "王强", "上门", 1.5, "B", "跟进中"));
        rows.add(visit(date(2026, 3, 15), "星辰电子", "王强", "电话", 0.5, "C", "待跟进"));
        // 合计占位行:拜访总时长留给 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/0052_style_customer-visit-record.xlsx");
        try (OutputStream os = new FileOutputStream(out)) {
            JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("indigo", rows, os);
            JQuickFactory factory = new JQuickXmlFactory(parser, XML);
            Style0052CustomerVisitRecordService service = factory.createApi(Style0052CustomerVisitRecordService.class);
            service.exportCustomerVisitRecord("field", "value");
        }

    }

    /** 构造一条拜访记录(a=日期,b=客户,c=拜访人,d=方式,e=时长,f=等级,g=状态)。 */
    private static JQuickRow visit(Date visitDate, String customer, String visitor, String visitType,
                                   double visitHours, String customerLevel, String followStatus) {
        JQuickRow row = new JQuickRow();
        row.put("a", visitDate);
        row.put("b", customer);
        row.put("c", visitor);
        row.put("d", visitType);
        row.put("e", visitHours);
        row.put("f", customerLevel);
        row.put("g", followStatus);
        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("indigo", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Style0052CustomerVisitRecordService service = factory.createApi(Style0052CustomerVisitRecordService.class);

XML config · 0052_style_customer-visit-record.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.Style0052CustomerVisitRecordService">

    <!-- 导出:客户拜访记录台账 -->
    <excel name="exportCustomerVisitRecord" returnClass="void">
        <![CDATA[
            EXPORT WITH SHEET="客户拜访记录台账", HEADER=true,
                MAPPING={"a":"拜访日期","b":"客户名称","c":"拜访人","d":"拜访方式","e":"拜访时长(h)","f":"客户等级","g":"跟进状态"},
                FORMAT={"a":"yyyy-MM-dd","e":"#,##0.0"},
                FORMULAS={
                    E8:'SUM(E2:E7)'
                },
                STYLE={
                    ROW 8:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center},
                    G5:{color:red,bold:true},
                    G7:{color:red,bold:true}
                }
        ]]>
    </excel>

    <!-- 导入解析:读取导出的客户拜访记录台账 -->
    <excel name="importCustomerVisitRecord" returnClass="java.util.List">
        <![CDATA[
            IMPORT WITH SHEET="客户拜访记录台账", HEADER=true,
                MAPPING={"拜访日期":"visitDate","客户名称":"customer","拜访人":"visitor","拜访方式":"visitType","拜访时长(h)":"visitHours","客户等级":"customerLevel","跟进状态":"followStatus"}
        ]]>
    </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.