# excel-fm-tpl **Repository Path**: xuhaohai/excel-fm-tpl ## Basic Information - **Project Name**: excel-fm-tpl - **Description**: 通过 excel 单元格的 freemarker 语法生成 excel 文件的工具,可以做为excel通过导出工具,支持 freemarker 的 全部语法,包括 list循环语法 ,其中 [#list] [/#list] : 等同于 <#list> - **Primary Language**: Java - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 4 - **Forks**: 1 - **Created**: 2022-03-11 - **Last Updated**: 2023-04-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: FreeMarker, Excel, template ## README 使用freemarker语法生成excel文件,支持循环标签,只需要修改模板,不需要修改代码即可生成一份excel文件 模板文件位置: [`src/test/resources/demo.xlsx`](./src/test/resources/demo.xlsx) 示例数据文件位置: [`src/test/resources/demo.json`](./src/test/resources/demo.json) 测试类的文件位置:[`src/test/java/../demo/Demo.java`](./src/test/java/com/icesoft/excel/TemplateHelperTest.java) **模板文件:** ![模板文件](./images/tpl.png) **处理后的文件:** ![处理后的文件](./images/output.png) 单元测试示例 ``` @Test public void demo() throws IOException, TemplateException { File dataFile = new File("src/test/resources/demo.json"); JSON json = JSONUtil.readJSON(dataFile, Charset.defaultCharset()); File tplFile = new File("src/test/resources/demo.xlsx"); File output = new File(FileUtil.getTmpDir(), "demo-output.xlsx"); Map context = new HashMap<>(); context.put("date", new Date()); context.put("json", json.toBean(new TypeReference>() { })); TemplateHelper.processExcelTpl(tplFile, output, context); System.out.println(output.getCanonicalPath()); RuntimeUtil.execForStr("cmd /c start " + output.getPath()); } ```