Skip to content

Export "Fixed Asset Acceptance Form" to Excel with Java (Formula & Calculated Reports)

JQuick-ExcelFormula & Calculated Reports

Formula & Calculated ReportsScene 0079

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

Download the Excel fileView raw XML configBack to all demos

Fixed Asset Acceptance Form — Formula & Calculated Reports
Full screenshot of the exported xlsx

About this demo

This demo exports the "Fixed Asset Acceptance Form" workbook: 1 data sheet(s); MAPPING over 7 columns (资产名称, 规格型号, 数量, 单价, 金额, 使用部门, 存放地点), 8 formula(s), 1 style rule(s). On the Java side it builds 6 data rows and calls exportFixedAssetAcceptance() 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 (65 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 Fixed Asset Acceptance Form to Excel with Java

Output specs

Scene no.
0079
Group
Formula & Calculated Reports
Config lines
31
Source lines
65

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

    private static final String XML = "jquick/biz/formulas/0079_formulas_fixed-asset-acceptance.xml";

    /** 导出:纯 XML 完成逐行金额、数量与金额合计。 */
    @Test
    public void exportFixedAssetAcceptance() throws Exception {
        List<JQuickRow> rows = new ArrayList<>();
        // e 留空,由 FORMULAS 计算
        rows.add(asset("笔记本电脑", "ThinkPad X1 Carbon", 5, 12000.00, "研发部", "A区工位"));
        rows.add(asset("打印机", "HP M405dn", 3, 2500.00, "行政部", "办公区"));
        rows.add(asset("办公桌", "1.6m 实木", 10, 1800.00, "行政部", "办公区"));
        rows.add(asset("空调", "格力 3匹柜机", 2, 6500.00, "行政部", "会议室"));
        rows.add(asset("服务器", "戴尔 R750", 1, 48000.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/formulas/0079_formulas_fixed-asset-acceptance.xlsx");
        try (OutputStream os = new FileOutputStream(out)) {
            JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("wineRed", rows, os);
            JQuickFactory factory = new JQuickXmlFactory(parser, XML);
            Formulas0079FixedAssetAcceptanceService service = factory.createApi(Formulas0079FixedAssetAcceptanceService.class);
            service.exportFixedAssetAcceptance("field", "value");
        }

    }

    /** 构造一项验收资产(a=资产名称,b=规格型号,c=数量,d=单价,e 留空,f=使用部门,g=存放地点)。 */
    private static JQuickRow asset(String assetName, String specification, double quantity,
                                   double unitPrice, String useDepartment, String location) {
        JQuickRow row = new JQuickRow();
        row.put("a", assetName);
        row.put("b", specification);
        row.put("c", quantity);
        row.put("d", unitPrice);
        row.put("e", null);
        row.put("f", useDepartment);
        row.put("g", location);
        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("wineRed", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Formulas0079FixedAssetAcceptanceService service = factory.createApi(Formulas0079FixedAssetAcceptanceService.class);

XML config · 0079_formulas_fixed-asset-acceptance.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.Formulas0079FixedAssetAcceptanceService">

    <!-- 导出:固定资产验收单 -->
    <excel name="exportFixedAssetAcceptance" returnClass="void">
        <![CDATA[
            EXPORT WITH SHEET="固定资产验收单", HEADER=true,
                MAPPING={"a":"资产名称","b":"规格型号","c":"数量","d":"单价","e":"金额","f":"使用部门","g":"存放地点"},
                FORMAT={"c":"0","d":"#,##0.00","e":"#,##0.00"},
                FORMULAS={
                    E2:'C2*D2',E3:'C3*D3',E4:'C4*D4',E5:'C5*D5',E6:'C6*D6',
                    C7:'SUM(C2:C6)',E7:'SUM(E2:E6)'
                },
                STYLE={
                    ROW 7:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center}
                }
        ]]>
    </excel>

    <!-- 导入解析:读取导出的固定资产验收单 -->
    <excel name="importFixedAssetAcceptance" returnClass="java.util.List">
        <![CDATA[
            IMPORT WITH SHEET="固定资产验收单", HEADER=true,
                MAPPING={"资产名称":"assetName","规格型号":"specification","数量":"quantity","单价":"unitPrice","金额":"amount","使用部门":"useDepartment","存放地点":"location"}
        ]]>
    </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.