Export "Training Assessment Score Grade Sheet" to Excel with Java (Data Transformation)
Data TransformationScene 0103
In training assessment, scores are converted to grades (≥90 A, ≥80 B, ≥60 C, otherwise D), and the assessment date is normalized. Implemented declaratively in pure XML — no Java business code required.

About this demo
This demo exports the "Training Assessment Score Grade Sheet" workbook: 1 data sheet(s); MAPPING over 5 columns (学号, 姓名, 等级, 考核日期, 班级). On the Java side it builds 5 data rows and calls exportTrainingScoreGrade() once — everything else is driven by the config.
It belongs to the "Data Transformation" group: TRANSFORM field conversion: code-value mapping, date formatting and masking applied during export.
What you can copy from this page
- The complete Java test class (52 lines, runnable as-is)
- The complete XML config (26 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 data transform, Java Excel code value mapping, Java Excel date formatting export, export Training Assessment Score Grade Sheet to Excel with Java
Output specs
- Scene no.
- 0103
- Group
- Data Transformation
- Config lines
- 26
- Source lines
- 52
Java source · Transform0103TrainingScoreGradeDemo.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.transform;
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.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
public class Transform0103TrainingScoreGradeDemo {
private static final String XML = "jquick/biz/transform/0103_transform_training-score-grade.xml";
/** 导出:分数经 SPI grade 换算为等级,回读校验等级列与日期格式。 */
@Test
public void exportTrainingScoreGrade() throws Exception {
List<JQuickRow> rows = new ArrayList<>();
rows.add(student("S2601", "张三丰", 95, "2005-09-01", "初级班"));
rows.add(student("S2602", "李四", 82, "2005-09-01", "初级班"));
rows.add(student("S2603", "王五", 58, "2005-09-02", "中级班"));
rows.add(student("S2604", "赵六", 90, "2005-09-02", "中级班"));
rows.add(student("S2605", "孙七", 76, "2005-09-03", "高级班"));
File out = new File("D:/test/excel/biz/transform/0103_transform_training-score-grade.xlsx");
try (OutputStream os = new FileOutputStream(out)) {
JQuickParseHandler parser = new JQuickExcelExportXmlParseFactory("amber", rows, os);
JQuickFactory factory = new JQuickXmlFactory(parser, XML);
Transform0103TrainingScoreGradeService service = factory.createApi(Transform0103TrainingScoreGradeService.class);
service.exportTrainingScoreGrade("field", "value");
}
}
/** 构造一名考生成绩(c 为分数,导出时经 SPI grade 换算为等级;d 为日期对象走 FORMAT)。 */
private static JQuickRow student(String no, String name, int score, String examDate, String className) throws Exception {
JQuickRow row = new JQuickRow();
row.put("a", no);
row.put("b", name);
row.put("c", score);
row.put("d", new SimpleDateFormat("yyyy-MM-dd").parse(examDate));
row.put("e", className);
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);
Transform0103TrainingScoreGradeService service = factory.createApi(Transform0103TrainingScoreGradeService.class);XML config · 0103_transform_training-score-grade.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.transform.Transform0103TrainingScoreGradeService">
<!-- 导出:分数 -> 等级 -->
<excel name="exportTrainingScoreGrade" returnClass="void">
<![CDATA[
EXPORT WITH SHEET="培训考核成绩", HEADER=true,
MAPPING={"a":"学号","b":"姓名","c":"等级","d":"考核日期","e":"班级"},
FORMAT={"d":"yyyy-MM-dd"},
TRANSFORM={"c":grade(${c})}
]]>
</excel>
<!-- 导入解析:考核日期归一为 yyyy-MM-dd -->
<excel name="importTrainingScoreGrade" returnClass="java.util.List">
<![CDATA[
IMPORT WITH SHEET="培训考核成绩", HEADER=true,
MAPPING={"学号":"studentNo","姓名":"studentName","等级":"gradeLevel","考核日期":"examDate","班级":"className"},
TRANSFORM={"examDate":dateFormat(${examDate},'yyyy-MM-dd')}
]]>
</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.