Skip to content

Export "Supplier Records Roster" to Excel with Java (Formula & Calculated Reports)

JQuick-ExcelFormula & Calculated Reports

Formula & Calculated ReportsScene 0071

Registers approved supplier profiles (code / name / category / years of cooperation / contact / phone / annual supply amount / rating), with the last row totaling the annual supply amount. Implemented declaratively in pure XML — no Java business code required.

Download the Excel fileView raw XML configBack to all demos

Supplier Records Roster — Formula & Calculated Reports
Full screenshot of the exported xlsx

About this demo

This demo exports the "Supplier Records Roster" workbook: 1 data sheet(s); MAPPING over 8 columns (供应商编码, 供应商名称, 供应类别, 合作年限, 联系人, 联系电话, 年供货额, 评级), 2 formula(s), 1 style rule(s). On the Java side it builds 7 data rows and calls exportSupplierProfileRoster() 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 (67 lines, runnable as-is)
  • The complete XML config (28 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 Supplier Records Roster to Excel with Java

Output specs

Scene no.
0071
Group
Formula & Calculated Reports
Config lines
28
Source lines
67

Java source · Formulas0071SupplierProfileRosterDemo.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 Formulas0071SupplierProfileRosterDemo {

    private static final String XML = "jquick/biz/formulas/0071_formulas_supplier-profile-roster.xml";

    /** 导出:纯 XML 完成年供货额汇总与合计行高亮。 */
    @Test
    public void exportSupplierProfileRoster() throws Exception {
        List<JQuickRow> rows = new ArrayList<>();
        rows.add(supplier("S2601", "华新电子有限公司", "电子元件", 8, "张明", "13800138001", 2400000.00, "战略供应商"));
        rows.add(supplier("S2602", "恒通材料有限公司", "金属材料", 5, "李强", "13900139002", 1800000.00, "核心供应商"));
        rows.add(supplier("S2603", "佳美包装有限公司", "包装耗材", 3, "王芳", "13700137003", 760000.00, "一般供应商"));
        rows.add(supplier("S2604", "中兴物流有限公司", "物流服务", 6, "赵敏", "13600136004", 540000.00, "核心供应商"));
        rows.add(supplier("S2605", "新元五金有限公司", "五金配件", 2, "陈杰", "13500135005", 320000.00, "一般供应商"));
        rows.add(supplier("S2606", "天海电子有限公司", "电子元件", 4, "周涛", "13400134006", 460000.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);
        total.put("h", null);
        rows.add(total);

        File out = new File("D:/test/excel/biz/formulas/0071_formulas_supplier-profile-roster.xlsx");
        try (OutputStream os = new FileOutputStream(out)) {
            JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("azure", rows, os);
            JQuickFactory factory = new JQuickXmlFactory(parser, XML);
            Formulas0071SupplierProfileRosterService service = factory.createApi(Formulas0071SupplierProfileRosterService.class);
            service.exportSupplierProfileRoster("field", "value");
        }

    }

    /** 构造一家供应商档案(a=编码,b=名称,c=类别,d=合作年限,e=联系人,f=电话,g=年供货额,h=评级)。 */
    private static JQuickRow supplier(String supplierNo, String supplierName, String category, int cooperationYears,
                                      String contact, String phone, double annualAmount, String rating) {
        JQuickRow row = new JQuickRow();
        row.put("a", supplierNo);
        row.put("b", supplierName);
        row.put("c", category);
        row.put("d", cooperationYears);
        row.put("e", contact);
        row.put("f", phone);
        row.put("g", annualAmount);
        row.put("h", rating);
        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("azure", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Formulas0071SupplierProfileRosterService service = factory.createApi(Formulas0071SupplierProfileRosterService.class);

XML config · 0071_formulas_supplier-profile-roster.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.Formulas0071SupplierProfileRosterService">

    <!-- 导出:供应商档案名册 -->
    <excel name="exportSupplierProfileRoster" returnClass="void">
        <![CDATA[
            EXPORT WITH SHEET="供应商档案名册", HEADER=true,
                MAPPING={"a":"供应商编码","b":"供应商名称","c":"供应类别","d":"合作年限","e":"联系人","f":"联系电话","g":"年供货额","h":"评级"},
                FORMAT={"d":"0","g":"#,##0.00"},
                FORMULAS={G8:'SUM(G2:G7)'},
                STYLE={
                    ROW 8:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center}
                }
        ]]>
    </excel>

    <!-- 导入解析:读取导出的供应商档案名册 -->
    <excel name="importSupplierProfileRoster" returnClass="java.util.List">
        <![CDATA[
            IMPORT WITH SHEET="供应商档案名册", HEADER=true,
                MAPPING={"供应商编码":"supplierNo","供应商名称":"supplierName","供应类别":"category","合作年限":"cooperationYears","联系人":"contact","联系电话":"phone","年供货额":"annualAmount","评级":"rating"}
        ]]>
    </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.