Export "Production Scheduling Plan" to Excel with Java (Styled & Formatted Reports)
Styled & Formatted ReportsScene 0087
Registers planned output and daily capacity per production line, computing Required Days = Planned Output / Daily Capacity and Planned Input Hours = Required Days × 8, with the last row summarizing planned output and input hours; the product with the longest schedule is marked in red. Implemented declaratively in pure XML — no Java business code required.

About this demo
This demo exports the "Production Scheduling Plan" workbook: 1 data sheet(s); MAPPING over 7 columns (产线, 产品名称, 计划产量, 日产能, 需求天数, 计划投入工时, 排产状态), 14 formula(s), 1 style rule(s). On the Java side it builds 6 data rows and calls exportProductionSchedulingPlan() 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 (65 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 Scheduling Plan to Excel with Java
Output specs
- Scene no.
- 0087
- Group
- Styled & Formatted Reports
- Config lines
- 33
- Source lines
- 65
Java source · Style0087ProductionSchedulingPlanDemo.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 Style0087ProductionSchedulingPlanDemo {
private static final String XML = "jquick/biz/style/0087_style_production-scheduling-plan.xml";
/** 导出:纯 XML 完成逐行需求天数、投入工时、合计与最长排期标红。 */
@Test
public void exportProductionSchedulingPlan() throws Exception {
List<JQuickRow> rows = new ArrayList<>();
// e/f 留空,由 FORMULAS 计算
rows.add(task("一号线", "A产品", 1200, 200, "已排产"));
rows.add(task("一号线", "B产品", 900, 150, "已排产"));
rows.add(task("二号线", "C产品", 800, 100, "待排产"));
rows.add(task("二号线", "D产品", 600, 120, "已排产"));
rows.add(task("三号线", "E产品", 1000, 250, "已排产"));
// 合计占位行:计划产量与投入工时合计留给 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/0087_style_production-scheduling-plan.xlsx");
try (OutputStream os = new FileOutputStream(out)) {
JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("mintFresh", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Style0087ProductionSchedulingPlanService service = factory.createApi(Style0087ProductionSchedulingPlanService.class);
service.exportProductionSchedulingPlan("field", "value");
}
}
/** 构造一条排产任务(a=产线,b=产品,c=计划产量,d=日产能,e/f 留空,g=排产状态)。 */
private static JQuickRow task(String productionLine, String productName, double plannedOutput,
double dailyCapacity, String scheduleStatus) {
JQuickRow row = new JQuickRow();
row.put("a", productionLine);
row.put("b", productName);
row.put("c", plannedOutput);
row.put("d", dailyCapacity);
row.put("e", null);
row.put("f", null);
row.put("g", scheduleStatus);
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("mintFresh", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Style0087ProductionSchedulingPlanService service = factory.createApi(Style0087ProductionSchedulingPlanService.class);XML config · 0087_style_production-scheduling-plan.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.Style0087ProductionSchedulingPlanService">
<!-- 导出:生产排产计划表 -->
<excel name="exportProductionSchedulingPlan" returnClass="void">
<![CDATA[
EXPORT WITH SHEET="生产排产计划表", HEADER=true,
MAPPING={"a":"产线","b":"产品名称","c":"计划产量","d":"日产能","e":"需求天数","f":"计划投入工时","g":"排产状态"},
FORMAT={"c":"#,##0","d":"#,##0","e":"0.0","f":"#,##0"},
FORMULAS={
E2:'C2/D2',F2:'E2*8',E3:'C3/D3',F3:'E3*8',E4:'C4/D4',F4:'E4*8',
E5:'C5/D5',F5:'E5*8',E6:'C6/D6',F6:'E6*8',
C7:'SUM(C2:C6)',E7:'SUM(E2:E6)',F7:'SUM(F2:F6)'
},
STYLE={
ROW 7:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center},
E4:{color:red,bold:true}
}
]]>
</excel>
<!-- 导入解析:读取导出的生产排产计划表 -->
<excel name="importProductionSchedulingPlan" returnClass="java.util.List">
<![CDATA[
IMPORT WITH SHEET="生产排产计划表", HEADER=true,
MAPPING={"产线":"productionLine","产品名称":"productName","计划产量":"plannedOutput","日产能":"dailyCapacity","需求天数":"requiredDays","计划投入工时":"plannedHours","排产状态":"scheduleStatus"}
]]>
</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.