Skip to content

Export "Input Invoice Ledger" to Excel with Java (Formula & Calculated Reports)

JQuick-ExcelFormula & Calculated Reports

Formula & Calculated ReportsScene 0020

Registers input VAT invoices obtained from purchases, computing Tax Amount = Amount Excl. Tax × Tax Rate and Total Incl. Tax = Amount Excl. Tax + Tax Amount per row, with the last row summarizing the amount excl. tax, tax amount and total incl. tax. Implemented declaratively in pure XML — no Java business code required.

Download the Excel fileView raw XML configBack to all demos

Input Invoice Ledger — Formula & Calculated Reports
Full screenshot of the exported xlsx

About this demo

This demo exports the "Input Invoice Ledger" 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 exportInputVatInvoice() 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 (74 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 Input Invoice Ledger to Excel with Java

Output specs

Scene no.
0020
Group
Formula & Calculated Reports
Config lines
34
Source lines
74

Java source · Formulas0020InputVatInvoiceLedgerDemo.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.Calendar;
import java.util.Date;
import java.util.List;

public class Formulas0020InputVatInvoiceLedgerDemo {

    private static final String XML = "jquick/biz/formulas/0020_formulas_input-vat-invoice-ledger.xml";

    /** 导出:纯 XML 完成税额、价税合计与合计行汇总。 */
    @Test
    public void exportInputVatInvoice() throws Exception {
        List<JQuickRow> rows = new ArrayList<>();
        rows.add(invoice("INV2026001", date(2026, 1, 5), "华新电子", 100000, 0.13));
        rows.add(invoice("INV2026002", date(2026, 1, 12), "恒通材料", 80000, 0.13));
        rows.add(invoice("INV2026003", date(2026, 1, 18), "光明物流", 20000, 0.09));
        rows.add(invoice("INV2026004", date(2026, 1, 25), "长江机械", 150000, 0.13));
        rows.add(invoice("INV2026005", date(2026, 2, 2), "佳美包装", 30000, 0.06));
        rows.add(invoice("INV2026006", date(2026, 2, 8), "兴业办公", 10000, 0.13));
        // 合计占位行:金额、税额、价税合计留给 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/0020_formulas_input-vat-invoice-ledger.xlsx");
        try (OutputStream os = new FileOutputStream(out)) {
            JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("bronze", rows, os);
            JQuickFactory factory = new JQuickXmlFactory(parser, XML);
            Formulas0020InputVatInvoiceLedgerService service = factory.createApi(Formulas0020InputVatInvoiceLedgerService.class);
            service.exportInputVatInvoice("field", "value");
        }

    }

    /** 构造一条进项发票明细(a=发票号,b=开票日期,c=供应商,d=不含税金额,e=税率)。 */
    private static JQuickRow invoice(String no, Date invoiceDate, String supplier, double amount, double rate) {
        JQuickRow row = new JQuickRow();
        row.put("a", no);
        row.put("b", invoiceDate);
        row.put("c", supplier);
        row.put("d", amount);
        row.put("e", rate);
        row.put("f", null);
        row.put("g", null);
        return row;
    }

    /** 构造一个「年-月-日」日期(月份从 1 开始)。 */
    private static Date date(int year, int month, int day) {
        Calendar c = Calendar.getInstance();
        c.clear();
        c.set(year, month - 1, day);
        return c.getTime();
    }
}

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("bronze", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Formulas0020InputVatInvoiceLedgerService service = factory.createApi(Formulas0020InputVatInvoiceLedgerService.class);

XML config · 0020_formulas_input-vat-invoice-ledger.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.Formulas0020InputVatInvoiceLedgerService">

    <!-- 导出:进项发票台账 -->
    <excel name="exportInputVatInvoice" returnClass="void">
        <![CDATA[
            EXPORT WITH SHEET="进项发票台账", HEADER=true,
                MAPPING={"a":"发票号码","b":"开票日期","c":"供应商","d":"不含税金额","e":"税率","f":"税额","g":"价税合计"},
                FORMAT={"b":"yyyy-MM-dd","d":"#,##0.00","e":"0%","f":"#,##0.00","g":"#,##0.00"},
                FORMULAS={
                    F2:'D2*E2',G2:'D2+F2',
                    F3:'D3*E3',G3:'D3+F3',
                    F4:'D4*E4',G4:'D4+F4',
                    F5:'D5*E5',G5:'D5+F5',
                    F6:'D6*E6',G6:'D6+F6',
                    F7:'D7*E7',G7:'D7+F7',
                    D8:'SUM(D2:D7)',F8:'SUM(F2:F7)',G8:'D8+F8'
                },
                STYLE={ROW 8:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center}}
        ]]>
    </excel>

    <!-- 导入解析:读取导出的进项发票台账 -->
    <excel name="importInputVatInvoice" returnClass="java.util.List">
        <![CDATA[
            IMPORT WITH SHEET="进项发票台账", HEADER=true,
                MAPPING={"发票号码":"invoiceNo","开票日期":"invoiceDate","供应商":"supplier","不含税金额":"amount","税率":"taxRate","税额":"taxAmount","价税合计":"totalAmount"}
        ]]>
    </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.