Export "Sales Commission Calculation" to Excel with Java (Styled & Formatted Reports)
Styled & Formatted ReportsScene 0040
Computes target achievement per salesperson, calculating Achievement Rate = Actual Sales / Sales Target and Commission Amount = Actual Sales × Commission Rate per row, with the achievement rate of salespeople who missed their target marked in red and the last row giving the overall achievement rate. Implemented declaratively in pure XML — no Java business code required.

About this demo
This demo exports the "Sales Commission Calculation" workbook: 1 data sheet(s); MAPPING over 7 columns (销售员, 销售区域, 销售目标, 实际销售额, 达成率, 提成比例, 提成金额), 16 formula(s), 1 style rule(s). On the Java side it builds 6 data rows and calls exportSalesCommission() once — everything else is driven by the config.
It belongs to the "Styled & Formatted Reports" group: STYLE and conditional formatting: themed headers, zebra striping, highlighted total rows and threshold-based colouring of abnormal cells.
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 styles, Java Excel header style zebra rows, Apache POI CellStyle export, Java Excel conditional formatting, export Sales Commission Calculation to Excel with Java
Output specs
- Scene no.
- 0040
- Group
- Styled & Formatted Reports
- Config lines
- 36
- Source lines
- 63
Java source · Style0040SalesCommissionDemo.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.style;
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 Style0040SalesCommissionDemo {
private static final String XML = "jquick/biz/style/0040_style_sales-commission.xml";
/** 导出:纯 XML 完成达成率、提成、合计汇总与未达成标红。 */
@Test
public void exportSalesCommission() throws Exception {
List<JQuickRow> rows = new ArrayList<>();
rows.add(salesman("张伟", "华东", 800000, 920000, 0.03));
rows.add(salesman("李娜", "华南", 600000, 480000, 0.025));
rows.add(salesman("王强", "华北", 700000, 735000, 0.03));
rows.add(salesman("赵敏", "西南", 500000, 560000, 0.028));
rows.add(salesman("陈刚", "东北", 400000, 380000, 0.02));
// 合计占位行:目标、实际销售额与提成金额留给 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/style/0040_style_sales-commission.xlsx");
try (OutputStream os = new FileOutputStream(out)) {
JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("azure", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Style0040SalesCommissionService service = factory.createApi(Style0040SalesCommissionService.class);
service.exportSalesCommission("field", "value");
}
}
/** 构造一名销售员行(a=销售员,b=区域,c=目标,d=实际,f=提成比例,e/g 留空)。 */
private static JQuickRow salesman(String name, String region, double target, double actualSales, double commissionRate) {
JQuickRow row = new JQuickRow();
row.put("a", name);
row.put("b", region);
row.put("c", target);
row.put("d", actualSales);
row.put("e", null);
row.put("f", commissionRate);
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("azure", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Style0040SalesCommissionService service = factory.createApi(Style0040SalesCommissionService.class);XML config · 0040_style_sales-commission.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.style.Style0040SalesCommissionService">
<!-- 导出:销售提成计算表 -->
<excel name="exportSalesCommission" returnClass="void">
<![CDATA[
EXPORT WITH SHEET="销售提成计算表", HEADER=true,
MAPPING={"a":"销售员","b":"销售区域","c":"销售目标","d":"实际销售额","e":"达成率","f":"提成比例","g":"提成金额"},
FORMAT={"c":"#,##0.00","d":"#,##0.00","e":"0.00%","f":"0.00%","g":"#,##0.00"},
FORMULAS={
E2:'D2/C2',G2:'D2*F2',
E3:'D3/C3',G3:'D3*F3',
E4:'D4/C4',G4:'D4*F4',
E5:'D5/C5',G5:'D5*F5',
E6:'D6/C6',G6:'D6*F6',
C7:'SUM(C2:C6)',D7:'SUM(D2:D6)',E7:'D7/C7',G7:'SUM(G2:G6)'
},
STYLE={
ROW 7:{bold:true,fillPattern:solid_foreground,fillForegroundColor:lightYellow,alignment:right,verticalAlignment:center},
E3:{color:red,bold:true}
}
]]>
</excel>
<!-- 导入解析:读取导出的销售提成计算表 -->
<excel name="importSalesCommission" returnClass="java.util.List">
<![CDATA[
IMPORT WITH SHEET="销售提成计算表", HEADER=true,
MAPPING={"销售员":"salesman","销售区域":"region","销售目标":"target","实际销售额":"actualSales","达成率":"achieveRate","提成比例":"commissionRate","提成金额":"commissionAmount"}
]]>
</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.