Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zhangyu836/xltpl4java
A Java library to generate xls/x files from a xls/x template.
https://github.com/zhangyu836/xltpl4java
excel java jinjava poi spreadsheet spreadsheet-manipulation template workbook worksheet xls xlsx
Last synced: about 17 hours ago
JSON representation
A Java library to generate xls/x files from a xls/x template.
- Host: GitHub
- URL: https://github.com/zhangyu836/xltpl4java
- Owner: zhangyu836
- License: apache-2.0
- Created: 2021-12-13T09:07:07.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-12-31T13:27:06.000Z (about 3 years ago)
- Last Synced: 2024-11-20T10:32:26.591Z (2 months ago)
- Topics: excel, java, jinjava, poi, spreadsheet, spreadsheet-manipulation, template, workbook, worksheet, xls, xlsx
- Language: Java
- Homepage:
- Size: 47.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# xltpl
使用 xls/x 文件作为模板来生成 xls/x 文件。 [English](README_EN.md)
## 获取```xml
io.github.zhangyu836
xltpl
0.4.0```
## 使用
* 要使用 xltpl,需要了解 [jinja2 模板的语法](http://docs.jinkan.org/docs/jinja2/templates.html) 。
* 选择一个 xls/x 文件作为模板。
* 在单元格中插入变量:
```jinja2
{{name}}
```* 在单元格中插入控制语句:
```jinja2
{%- for row in rows %}
{% set outer_loop = loop %}{% for row in rows %}
Cell
{{outer_loop.index}}{{loop.index}}
{%+ endfor%}{%+ endfor%}
```* Java code
```java
import io.github.zhangyu836.xltpl.BookWriter;
``````java
BookWriter bookWriter = new BookWriter();
bookWriter.load(fileName);
Map context = new HashMap<>();
context.put("name", "Hello Wizard");
context.put("address", "Somewhere over the rainbow");
context.put("date", new Date());
context.put("items", items);
bookWriter.renderSheet(context);
bookWriter.save(outFileName);
```> 参见 [示例](https://github.com/zhangyu836/xltpl4java/tree/main/example/src/main/java) 。
## 实现方法
xls/x 文件的每个工作表会被转换为一棵树。
树会被转换为带有自定义 tag 的 jinja2 模板。
渲染模板时,自定义 tag 所对应的 jinja2 扩展调用相应的树节点来写入 xls/x 文件。## 相关
* [xtpl for python](https://github.com/zhangyu836/xltpl)