Skip to content

Export "Equipment Inspection Record Submission Form" to Excel with Java (Data Validation)

JQuick-ExcelData Validation

Data ValidationScene 0054

Registers the inspector and operating parameters for each piece of equipment, with the last row summarizing total operating hours; submitted content is rule-validated on import (ID / name length, operating hours as an integer and within range, temperature ceiling, conclusion dictionary). Implemented declaratively in pure XML — no Java business code required.

Download the Excel fileView raw XML configBack to all demos

Equipment Inspection Record Submission Form — Data Validation
Full screenshot of the exported xlsx

About this demo

This demo exports the "Equipment Inspection Record Submission Form" 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 exportEquipmentInspectionRecord() 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 (65 lines, runnable as-is)
  • The complete XML config (39 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 Equipment Inspection Record Submission Form to Excel with Java

Output specs

Scene no.
0054
Group
Data Validation
Config lines
39
Source lines
65

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

    private static final String XML = "jquick/biz/validation/0054_validation_equipment-inspection-record.xml";

    /** 导出:纯 XML 完成运行时长合计。 */
    @Test
    public void exportEquipmentInspectionRecord() throws Exception {
        List<JQuickRow> rows = new ArrayList<>();
        rows.add(equipment("EQ001", "注塑机", "张伟", 8, 62.5, "正常", ""));
        rows.add(equipment("EQ002", "空压机", "李娜", 12, 78.0, "正常", ""));
        rows.add(equipment("EQ003", "数控车床", "王强", 20, 55.5, "正常", ""));
        rows.add(equipment("EQ004", "磨床", "赵敏", 6, 48.0, "正常", ""));
        rows.add(equipment("EQ005", "铣床", "陈晨", 10, 52.0, "正常", ""));
        rows.add(equipment("EQ006", "钻床", "周涛", 4, 45.5, "正常", ""));
        // 合计占位行:运行时长合计留给 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/validation/0054_validation_equipment-inspection-record.xlsx");
        try (OutputStream os = new FileOutputStream(out)) {
            JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("crimsonRed", rows, os);
            JQuickFactory factory = new JQuickXmlFactory(parser, XML);
            Validation0054EquipmentInspectionRecordService service = factory.createApi(Validation0054EquipmentInspectionRecordService.class);
            service.exportEquipmentInspectionRecord("field", "value");
        }

    }

    /** 构造一条点检记录(a=编号,b=名称,c=点检人,d=运行时长,e=温度,f=结论,g=备注)。 */
    private static JQuickRow equipment(String code, String name, String inspector, double runningHours,
                                       double temperature, String inspectionResult, String remark) {
        JQuickRow row = new JQuickRow();
        row.put("a", code);
        row.put("b", name);
        row.put("c", inspector);
        row.put("d", runningHours);
        row.put("e", temperature);
        row.put("f", inspectionResult);
        row.put("g", remark);
        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("crimsonRed", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Validation0054EquipmentInspectionRecordService service = factory.createApi(Validation0054EquipmentInspectionRecordService.class);

XML config · 0054_validation_equipment-inspection-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.validation.Validation0054EquipmentInspectionRecordService">

    <!-- 导出:设备点检记录填报表 -->
    <excel name="exportEquipmentInspectionRecord" returnClass="void">
        <![CDATA[
            EXPORT WITH SHEET="设备点检记录填报表", HEADER=true,
                MAPPING={"a":"设备编号","b":"设备名称","c":"点检人","d":"运行时长","e":"温度","f":"点检结论","g":"备注"},
                FORMAT={"d":"0","e":"0.0"},
                FORMULAS={
                    D8:'SUM(D2:D7)'
                },
                STYLE={
                    ROW 8:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center}
                }
        ]]>
    </excel>

    <!-- 导入解析:读取并校验设备点检记录填报表 -->
    <excel name="importEquipmentInspectionRecord" returnClass="java.util.List">
        <![CDATA[
            IMPORT WITH SHEET="设备点检记录填报表", HEADER=true,
                MAPPING={"设备编号":"equipmentCode","设备名称":"equipmentName","点检人":"inspector","运行时长":"runningHours","温度":"temperature","点检结论":"inspectionResult","备注":"remark"},
                VALIDATION={
                    A2:A7:{min_length{required:true,msg:'设备编号至少3位',map:{minLength:3}}},
                    B2:B7:{min_length{required:true,msg:'设备名称至少2个字',map:{minLength:2}}},
                    D2:D7:{integer{required:true,msg:'运行时长必须是整数'}},
                    D2:D7:{min_value{required:true,msg:'运行时长不能小于1',map:{minValue:1}}},
                    D2:D7:{max_value{required:true,msg:'运行时长不能超过24',map:{maxValue:24}}},
                    E2:E7:{max_value{required:true,msg:'温度不能超过85',map:{maxValue:85}}},
                    F2:F7:{dict{required:true,msg:'点检结论必须在字典内',map:{'正常':'正常','异常':'异常'}}}
                }
        ]]>
    </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.