Export "Inventory Write-Down Provision Schedule" to Excel with Java (Formula & Calculated Reports)
Formula & Calculated ReportsScene 0049
Measures inventory write-down item by item at period end, computing Book Cost = Quantity × Unit Cost and Write-Down Provision = Book Cost - Net Realizable Value per row, with a summary in the last row and the inventory with the highest write-down amount marked in red. Implemented declaratively in pure XML — no Java business code required.

About this demo
This demo exports the "Inventory Write-Down Provision Schedule" workbook: 1 data sheet(s); MAPPING over 7 columns (存货编码, 存货名称, 数量, 单位成本, 账面成本, 可变现净值, 跌价准备), 12 formula(s), 1 style rule(s). On the Java side it builds 6 data rows and calls exportInventoryDepreciation() 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 (63 lines, runnable as-is)
- The complete XML config (36 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 Inventory Write-Down Provision Schedule to Excel with Java
Output specs
- Scene no.
- 0049
- Group
- Formula & Calculated Reports
- Config lines
- 36
- Source lines
- 63
Java source · Formulas0049InventoryDepreciationDemo.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 Formulas0049InventoryDepreciationDemo {
private static final String XML = "jquick/biz/formulas/0049_formulas_inventory-depreciation.xml";
/** 导出:纯 XML 完成账面成本、跌价准备、合计汇总与跌价金额最高项标红。 */
@Test
public void exportInventoryDepreciation() throws Exception {
List<JQuickRow> rows = new ArrayList<>();
rows.add(item("IC2601", "成品A", 200, 120, 20000.00));
rows.add(item("IC2602", "成品B", 150, 80, 10500.00));
rows.add(item("IC2603", "半成品C", 300, 50, 9000.00));
rows.add(item("IC2604", "原材料D", 500, 30, 14500.00));
rows.add(item("IC2605", "原材料E", 400, 25, 9800.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/0049_formulas_inventory-depreciation.xlsx");
try (OutputStream os = new FileOutputStream(out)) {
JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("slate", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Formulas0049InventoryDepreciationService service = factory.createApi(Formulas0049InventoryDepreciationService.class);
service.exportInventoryDepreciation("field", "value");
}
}
/** 构造一项存货(a=编码,b=名称,c=数量,d=单位成本,f=可变现净值,e/g 留空由 FORMULAS 计算)。 */
private static JQuickRow item(String itemCode, String itemName, int quantity, double unitCost, double netRealizableValue) {
JQuickRow row = new JQuickRow();
row.put("a", itemCode);
row.put("b", itemName);
row.put("c", quantity);
row.put("d", unitCost);
row.put("e", null);
row.put("f", netRealizableValue);
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("slate", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Formulas0049InventoryDepreciationService service = factory.createApi(Formulas0049InventoryDepreciationService.class);XML config · 0049_formulas_inventory-depreciation.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.Formulas0049InventoryDepreciationService">
<!-- 导出:存货跌价准备计提表 -->
<excel name="exportInventoryDepreciation" 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","f":"#,##0.00","g":"#,##0.00"},
FORMULAS={
E2:'C2*D2',G2:'E2-F2',
E3:'C3*D3',G3:'E3-F3',
E4:'C4*D4',G4:'E4-F4',
E5:'C5*D5',G5:'E5-F5',
E6:'C6*D6',G6:'E6-F6',
E7:'SUM(E2:E6)',G7:'SUM(G2:G6)'
},
STYLE={
ROW 7:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center},
G4:{color:red,bold:true}
}
]]>
</excel>
<!-- 导入解析:读取导出的存货跌价准备计提表 -->
<excel name="importInventoryDepreciation" returnClass="java.util.List">
<![CDATA[
IMPORT WITH SHEET="存货跌价准备计提表", HEADER=true,
MAPPING={"存货编码":"itemCode","存货名称":"itemName","数量":"quantity","单位成本":"unitCost","账面成本":"bookCost","可变现净值":"netRealizableValue","跌价准备":"depreciation"}
]]>
</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.