# easyword **Repository Path**: weicom/easyword ## Basic Information - **Project Name**: easyword - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 24 - **Created**: 2024-09-11 - **Last Updated**: 2024-11-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # JAVA解析Word工具EasyWord ### 介绍 - 基于Apache poi封装,在上层做了模型转换的封装,让使用者更加简单方便 - 只支持docx的导出,不支持doc ### 组件依赖 | 依赖 | 版本 | 备注 | |---|---|---| | lombok | 1.18.10 | | | poi | 5.1.0 | | | poi-ooxml | 5.1.0 | | | poi-scratchpad | 5.1.0 | | ### 安装教程 ``` com.sushengren easyword 1.1.3 ``` ### 使用说明 #### 模板 ![导出模板](doc/%E5%AF%BC%E5%87%BA%E6%A8%A1%E6%9D%BF.png) #### 输出 ![导出效果](doc/%E5%AF%BC%E5%87%BA%E6%95%88%E6%9E%9C.png) #### 代码 ```Java @Getter @Setter @Builder @NoArgsConstructor @AllArgsConstructor public class DemoData { @WordProperty("标题") private String title; @WordProperty("生成时间") private String generationTime; @WordProperty("学生数") private Integer numberOfStudents; @WordProperty("监考老师数") private Integer numberOfInvigilators; @WordProperty("评卷老师数") private Integer numberOfTeachers; @WordProperty("年度") private String year; @WordProperty("学期") private String semester; @WordProperty("考试时间") private String examinationTime; @WordProperty("科目") private String subject; @WordProperty(value = "Logo", converter = PictureConverter.class) private InputStream logo; @WordProperty("班级列表") private List classList; @Getter @Setter @Builder @NoArgsConstructor @AllArgsConstructor public static class ClassInfo { @WordProperty("班级") private String className; @WordProperty("人数") private Integer numberOfPeople; @WordProperty("平均分") private Double theAverageScore; @WordProperty("年级") private String grade; @WordProperty("排名") private Integer ranking; @WordProperty("班主任") private String classTeacher; @WordProperty("学生列表") private List studentList; } @Getter @Setter @Builder @NoArgsConstructor @AllArgsConstructor public static class StudentInfo { @WordProperty("姓名") private String name; @WordProperty("学号") private String studentID; @WordProperty("总分") private Double totalScore; @WordProperty("平均分") private Double theAverageScore; @WordProperty("排名") private Integer ranking; @WordProperty("年级排名") private Integer gradeRanking; @WordProperty("备注") private String remark; } } ``` ```Java public static void main(String[] args) throws IOException { List studentList = new ArrayList<>(); studentList.add(new StudentInfo("小明", "No00001", 280.0, 93.3, 1, 1, "")); studentList.add(new StudentInfo("小红", "No00002", 260.0, 86.6, 2, 2, "")); studentList.add(new StudentInfo("小花", "No00003", 270.0, 90.0, 3, 120, "")); studentList.add(new StudentInfo("小莉", "No00004", 250.0, 83.3, 4, 210, "")); studentList.add(new StudentInfo("托尼", "No00005", 241.0, 80.3, 5, 600, "")); List classList = new ArrayList<>(); classList.add(new ClassInfo("一年级一班", 50, 270.5, "一年级", 1, "温娟", studentList)); classList.add(new ClassInfo("一年级二班", 60, 260.5, "一年级", 2, "张三", studentList)); classList.add(new ClassInfo("一年级三班", 35, 280.5, "一年级", 3, "李四", studentList)); classList.add(new ClassInfo("一年级四班", 56, 290.5, "一年级", 4, "王五", studentList)); DemoData data = DemoData.builder() .title("2022年度期末考试成绩报告") .generationTime("2022-01-01") .numberOfStudents(1510) .numberOfInvigilators(157) .numberOfTeachers(157) .year("二零二二") .semester("第二学期") .examinationTime("2022-10-01 至 2022-10-02") .subject("语文、数学、英语") .classList(classList) .logo(new FileInputStream("C:\\Users\\mangfu\\Pictures\\logo.png")) .build(); File file = new File("C:\\Users\\mangfu\\Desktop\\期末成绩报告模板.docx"); FileOutputStream out = new FileOutputStream("C:\\Users\\mangfu\\Desktop\\期末成绩报告模板-1.docx"); EasyWord.of(file).doWrite(data).toOutputStream(out); } ```