Export "Customer Contact Masking Ledger" to Excel with Java (Data Transformation)
Data TransformationScene 0102
On export of the customer ledger, the contact's name is masked (keeping the first character), and the customer level is converted from an internal code into a customer segment via a dictionary. Implemented declaratively in pure XML — no Java business code required.

About this demo
This demo exports the "Customer Contact Masking Ledger" workbook: 1 data sheet(s); MAPPING over 7 columns (客户编码, 客户名称, 联系人, 电话, 客户等级, 年金额, 签约日期). On the Java side it builds 4 data rows and calls exportCustomerContactMasking() once — everything else is driven by the config.
It belongs to the "Data Transformation" group: TRANSFORM field conversion: code-value mapping, date formatting and masking applied during export.
What you can copy from this page
- The complete Java test class (64 lines, runnable as-is)
- The complete XML config (25 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 data transform, Java Excel code value mapping, Java Excel date formatting export, export Customer Contact Masking Ledger to Excel with Java
Output specs
- Scene no.
- 0102
- Group
- Data Transformation
- Config lines
- 25
- Source lines
- 64
Java source · Transform0102CustomerContactMaskingDemo.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.transform;
import com.github.paohaijiao.param.JContext;
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.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Transform0102CustomerContactMaskingDemo {
private static final String XML = "jquick/biz/transform/0102_transform_customer-contact-masking.xml";
/** 导出:联系人经 SPI maskname 脱敏、等级经字典转中文,回读校验两列。 */
@Test
public void exportCustomerContactMasking() throws Exception {
JContext ctx = new JContext();
Map<String, Object> dict = new HashMap<>();
dict.put("v1", "钻石客户");
dict.put("v2", "黄金客户");
dict.put("v3", "普通客户");
ctx.put("dict", dict);
List<JQuickRow> rows = new ArrayList<>();
rows.add(customer("C2601", "华东贸易有限公司", "张伟", "13800138001", "v1", 1250000.00, "2020-01-10"));
rows.add(customer("C2602", "南方物流集团", "李娜", "13900139002", "v2", 880000.00, "2020-05-22"));
rows.add(customer("C2603", "西部能源股份", "王强", "13700137003", "v3", 320000.00, "2021-03-08"));
rows.add(customer("C2604", "北方建设集团", "刘洋", "13600136004", "v1", 1560000.00, "2019-11-16"));
File out = new File("D:/test/excel/biz/transform/0102_transform_customer-contact-masking.xlsx");
try (OutputStream os = new FileOutputStream(out)) {
JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("sakuraPink", ctx, rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Transform0102CustomerContactMaskingService service = factory.createApi(Transform0102CustomerContactMaskingService.class);
service.exportCustomerContactMasking("field", "value");
}
}
/** 构造一条客户台账(c 走 SPI 脱敏、e 走字典,g 为日期对象走 FORMAT)。 */
private static JQuickRow customer(String no, String name, String contact, String phone,
String level, double annualAmount, String signDate) throws Exception {
JQuickRow row = new JQuickRow();
row.put("a", no);
row.put("b", name);
row.put("c", contact);
row.put("d", phone);
row.put("e", level);
row.put("f", annualAmount);
row.put("g", new SimpleDateFormat("yyyy-MM-dd").parse(signDate));
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("sakuraPink", ctx, rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Transform0102CustomerContactMaskingService service = factory.createApi(Transform0102CustomerContactMaskingService.class);XML config · 0102_transform_customer-contact-masking.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.transform.Transform0102CustomerContactMaskingService">
<!-- 导出:联系人脱敏 + 客户等级码值转义 -->
<excel name="exportCustomerContactMasking" returnClass="void">
<![CDATA[
EXPORT WITH SHEET="客户联系人脱敏台账", HEADER=true,
MAPPING={"a":"客户编码","b":"客户名称","c":"联系人","d":"电话","e":"客户等级","f":"年金额","g":"签约日期"},
FORMAT={"f":"#,##0.00","g":"yyyy-MM-dd"},
TRANSFORM={"c":maskname(${c}),"e":trans(${dict},${e})}
]]>
</excel>
<!-- 导入解析:读取脱敏后的客户台账 -->
<excel name="importCustomerContactMasking" returnClass="java.util.List">
<![CDATA[
IMPORT WITH SHEET="客户联系人脱敏台账", HEADER=true,
MAPPING={"客户编码":"customerNo","客户名称":"customerName","联系人":"contact","电话":"phone","客户等级":"level","年金额":"annualAmount","签约日期":"signDate"}
]]>
</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.