Skip to content

Export "Project Schedule Plan" to Excel with Java (Merge & Grouped Reports)

JQuick-ExcelMerge & Grouped Reports

Merge & Grouped ReportsScene 0018

Projects scheduled by phase, computing Duration (in days) = End Date - Start Date per row, with a duration subtotal row after each phase and a total duration and overall average completion rate in the last row; the phase-name column is vertically merged into one block. Java only groups and pre-processes the rows; all statistics and layout are declared in XML.

Download the Excel fileView raw XML configBack to all demos

Project Schedule Plan — Merge & Grouped Reports
Full screenshot of the exported xlsx

About this demo

This demo exports the "Project Schedule Plan" workbook: 1 data sheet(s); MAPPING over 7 columns (阶段, 任务名称, 负责人, 开始日期, 结束日期, 工期(天), 完成率), 13 formula(s), 7 style rule(s). On the Java side it only builds the data and calls exportProjectSchedule() once — everything else is driven by the config.

It belongs to the "Merge & Grouped Reports" group: MERGE group blocks with SUBTOTAL/TOTAL rows: each group column merges into one vertical block, every group closes with a subtotal and the report ends with a grand total.

What you can copy from this page

  • The complete Java test class (109 lines, runnable as-is)
  • The complete XML config (41 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 merged cells, Java Excel group subtotal and total rows, Apache POI merged cells export, Java grouped report export, export Project Schedule Plan to Excel with Java

Output specs

Scene no.
0018
Group
Merge & Grouped Reports
Config lines
41
Source lines
109

Java source · Merge0018ProjectScheduleDemo.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.merge;

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 Merge0018ProjectScheduleDemo {

    private static final String XML = "jquick/biz/merge/0018_merge_project-schedule.xml";

    /** 导出:Java 分组 + 插小计行,阶段列纵向合并,工期 / 完成率由 XML FORMULAS 完成。 */
    @Test
    public void exportProjectSchedule() throws Exception {
        // 1. 构造扁平任务明细(Java 不做任何工期计算)
        List<JQuickRow> flat = new ArrayList<>();
        flat.add(task("需求分析", "需求调研", "张伟", date(2026, 3, 1), date(2026, 3, 5), 1.0));
        flat.add(task("需求分析", "需求评审", "李娜", date(2026, 3, 6), date(2026, 3, 8), 1.0));
        flat.add(task("系统设计", "概要设计", "王强", date(2026, 3, 9), date(2026, 3, 13), 1.0));
        flat.add(task("系统设计", "详细设计", "赵敏", date(2026, 3, 14), date(2026, 3, 18), 0.8));
        flat.add(task("开发实现", "后端开发", "陈刚", date(2026, 3, 19), date(2026, 3, 28), 0.5));
        flat.add(task("开发实现", "前端开发", "孙丽", date(2026, 3, 19), date(2026, 3, 26), 0.4));
        flat.add(task("开发实现", "联调测试", "周杰", date(2026, 3, 29), date(2026, 4, 2), 0.1));

        // 2. Java 分组并插入小计 / 合计占位行(工期、完成率留给 FORMULAS)
        List<JQuickRow> rows = groupWithSubtotal(flat);

        File out = new File("D:/test/excel/biz/merge/0018_merge_project-schedule.xlsx");
        try (OutputStream os = new FileOutputStream(out)) {
            JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("terracotta", rows, os);
            JQuickFactory factory = new JQuickXmlFactory(parser, XML);
            Merge0018ProjectScheduleService service = factory.createApi(Merge0018ProjectScheduleService.class);
            service.exportProjectSchedule("field", "value");
        }

    }

    /** 按阶段分组,阶段切换处插入小计行,末尾追加合计行(不做工期计算)。 */
    private static List<JQuickRow> groupWithSubtotal(List<JQuickRow> flat) {
        List<JQuickRow> out = new ArrayList<>();
        String current = null;
        for (JQuickRow r : flat) {
            String phase = String.valueOf(r.get("a"));
            if (current != null && !current.equals(phase)) {
                out.add(subtotalRow(current));
            }
            out.add(r);
            current = phase;
        }
        if (current != null) {
            out.add(subtotalRow(current));
        }
        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);
        out.add(total);
        return out;
    }

    /** 小计占位行:只写阶段与小计文字,工期留空由 FORMULAS 计算,完成率留空供合计行平均时忽略。 */
    private static JQuickRow subtotalRow(String phase) {
        JQuickRow row = new JQuickRow();
        row.put("a", phase);
        row.put("b", "小计");
        row.put("c", null);
        row.put("d", null);
        row.put("e", null);
        row.put("f", null);
        row.put("g", null);
        return row;
    }

    /** 构造一条任务明细(a=阶段,b=任务,c=负责人,d=开始,e=结束,g=完成率)。 */
    private static JQuickRow task(String phase, String name, String owner, Date start, Date end, double progress) {
        JQuickRow row = new JQuickRow();
        row.put("a", phase);
        row.put("b", name);
        row.put("c", owner);
        row.put("d", start);
        row.put("e", end);
        row.put("f", null);
        row.put("g", progress);
        return row;
    }

    /** 构造一个「年-月-日」日期(月份从 1 开始)。 */
    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("terracotta", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Merge0018ProjectScheduleService service = factory.createApi(Merge0018ProjectScheduleService.class);

XML config · 0018_merge_project-schedule.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.merge.Merge0018ProjectScheduleService">

    <!-- 导出:项目进度计划排期表 -->
    <excel name="exportProjectSchedule" returnClass="void">
        <![CDATA[
            EXPORT WITH SHEET="项目进度计划排期表", HEADER=true,
                MAPPING={"a":"阶段","b":"任务名称","c":"负责人","d":"开始日期","e":"结束日期","f":"工期(天)","g":"完成率"},
                FORMAT={"d":"yyyy-MM-dd","e":"yyyy-MM-dd","f":"0","g":"0%"},
                FORMULAS={
                    F2:'E2-D2',F3:'E3-D3',F4:'SUM(F2:F3)',
                    F5:'E5-D5',F6:'E6-D6',F7:'SUM(F5:F6)',
                    F8:'E8-D8',F9:'E9-D9',F10:'E10-D10',F11:'SUM(F8:F10)',
                    F12:'F4+F7+F11',G12:'AVERAGE(G2:G10)'
                },
                STYLE={
                    ROW 4:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center},
                    ROW 7:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center},
                    ROW 11:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center},
                    ROW 12:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center}
                },
                MERGE:{
                    RANGE A2:A3 WITH MERGE_WITH_FIRST,
                    RANGE A5:A6 WITH MERGE_WITH_FIRST,
                    RANGE A8:A10 WITH MERGE_WITH_FIRST
                }
        ]]>
    </excel>

    <!-- 导入解析:读取导出的项目进度计划排期表 -->
    <excel name="importProjectSchedule" returnClass="java.util.List">
        <![CDATA[
            IMPORT WITH SHEET="项目进度计划排期表", HEADER=true,
                MAPPING={"阶段":"phase","任务名称":"task","负责人":"owner","开始日期":"startDate","结束日期":"endDate","工期(天)":"duration","完成率":"progress"}
        ]]>
    </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.