2 Star 53 Fork 19

sushengren / easyword

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

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

安装教程

<dependency>
    <groupId>com.sushengren</groupId>
    <artifactId>easyword</artifactId>
    <version>1.1.3</version>
</dependency>

使用说明

模板

导出模板

输出

导出效果

代码

@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<ClassInfo> 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<StudentInfo> 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;

    }

}
public static void main(String[] args) throws IOException {
        List<StudentInfo> 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<ClassInfo> 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);
    }
MIT License Copyright (c) 2020 sushengren Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

基于Apache poi封装,在上层做了模型转换的封装,让使用者更加简单方便 展开 收起
Java
MIT
取消

发行版 (4)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/sushengren/easyword.git
git@gitee.com:sushengren/easyword.git
sushengren
easyword
easyword
master

搜索帮助