Skip to content

Export "Customer Profile Supplement Submission Form" to Excel with Java (Data Validation)

JQuick-ExcelData Validation

Data ValidationScene 0067

Summarizes supplemented customer profiles (code / name / type / credit rating / contact / phone / annual purchase amount / status), with the last row totaling the annual purchase amount; submitted content is rule-validated on import. Implemented declaratively in pure XML — no Java business code required.

Download the Excel fileView raw XML configBack to all demos

Customer Profile Supplement Submission Form — Data Validation
Full screenshot of the exported xlsx

About this demo

This demo exports the "Customer Profile Supplement Submission Form" workbook: 1 data sheet(s); MAPPING over 8 columns (客户编号, 客户名称, 客户类型, 信用等级, 联系人, 联系电话, 年采购额, 建档状态), 2 formula(s), 1 style rule(s). On the Java side it builds 7 data rows and calls exportCustomerProfileFiling() once — everything else is driven by the config.

It belongs to the "Data Validation" group: VALIDATION form validation: an input template is exported and every field is validated when it is imported back.

What you can copy from this page

  • The complete Java test class (68 lines, runnable as-is)
  • The complete XML config (37 lines: mapping, formulas, styles, charts and every other rule)
  • The exported xlsx file (real output, comparable with the preview above)

Related searches: Java Excel export validation, Java validate imported Excel, Java Excel form template validation, export Customer Profile Supplement Submission Form to Excel with Java

Output specs

Scene no.
0067
Group
Data Validation
Config lines
37
Source lines
68

Java source · Validation0067CustomerProfileFilingDemo.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.validation;

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 Validation0067CustomerProfileFilingDemo {

    private static final String XML = "jquick/biz/validation/0067_validation_customer-profile-filing.xml";

    /** 导出:纯 XML 完成年采购额汇总与合计行高亮。 */
    @Test
    public void exportCustomerProfileFiling() throws Exception {
        List<JQuickRow> rows = new ArrayList<>();
        rows.add(customer("C2601", "华新电子有限公司", "企业客户", "AAA", "张明", "13800138001", 1200000, "已建档"));
        rows.add(customer("C2602", "恒通材料有限公司", "企业客户", "AA", "李强", "13900139002", 860000, "已建档"));
        rows.add(customer("C2603", "佳美包装有限公司", "企业客户", "A", "王芳", "13700137003", 540000, "已建档"));
        rows.add(customer("C2604", "个人客户赵敏", "个人客户", "A", "赵敏", "13600136004", 120000, "已建档"));
        rows.add(customer("C2605", "个人客户陈杰", "个人客户", "B", "陈杰", "13500135005", 60000, "已建档"));
        rows.add(customer("C2606", "天海物流有限公司", "企业客户", "AA", "周涛", "13400134006", 720000, "待审核"));
        // 合计占位行:年采购额合计留给 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);
        total.put("h", null);
        rows.add(total);

        File out = new File("D:/test/excel/biz/validation/0067_validation_customer-profile-filing.xlsx");
        try (OutputStream os = new FileOutputStream(out)) {
            JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("tropicalTeal", rows, os);
            JQuickFactory factory = new JQuickXmlFactory(parser, XML);
            Validation0067CustomerProfileFilingService service = factory.createApi(Validation0067CustomerProfileFilingService.class);
            service.exportCustomerProfileFiling("field", "value");
        }

    }

    /** 构造一条客户补录(a=客户编号,b=客户名称,c=客户类型,d=信用等级,e=联系人,f=电话,g=年采购额,h=建档状态)。 */
    private static JQuickRow customer(String customerNo, String customerName, String customerType,
                                      String creditLevel, String contact, String phone,
                                      int annualAmount, String filingStatus) {
        JQuickRow row = new JQuickRow();
        row.put("a", customerNo);
        row.put("b", customerName);
        row.put("c", customerType);
        row.put("d", creditLevel);
        row.put("e", contact);
        row.put("f", phone);
        row.put("g", annualAmount);
        row.put("h", filingStatus);
        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("tropicalTeal", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Validation0067CustomerProfileFilingService service = factory.createApi(Validation0067CustomerProfileFilingService.class);

XML config · 0067_validation_customer-profile-filing.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.validation.Validation0067CustomerProfileFilingService">

    <!-- 导出:客户档案信息补录填报表 -->
    <excel name="exportCustomerProfileFiling" returnClass="void">
        <![CDATA[
            EXPORT WITH SHEET="客户档案信息补录填报表", HEADER=true,
                MAPPING={"a":"客户编号","b":"客户名称","c":"客户类型","d":"信用等级","e":"联系人","f":"联系电话","g":"年采购额","h":"建档状态"},
                FORMAT={"g":"0"},
                FORMULAS={G8:'SUM(G2:G7)'},
                STYLE={
                    ROW 8:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center}
                }
        ]]>
    </excel>

    <!-- 导入解析:读取补录结果并逐项校验(校验不通过时抛出异常,异常信息即规则 msg) -->
    <excel name="importCustomerProfileFiling" returnClass="java.util.List">
        <![CDATA[
            IMPORT WITH SHEET="客户档案信息补录填报表", HEADER=true,
                MAPPING={"客户编号":"customerNo","客户名称":"customerName","客户类型":"customerType","信用等级":"creditLevel","联系人":"contact","联系电话":"phone","年采购额":"annualAmount","建档状态":"filingStatus"},
                VALIDATION={
                    A2:A7:{min_length{required:true,msg:'客户编号至少4位',map:{minLength:4}}},
                    B2:B7:{min_length{required:true,msg:'客户名称至少2个字',map:{minLength:2}}},
                    C2:C7:{dict{required:true,msg:'客户类型必须是(企业客户/个人客户)',map:{'企业客户':'企业客户','个人客户':'个人客户'}}},
                    D2:D7:{dict{required:true,msg:'信用等级必须在(AAA/AA/A/B)内',map:{'AAA':'AAA','AA':'AA','A':'A','B':'B'}}},
                    F2:F7:{mobile{required:true,msg:'联系电话格式无效'}},
                    G2:G7:{integer{required:true,msg:'年采购额必须是整数'}},
                    G2:G7:{min_value{required:true,msg:'年采购额不能为负数',map:{minValue:0}}}
                }
        ]]>
    </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.