Skip to content

Export "Fixed Asset Depreciation Detail" to Excel with Java (Formula & Calculated Reports)

JQuick-ExcelFormula & Calculated Reports

Formula & Calculated ReportsScene 0031

Calculates annual and monthly depreciation of fixed assets using the straight-line method, computing Annual Depreciation = Original Value × (1 - Residual Rate) / Useful Life and Monthly Depreciation = Annual Depreciation / 12 per row, with the last row summarizing original value, annual depreciation and monthly depreciation. Implemented declaratively in pure XML — no Java business code required.

Download the Excel fileView raw XML configBack to all demos

Fixed Asset Depreciation Detail — Formula & Calculated Reports
Full screenshot of the exported xlsx

About this demo

This demo exports the "Fixed Asset Depreciation Detail" workbook: 1 data sheet(s); MAPPING over 7 columns (资产编号, 资产名称, 原值, 残值率, 使用年限, 年折旧额, 月折旧额), 16 formula(s), 1 style rule(s). On the Java side it builds 7 data rows and calls exportAssetDepreciation() 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 (64 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 formulas, Java Excel SUM formula export, Apache POI write formula example, Java computed column export, export Fixed Asset Depreciation Detail to Excel with Java

Output specs

Scene no.
0031
Group
Formula & Calculated Reports
Config lines
34
Source lines
64

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

    private static final String XML = "jquick/biz/formulas/0031_formulas_asset-depreciation-detail.xml";

    /** 导出:纯 XML 完成年 / 月折旧额计算与合计行汇总。 */
    @Test
    public void exportAssetDepreciation() throws Exception {
        List<JQuickRow> rows = new ArrayList<>();
        rows.add(asset("FA001", "服务器", 80000, 0.05, 5));
        rows.add(asset("FA002", "开发工作站", 45000, 0.05, 3));
        rows.add(asset("FA003", "测试设备", 30000, 0.05, 5));
        rows.add(asset("FA004", "办公家具", 25000, 0.05, 8));
        rows.add(asset("FA005", "激光打印机", 12000, 0.05, 5));
        rows.add(asset("FA006", "生产线设备", 200000, 0.05, 10));
        // 合计占位行:折旧额留给 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/0031_formulas_asset-depreciation-detail.xlsx");
        try (OutputStream os = new FileOutputStream(out)) {
            JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("amber", rows, os);
            JQuickFactory factory = new JQuickXmlFactory(parser, XML);
            Formulas0031AssetDepreciationDetailService service = factory.createApi(Formulas0031AssetDepreciationDetailService.class);
            service.exportAssetDepreciation("field", "value");
        }

    }

    /** 构造一条固定资产(a=编号,b=名称,c=原值,d=残值率,e=使用年限)。 */
    private static JQuickRow asset(String no, String name, double originalValue, double residualRate, int life) {
        JQuickRow row = new JQuickRow();
        row.put("a", no);
        row.put("b", name);
        row.put("c", originalValue);
        row.put("d", residualRate);
        row.put("e", life);
        row.put("f", null);
        row.put("g", 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("amber", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Formulas0031AssetDepreciationDetailService service = factory.createApi(Formulas0031AssetDepreciationDetailService.class);

XML config · 0031_formulas_asset-depreciation-detail.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.Formulas0031AssetDepreciationDetailService">

    <!-- 导出:固定资产折旧明细表 -->
    <excel name="exportAssetDepreciation" returnClass="void">
        <![CDATA[
            EXPORT WITH SHEET="固定资产折旧明细表", HEADER=true,
                MAPPING={"a":"资产编号","b":"资产名称","c":"原值","d":"残值率","e":"使用年限","f":"年折旧额","g":"月折旧额"},
                FORMAT={"c":"#,##0.00","d":"0%","e":"0","f":"#,##0.00","g":"#,##0.00"},
                FORMULAS={
                    F2:'C2*(1-D2)/E2',G2:'F2/12',
                    F3:'C3*(1-D3)/E3',G3:'F3/12',
                    F4:'C4*(1-D4)/E4',G4:'F4/12',
                    F5:'C5*(1-D5)/E5',G5:'F5/12',
                    F6:'C6*(1-D6)/E6',G6:'F6/12',
                    F7:'C7*(1-D7)/E7',G7:'F7/12',
                    C8:'SUM(C2:C7)',F8:'SUM(F2:F7)',G8:'SUM(G2:G7)'
                },
                STYLE={ROW 8:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center}}
        ]]>
    </excel>

    <!-- 导入解析:读取导出的固定资产折旧明细表 -->
    <excel name="importAssetDepreciation" returnClass="java.util.List">
        <![CDATA[
            IMPORT WITH SHEET="固定资产折旧明细表", HEADER=true,
                MAPPING={"资产编号":"assetNo","资产名称":"assetName","原值":"originalValue","残值率":"residualRate","使用年限":"usefulLife","年折旧额":"annualDepreciation","月折旧额":"monthlyDepreciation"}
        ]]>
    </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.