Export "Production Plan Achievement Rate" to Excel with Java (Styled & Formatted Reports)
Styled & Formatted ReportsScene 0064
Registers planned quantity and actual output per production work order, computing Achievement Rate = Actual Output / Planned Quantity per row, with the last row giving the average achievement rate and the achievement rate of unmet work orders marked in red. Implemented declaratively in pure XML — no Java business code required.

About this demo
This demo exports the "Production Plan Achievement Rate" workbook: 1 data sheet(s); MAPPING over 8 columns (工单号, 产品名称, 计划数量, 实际产量, 达成率, 计划完成日, 实际完成日, 达成状态), 10 formula(s), 1 style rule(s). On the Java side it builds 6 data rows and calls exportProductionPlanAchievement() 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 (77 lines, runnable as-is)
- The complete XML config (33 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 Plan Achievement Rate to Excel with Java
Output specs
- Scene no.
- 0064
- Group
- Styled & Formatted Reports
- Config lines
- 33
- Source lines
- 77
Java source · Style0064ProductionPlanAchievementDemo.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.Calendar;
import java.util.Date;
import java.util.List;
public class Style0064ProductionPlanAchievementDemo {
private static final String XML = "jquick/biz/style/0064_style_production-plan-achievement.xml";
/** 导出:纯 XML 完成达成率计算、平均达成率与未达成标红。 */
@Test
public void exportProductionPlanAchievement() throws Exception {
List<JQuickRow> rows = new ArrayList<>();
// e=达成率 留空,由 FORMULAS 计算
rows.add(plan("WO2601", "智能手环", 5000, 5200, date(2026, 3, 10), date(2026, 3, 9), "达成"));
rows.add(plan("WO2602", "无线耳机", 4000, 3800, date(2026, 3, 12), date(2026, 3, 13), "未达成"));
rows.add(plan("WO2603", "扫地机器人", 800, 840, date(2026, 3, 15), date(2026, 3, 15), "达成"));
rows.add(plan("WO2604", "空气炸锅", 6000, 6300, date(2026, 3, 18), date(2026, 3, 17), "达成"));
rows.add(plan("WO2605", "破壁机", 2000, 1900, date(2026, 3, 20), date(2026, 3, 22), "未达成"));
// 合计占位行:数量合计与平均达成率留给 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/style/0064_style_production-plan-achievement.xlsx");
try (OutputStream os = new FileOutputStream(out)) {
JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("midnightDark", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Style0064ProductionPlanAchievementService service = factory.createApi(Style0064ProductionPlanAchievementService.class);
service.exportProductionPlanAchievement("field", "value");
}
}
/** 构造一条工单排期(a=工单号,b=产品,c=计划数量,d=实际产量,e=达成率,f=计划完成日,g=实际完成日,h=状态)。 */
private static JQuickRow plan(String orderNo, String productName, int planQty, int actualQty,
Date planDate, Date actualDate, String status) {
JQuickRow row = new JQuickRow();
row.put("a", orderNo);
row.put("b", productName);
row.put("c", planQty);
row.put("d", actualQty);
row.put("e", null);
row.put("f", planDate);
row.put("g", actualDate);
row.put("h", status);
return row;
}
/** 构造日期(月份按自然月 1-12 传入)。 */
private static Date date(int year, int month, int day) {
Calendar c = Calendar.getInstance();
c.clear();
c.set(year, month - 1, day);
return c.getTime();
}
}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("midnightDark", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Style0064ProductionPlanAchievementService service = factory.createApi(Style0064ProductionPlanAchievementService.class);XML config · 0064_style_production-plan-achievement.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.Style0064ProductionPlanAchievementService">
<!-- 导出:生产计划达成率表 -->
<excel name="exportProductionPlanAchievement" returnClass="void">
<![CDATA[
EXPORT WITH SHEET="生产计划达成率表", HEADER=true,
MAPPING={"a":"工单号","b":"产品名称","c":"计划数量","d":"实际产量","e":"达成率","f":"计划完成日","g":"实际完成日","h":"达成状态"},
FORMAT={"c":"#,##0","d":"#,##0","e":"0.00%","f":"yyyy-MM-dd","g":"yyyy-MM-dd"},
FORMULAS={
E2:'D2/C2',E3:'D3/C3',E4:'D4/C4',E5:'D5/C5',E6:'D6/C6',
C7:'SUM(C2:C6)',D7:'SUM(D2:D6)',E7:'AVERAGE(E2:E6)'
},
STYLE={
ROW 7:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center},
E3:{color:red,bold:true},
E6:{color:red,bold:true}
}
]]>
</excel>
<!-- 导入解析:读取导出的计划达成率表 -->
<excel name="importProductionPlanAchievement" returnClass="java.util.List">
<![CDATA[
IMPORT WITH SHEET="生产计划达成率表", HEADER=true,
MAPPING={"工单号":"orderNo","产品名称":"productName","计划数量":"planQty","实际产量":"actualQty","达成率":"achievementRate","计划完成日":"planDate","实际完成日":"actualDate","达成状态":"status"}
]]>
</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.