Skip to content

Export "Material Requisition Overlay Print" to Excel with Java (Formula & Calculated Reports)

JQuick-ExcelFormula & Calculated Reports

Formula & Calculated ReportsScene 0050

Registers the specification, quantity and unit price of requisitioned materials item by item, computing Amount = Requisitioned Quantity × Unit Price, with the last row summarizing the total requisitioned quantity and total amount. Implemented declaratively in pure XML — no Java business code required.

Download the Excel fileView raw XML configBack to all demos

Material Requisition Overlay Print — Formula & Calculated Reports
Full screenshot of the exported xlsx

About this demo

This demo exports the "Material Requisition Overlay Print" workbook: 1 data sheet(s); MAPPING over 7 columns (材料名称, 规格型号, 领用数量, 计量单位, 单价, 金额, 用途), 9 formula(s), 1 style rule(s). On the Java side it builds 7 data rows and calls exportMaterialRequisition() once — everything else is driven by the config.

It belongs to the "Formula & Calculated Reports" group: FORMULAS — inline expressions and aggregate functions such as Quantity × Unit Price or Balance = Receivable − Received, with SUM totals on the last row.

What you can copy from this page

  • The complete Java test class (66 lines, runnable as-is)
  • The complete XML config (31 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 formulas, Java Excel SUM formula export, Apache POI write formula example, Java computed column export, export Material Requisition Overlay Print to Excel with Java

Output specs

Scene no.
0050
Group
Formula & Calculated Reports
Config lines
31
Source lines
66

Java source · Formulas0050MaterialRequisitionDemo.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.formulas;

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

    private static final String XML = "jquick/biz/formulas/0050_formulas_material-requisition.xml";

    /** 导出:纯 XML 完成逐行金额、数量与金额合计。 */
    @Test
    public void exportMaterialRequisition() throws Exception {
        List<JQuickRow> rows = new ArrayList<>();
        // f 留空,由 FORMULAS 计算
        rows.add(material("钢板", "Q235 δ3mm", 20, "张", 380.00, "机架制作"));
        rows.add(material("角钢", "50×50×5", 40, "根", 65.00, "机架制作"));
        rows.add(material("焊条", "J422 φ3.2", 100, "kg", 8.50, "焊接工艺"));
        rows.add(material("螺栓", "M12×60", 500, "套", 1.20, "整机装配"));
        rows.add(material("防锈漆", "红丹底漆", 30, "kg", 22.00, "表面处理"));
        rows.add(material("砂纸", "240目", 200, "张", 1.50, "表面处理"));
        // 合计占位行:数量与金额合计留给 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/formulas/0050_formulas_material-requisition.xlsx");
        try (OutputStream os = new FileOutputStream(out)) {
            JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("roseQuartz", rows, os);
            JQuickFactory factory = new JQuickXmlFactory(parser, XML);
            Formulas0050MaterialRequisitionService service = factory.createApi(Formulas0050MaterialRequisitionService.class);
            service.exportMaterialRequisition("field", "value");
        }

    }

    /** 构造一項领用材料(a=名称,b=规格,c=数量,d=单位,e=单价,f 留空,g=用途)。 */
    private static JQuickRow material(String materialName, String specification, double requisitionQuantity,
                                      String unit, double unitPrice, String purpose) {
        JQuickRow row = new JQuickRow();
        row.put("a", materialName);
        row.put("b", specification);
        row.put("c", requisitionQuantity);
        row.put("d", unit);
        row.put("e", unitPrice);
        row.put("f", null);
        row.put("g", purpose);
        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("roseQuartz", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Formulas0050MaterialRequisitionService service = factory.createApi(Formulas0050MaterialRequisitionService.class);

XML config · 0050_formulas_material-requisition.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.formulas.Formulas0050MaterialRequisitionService">

    <!-- 导出:材料领用单 -->
    <excel name="exportMaterialRequisition" returnClass="void">
        <![CDATA[
            EXPORT WITH SHEET="材料领用单", HEADER=true,
                MAPPING={"a":"材料名称","b":"规格型号","c":"领用数量","d":"计量单位","e":"单价","f":"金额","g":"用途"},
                FORMAT={"c":"0","e":"#,##0.00","f":"#,##0.00"},
                FORMULAS={
                    F2:'C2*E2',F3:'C3*E3',F4:'C4*E4',F5:'C5*E5',F6:'C6*E6',F7:'C7*E7',
                    C8:'SUM(C2:C7)',F8:'SUM(F2:F7)'
                },
                STYLE={
                    ROW 8:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center}
                }
        ]]>
    </excel>

    <!-- 导入解析:读取导出的材料领用单 -->
    <excel name="importMaterialRequisition" returnClass="java.util.List">
        <![CDATA[
            IMPORT WITH SHEET="材料领用单", HEADER=true,
                MAPPING={"材料名称":"materialName","规格型号":"specification","领用数量":"requisitionQuantity","计量单位":"unit","单价":"unitPrice","金额":"amount","用途":"purpose"}
        ]]>
    </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.