数据读写
写入 Excel
type excelWrite
把 List<Map> / List<List> 写成 xls/xlsx
使用说明
要点:把 List<Map> 或 List<List> 写成 Excel;path 是目录时与 fileName 拼接,fileName 支持 Simple。示例先把 JSON 数组转成 List。
属性
| 字段 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
path目标路径 |
文本 | 必填 | — | /data/out.xlsx 或 /data/ |
fileName文件名 |
文本 | 可选 | — | order-${header.id}.xlsx |
engine引擎 |
枚举 | 可选 | auto |
|
sheet工作表 |
文本 | 可选 | — | Sheet1 |
headers表头 |
字符串数组 | 可选 | — | name, age;缺省取首个 Map 的 key |
append追加到已有文件 |
布尔 | 可选 | false |
|
autoSize自动列宽 |
布尔 | 可选 | false |
示例流程
可直接保存为 demo-excelWrite.json 并部署;非入口节点默认套了一个 REST 入口。
{
"id": "demo-excelWrite",
"desc": "写入 Excel 示例",
"group": "示例/数据读写",
"schemaVersion": 1,
"nodes": [
{
"id": "n1",
"type": "rest",
"props": {
"method": "POST",
"path": "/demo/excelWrite",
"desc": "示例入口"
}
},
{
"type": "unmarshal",
"props": {
"format": "json",
"type": "java.util.List"
},
"id": "n1"
},
{
"type": "excelWrite",
"props": {
"path": "./data/out",
"fileName": "users-${header.id}.xlsx",
"engine": "poi",
"sheet": "用户",
"headers": [
"id",
"name",
"level"
],
"autoSize": true
},
"id": "n2"
},
{
"type": "log",
"props": {
"message": "已写出 Excel:users-${header.id}.xlsx",
"level": "INFO"
},
"id": "n3"
}
]
}
curl -X POST 'http://localhost:8086/flow' \
-H 'Content-Type: application/json' \
-H 'X-Flow-Token: change-me' \
--data-binary @demo-excelWrite.json
调用方式
curl -X POST 'http://localhost:8086/demo/excelWrite' \
-H 'Content-Type: application/json' \
-d '[{"id":1,"name":"alice","level":2},{"id":2,"name":"bob","level":1}]'