Skip to content

Export "Production Equipment OEE Analysis" to Excel with Java (Styled & Formatted Reports)

JQuick-ExcelStyled & Formatted Reports

Styled & Formatted ReportsScene 0059

Tallies availability rate, performance rate and quality rate per piece of equipment, computing OEE = the product of the three per row, with the last row giving the average OEE and equipment below the benchmark marked in red. Implemented declaratively in pure XML — no Java business code required.

Download the Excel fileView raw XML configBack to all demos

Production Equipment OEE Analysis — Styled & Formatted Reports
Full screenshot of the exported xlsx

About this demo

This demo exports the "Production Equipment OEE Analysis" workbook: 1 data sheet(s); MAPPING over 7 columns (设备编号, 设备名称, 时间开动率, 性能开动率, 合格品率, OEE, 评价), 6 formula(s), 1 style rule(s). On the Java side it builds 6 data rows and calls exportEquipmentOeeAnalysis() 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 (64 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 Production Equipment OEE Analysis to Excel with Java

Output specs

Scene no.
0059
Group
Styled & Formatted Reports
Config lines
32
Source lines
64

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

    private static final String XML = "jquick/biz/style/0059_style_equipment-oee-analysis.xml";

    /** 导出:纯 XML 完成 OEE 连乘、平均 OEE 与偏低设备标红。 */
    @Test
    public void exportEquipmentOeeAnalysis() throws Exception {
        List<JQuickRow> rows = new ArrayList<>();
        rows.add(equipment("MC2601", "一号压铸机", 0.92, 0.95, 0.98, "达标"));
        rows.add(equipment("MC2602", "二号压铸机", 0.88, 0.90, 0.97, "达标"));
        rows.add(equipment("MC2603", "数控铣床", 0.85, 0.82, 0.95, "待改善"));
        rows.add(equipment("MC2604", "注塑机", 0.90, 0.93, 0.96, "达标"));
        rows.add(equipment("MC2605", "装配线", 0.95, 0.90, 0.99, "达标"));
        // 合计占位行:平均 OEE 留给 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/0059_style_equipment-oee-analysis.xlsx");
        try (OutputStream os = new FileOutputStream(out)) {
            JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("sakuraPink", rows, os);
            JQuickFactory factory = new JQuickXmlFactory(parser, XML);
            Style0059EquipmentOeeAnalysisService service = factory.createApi(Style0059EquipmentOeeAnalysisService.class);
            service.exportEquipmentOeeAnalysis("field", "value");
        }

    }

    /** 构造一台设备(a=编号,b=名称,c=时间开动率,d=性能开动率,e=合格品率,g=评价,f 留空由 FORMULAS 计算)。 */
    private static JQuickRow equipment(String equipmentNo, String equipmentName,
                                       double availability, double performance, double quality, String evaluation) {
        JQuickRow row = new JQuickRow();
        row.put("a", equipmentNo);
        row.put("b", equipmentName);
        row.put("c", availability);
        row.put("d", performance);
        row.put("e", quality);
        row.put("f", null);
        row.put("g", evaluation);
        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", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Style0059EquipmentOeeAnalysisService service = factory.createApi(Style0059EquipmentOeeAnalysisService.class);

XML config · 0059_style_equipment-oee-analysis.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.Style0059EquipmentOeeAnalysisService">

    <!-- 导出:生产设备 OEE 分析表 -->
    <excel name="exportEquipmentOeeAnalysis" returnClass="void">
        <![CDATA[
            EXPORT WITH SHEET="生产设备OEE分析表", HEADER=true,
                MAPPING={"a":"设备编号","b":"设备名称","c":"时间开动率","d":"性能开动率","e":"合格品率","f":"OEE","g":"评价"},
                FORMAT={"c":"0.00%","d":"0.00%","e":"0.00%","f":"0.00%"},
                FORMULAS={
                    F2:'C2*D2*E2',F3:'C3*D3*E3',F4:'C4*D4*E4',F5:'C5*D5*E5',F6:'C6*D6*E6',
                    F7:'AVERAGE(F2:F6)'
                },
                STYLE={
                    ROW 7:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center},
                    F4:{color:red,bold:true}
                }
        ]]>
    </excel>

    <!-- 导入解析:读取导出的生产设备 OEE 分析表 -->
    <excel name="importEquipmentOeeAnalysis" returnClass="java.util.List">
        <![CDATA[
            IMPORT WITH SHEET="生产设备OEE分析表", HEADER=true,
                MAPPING={"设备编号":"equipmentNo","设备名称":"equipmentName","时间开动率":"availability","性能开动率":"performance","合格品率":"quality","OEE":"oee","评价":"evaluation"}
        ]]>
    </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.