Skip to content

Export "Inventory Level Trend" to Excel with Java (Chart & Visualization)

JQuick-ExcelChart & Visualization

Chart & VisualizationScene 0107

Registers opening balance / inbound / outbound by month, rolling the closing balance forward (Closing = Opening + Inbound - Outbound) with a summary in the last row; includes a 3-D area chart showing the inventory trend. All statistics and charts are declared in XML. Exported as a multi-sheet workbook (Inventory Level Trend / Inventory Level Trend Chart). Implemented declaratively in pure XML — no Java business code required.

Download the Excel fileView raw XML configBack to all demos

Inventory Level Trend — Chart & Visualization
Full screenshot of the exported xlsx

About this demo

This demo exports the "Inventory Level Trend" workbook: 1 data sheet(s); MAPPING over 5 columns (月份, 期初, 入库, 出库, 期末), 9 formula(s), 1 style rule(s), AREA3D chart on its own sheet. On the Java side it builds 5 data rows and calls exportInventoryTrend() once — everything else is driven by the config.

It belongs to the "Chart & Visualization" group: GRAPH charts — column, line, scatter and radar charts written into a separate sheet, making the workbook multi-sheet.

What you can copy from this page

  • The complete Java test class (62 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 chart, Java generate Excel line chart, Apache POI chart export example, Java multi-sheet workbook export, export Inventory Level Trend to Excel with Java

Output specs

Scene no.
0107
Group
Chart & Visualization
Config lines
34
Source lines
62

Java source · Graph0107InventoryTrendDemo.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.graph;

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

    private static final String XML = "jquick/biz/graph/0107_graph_inventory-trend.xml";

    /** 导出:4 个月 + 1 行合计 + 三维面积图,回读校验滚动期末、汇总与图表 sheet。 */
    @Test
    public void exportInventoryTrend() throws Exception {
        List<JQuickRow> rows = new ArrayList<>();
        rows.add(detail("1月", 5000, 2000, 2200));
        rows.add(detail("2月", 4800, 2400, 2000));
        rows.add(detail("3月", 5200, 1800, 2400));
        rows.add(detail("4月", 4600, 2600, 2100));
        rows.add(totalRow());

        File out = new File("D:/test/excel/biz/graph/0107_graph_inventory-trend.xlsx");
        try (OutputStream os = new FileOutputStream(out)) {
            JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("forestGreen", rows, os);
            JQuickFactory factory = new JQuickXmlFactory(parser, XML);
            Graph0107InventoryTrendService service = factory.createApi(Graph0107InventoryTrendService.class);
            service.exportInventoryTrend("field", "value");
        }

    }

    /** 构造一条月度明细(e=期末由 FORMULAS 滚动计算,占位保列)。 */
    private static JQuickRow detail(String month, double opening, double inbound, double outbound) {
        JQuickRow row = new JQuickRow();
        row.put("a", month);
        row.put("b", opening);
        row.put("c", inbound);
        row.put("d", outbound);
        row.put("e", null);
        return row;
    }

    /** 合计行:只写「合计」文字,其余列以空值占位(必须补齐全部映射列)。 */
    private static JQuickRow totalRow() {
        JQuickRow row = new JQuickRow();
        row.put("a", "合计");
        row.put("b", null);
        row.put("c", null);
        row.put("d", null);
        row.put("e", null);
        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("forestGreen", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Graph0107InventoryTrendService service = factory.createApi(Graph0107InventoryTrendService.class);

XML config · 0107_graph_inventory-trend.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.graph.Graph0107InventoryTrendService">

    <!-- 导出:库存量趋势 -->
    <excel name="exportInventoryTrend" returnClass="void">
        <![CDATA[
            EXPORT WITH SHEET="库存量趋势", HEADER=true,
                MAPPING={"a":"月份","b":"期初","c":"入库","d":"出库","e":"期末"},
                FORMAT={"b":"#,##0","c":"#,##0","d":"#,##0","e":"#,##0"},
                FORMULAS={
                    E2:'B2+C2-D2',E3:'E2+C3-D3',E4:'E3+C4-D4',E5:'E4+C5-D5',
                    C6:'SUM(C2:C5)',D6:'SUM(D2:D5)',E6:'E5'
                },
                STYLE={ROW 6:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center}},
                GRAPH={TYPE=AREA3D, TITLE="库存量趋势图", CATEGORY_AXIS=月份, VALUE_AXIS=库存,
                       CATEGORIES=["1月","2月","3月","4月"],
                       SERIES=[
                           {NAME=期末, DATA=[4800,5200,4600,5100]}
                       ]}
        ]]>
    </excel>

    <!-- 导入解析:读取导出的库存量趋势 -->
    <excel name="importInventoryTrend" returnClass="java.util.List">
        <![CDATA[
            IMPORT WITH SHEET="库存量趋势", HEADER=true,
                MAPPING={"月份":"month","期初":"opening","入库":"inbound","出库":"outbound","期末":"closing"}
        ]]>
    </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.