Skip to content

Export "Incoming Inspection Nonconformance Record" to Excel with Java (Styled & Formatted Reports)

JQuick-ExcelStyled & Formatted Reports

Styled & Formatted ReportsScene 0072

Registers submitted quantity and nonconforming quantity by incoming batch, computing Nonconformance Rate = Nonconforming Quantity / Submitted Quantity per row, with the last row giving the summary quantity and overall nonconformance rate; batches exceeding the nonconformance-rate limit are marked in red. Implemented declaratively in pure XML — no Java business code required.

Download the Excel fileView raw XML configBack to all demos

Incoming Inspection Nonconformance Record — Styled & Formatted Reports
Full screenshot of the exported xlsx

About this demo

This demo exports the "Incoming Inspection Nonconformance Record" workbook: 1 data sheet(s); MAPPING over 7 columns (批次号, 物料名称, 供应商, 送检数量, 不合格数量, 不合格率, 处理方式), 11 formula(s), 1 style rule(s). On the Java side it builds 7 data rows and calls exportIncomingInspectionDefect() 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 (66 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 Incoming Inspection Nonconformance Record to Excel with Java

Output specs

Scene no.
0072
Group
Styled & Formatted Reports
Config lines
32
Source lines
66

Java source · Style0072IncomingInspectionDefectDemo.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.List;

public class Style0072IncomingInspectionDefectDemo {

    private static final String XML = "jquick/biz/style/0072_style_incoming-inspection-defect.xml";

    /** 导出:纯 XML 完成不合格率、数量汇总与超标标红。 */
    @Test
    public void exportIncomingInspectionDefect() throws Exception {
        List<JQuickRow> rows = new ArrayList<>();
        // f=不合格率 留空,由 FORMULAS 计算
        rows.add(batch("IQ2601", "冷轧钢板", "华新电子", 2000, 20, "让步接收"));
        rows.add(batch("IQ2602", "铜芯电缆", "恒通材料", 1500, 15, "让步接收"));
        rows.add(batch("IQ2603", "铝合金型材", "佳美包装", 1200, 96, "退货"));
        rows.add(batch("IQ2604", "不锈钢管", "新元五金", 800, 12, "让步接收"));
        rows.add(batch("IQ2605", "橡胶密封圈", "天海电子", 5000, 40, "让步接收"));
        rows.add(batch("IQ2606", "弹簧垫片", "中兴物流", 3000, 30, "让步接收"));
        // 合计占位行:数量合计与整体不合格率留给 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/0072_style_incoming-inspection-defect.xlsx");
        try (OutputStream os = new FileOutputStream(out)) {
            JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("peach", rows, os);
            JQuickFactory factory = new JQuickXmlFactory(parser, XML);
            Style0072IncomingInspectionDefectService service = factory.createApi(Style0072IncomingInspectionDefectService.class);
            service.exportIncomingInspectionDefect("field", "value");
        }

    }

    /** 构造一条来料检验(a=批次号,b=物料名称,c=供应商,d=送检数量,e=不合格数量,f=不合格率,g=处理方式)。 */
    private static JQuickRow batch(String batchNo, String materialName, String supplier,
                                   int inspectionQty, int defectQty, String disposal) {
        JQuickRow row = new JQuickRow();
        row.put("a", batchNo);
        row.put("b", materialName);
        row.put("c", supplier);
        row.put("d", inspectionQty);
        row.put("e", defectQty);
        row.put("f", null);
        row.put("g", disposal);
        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("peach", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Style0072IncomingInspectionDefectService service = factory.createApi(Style0072IncomingInspectionDefectService.class);

XML config · 0072_style_incoming-inspection-defect.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.Style0072IncomingInspectionDefectService">

    <!-- 导出:来料检验不合格记录表 -->
    <excel name="exportIncomingInspectionDefect" returnClass="void">
        <![CDATA[
            EXPORT WITH SHEET="来料检验不合格记录表", HEADER=true,
                MAPPING={"a":"批次号","b":"物料名称","c":"供应商","d":"送检数量","e":"不合格数量","f":"不合格率","g":"处理方式"},
                FORMAT={"d":"#,##0","e":"#,##0","f":"0.00%"},
                FORMULAS={
                    F2:'E2/D2',F3:'E3/D3',F4:'E4/D4',F5:'E5/D5',F6:'E6/D6',F7:'E7/D7',
                    D8:'SUM(D2:D7)',E8:'SUM(E2:E7)',F8:'E8/D8'
                },
                STYLE={
                    ROW 8:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center},
                    F4:{color:red,bold:true}
                }
        ]]>
    </excel>

    <!-- 导入解析:读取导出的来料检验记录 -->
    <excel name="importIncomingInspectionDefect" returnClass="java.util.List">
        <![CDATA[
            IMPORT WITH SHEET="来料检验不合格记录表", HEADER=true,
                MAPPING={"批次号":"batchNo","物料名称":"materialName","供应商":"supplier","送检数量":"inspectionQty","不合格数量":"defectQty","不合格率":"defectRate","处理方式":"disposal"}
        ]]>
    </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.