Export "R&D Project Milestone Progress" to Excel with Java (Styled & Formatted Reports)
Styled & Formatted ReportsScene 0075
Registers planned and actual hours per milestone, computing Hour Variance = Planned - Actual and Hour Achievement Rate = Planned / Actual, with the last row summarizing total planned hours, total actual hours, total variance and the overall achievement rate; the milestone with the lowest achievement rate is marked in red. Implemented declaratively in pure XML — no Java business code required.

About this demo
This demo exports the "R&D Project Milestone Progress" workbook: 1 data sheet(s); MAPPING over 7 columns (里程碑阶段, 负责人, 计划工时, 实际工时, 偏差工时, 工时达成率, 状态), 16 formula(s), 1 style rule(s). On the Java side it builds 6 data rows and calls exportProjectMilestoneProgress() 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 (34 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 R&D Project Milestone Progress to Excel with Java
Output specs
- Scene no.
- 0075
- Group
- Styled & Formatted Reports
- Config lines
- 34
- Source lines
- 65
Java source · Style0075ProjectMilestoneProgressDemo.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 Style0075ProjectMilestoneProgressDemo {
private static final String XML = "jquick/biz/style/0075_style_project-milestone-progress.xml";
/** 导出:纯 XML 完成偏差工时、达成率、合计与最低达成率标红。 */
@Test
public void exportProjectMilestoneProgress() throws Exception {
List<JQuickRow> rows = new ArrayList<>();
// e/f 留空,由 FORMULAS 计算
rows.add(milestone("需求分析", "张伟", 120.00, 110.00, "已完成"));
rows.add(milestone("系统设计", "李娜", 200.00, 230.00, "已完成"));
rows.add(milestone("编码开发", "王强", 800.00, 850.00, "进行中"));
rows.add(milestone("测试验证", "赵敏", 300.00, 280.00, "进行中"));
rows.add(milestone("上线部署", "陈晨", 80.00, 90.00, "未开始"));
// 合计占位行:各列合计与整体达成率留给 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/0075_style_project-milestone-progress.xlsx");
try (OutputStream os = new FileOutputStream(out)) {
JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("jade", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Style0075ProjectMilestoneProgressService service = factory.createApi(Style0075ProjectMilestoneProgressService.class);
service.exportProjectMilestoneProgress("field", "value");
}
}
/** 构造一个里程碑(a=阶段,b=负责人,c=计划工时,d=实际工时,e/f 留空,g=状态)。 */
private static JQuickRow milestone(String stage, String owner, double plannedHours,
double actualHours, String status) {
JQuickRow row = new JQuickRow();
row.put("a", stage);
row.put("b", owner);
row.put("c", plannedHours);
row.put("d", actualHours);
row.put("e", null);
row.put("f", null);
row.put("g", status);
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("jade", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Style0075ProjectMilestoneProgressService service = factory.createApi(Style0075ProjectMilestoneProgressService.class);XML config · 0075_style_project-milestone-progress.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.Style0075ProjectMilestoneProgressService">
<!-- 导出:研发项目里程碑进度表 -->
<excel name="exportProjectMilestoneProgress" returnClass="void">
<![CDATA[
EXPORT WITH SHEET="研发项目里程碑进度表", HEADER=true,
MAPPING={"a":"里程碑阶段","b":"负责人","c":"计划工时","d":"实际工时","e":"偏差工时","f":"工时达成率","g":"状态"},
FORMAT={"c":"#,##0","d":"#,##0","e":"#,##0","f":"0.00%"},
FORMULAS={
E2:'C2-D2',F2:'C2/D2',E3:'C3-D3',F3:'C3/D3',
E4:'C4-D4',F4:'C4/D4',E5:'C5-D5',F5:'C5/D5',
E6:'C6-D6',F6:'C6/D6',
C7:'SUM(C2:C6)',D7:'SUM(D2:D6)',E7:'C7-D7',F7:'C7/D7'
},
STYLE={
ROW 7:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center},
F3:{color:red,bold:true}
}
]]>
</excel>
<!-- 导入解析:读取导出的研发项目里程碑进度表 -->
<excel name="importProjectMilestoneProgress" returnClass="java.util.List">
<![CDATA[
IMPORT WITH SHEET="研发项目里程碑进度表", HEADER=true,
MAPPING={"里程碑阶段":"milestone","负责人":"owner","计划工时":"plannedHours","实际工时":"actualHours","偏差工时":"deviationHours","工时达成率":"achievementRate","状态":"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.