DOCX
SmartArt
使用内置布局和树形数据创建 SmartArt 图形
使用 smartArt 属性向文档中添加 SmartArt 图形。
基本 SmartArt
{
"sections": [
{
"children": [
{
"paragraph": {
"children": [
{
"smartArt": {
"data": {
"nodes": [{ "text": "步骤 1" }, { "text": "步骤 2" }, { "text": "步骤 3" }]
},
"transformation": { "width": "11.9cm", "height": "6.6cm" }
}
}
]
}
}
]
}
]
}
import { generateDocument } from "@office-open/docx";
await generateDocument({
sections: [
{
children: [
{
paragraph: {
children: [
{
smartArt: {
data: {
nodes: [{ text: "步骤 1" }, { text: "步骤 2" }, { text: "步骤 3" }],
},
transformation: { width: "11.9cm", height: "6.6cm" },
},
},
],
},
},
],
},
],
});
层次数据
节点支持通过 children 嵌套,用于层次结构布局:
{
"sections": [
{
"children": [
{
"paragraph": {
"children": [
{
"smartArt": {
"data": {
"nodes": [
{
"text": "CEO",
"children": [
{
"text": "工程副总裁",
"children": [{ "text": "前端" }, { "text": "后端" }]
},
{
"text": "市场副总裁",
"children": [{ "text": "品牌" }, { "text": "增长" }]
}
]
}
]
},
"transformation": { "width": "13.2cm", "height": "9.3cm" },
"layout": "hierarchy1"
}
}
]
}
}
]
}
]
}
import { generateDocument } from "@office-open/docx";
await generateDocument({
sections: [
{
children: [
{
paragraph: {
children: [
{
smartArt: {
data: {
nodes: [
{
text: "CEO",
children: [
{
text: "工程副总裁",
children: [{ text: "前端" }, { text: "后端" }],
},
{
text: "市场副总裁",
children: [{ text: "品牌" }, { text: "增长" }],
},
],
},
],
},
transformation: { width: "13.2cm", height: "9.3cm" },
layout: "hierarchy1",
},
},
],
},
},
],
},
],
});
布局、样式和配色
通过 layout、style 和 color 自定义外观:
{
"sections": [
{
"children": [
{
"paragraph": {
"children": [
{
"smartArt": {
"data": {
"nodes": [
{ "text": "计划" },
{ "text": "设计" },
{ "text": "构建" },
{ "text": "测试" },
{ "text": "部署" }
]
},
"transformation": { "width": "14.6cm", "height": "6.6cm" },
"layout": "process1",
"style": "moderate1",
"color": "accent3_2"
}
}
]
}
}
]
}
]
}
import { generateDocument } from "@office-open/docx";
await generateDocument({
sections: [
{
children: [
{
paragraph: {
children: [
{
smartArt: {
data: {
nodes: [
{ text: "计划" },
{ text: "设计" },
{ text: "构建" },
{ text: "测试" },
{ text: "部署" },
],
},
transformation: { width: "14.6cm", height: "6.6cm" },
layout: "process1",
style: "moderate1",
color: "accent3_2",
},
},
],
},
},
],
},
],
});
布局 ID
| 类别 | 布局 ID |
|---|---|
| 默认 | "default" |
| 列表 | "list1", "list2", "vList2", "hList1", "pList1" |
| 流程 | "process1", "process2", "process3", "chevron1", "arrow1" |
| 循环 | "cycle1", "cycle2", "cycle3", "cycle4", "cycle5" |
| 层次结构 | "hierarchy1", "hierarchy2", "hierarchy3", "orgChart1" |
| 棱锥图 | "pyramid1", "pyramid2", "pyramid3" |
| 矩阵 | "matrix1", "matrix2", "matrix3" |
| 其他 | "radial1", "venn1", "funnel1", "balance1", "gear1" |
样式 ID
"simple1"–"simple5"、"moderate1"–"moderate4"、"polished1"–"polished4"、"professional1"–"professional4"
配色 ID
"accent1_2"–"accent6_2"、"colorful1"–"colorful4"、"dark1"、"dark2"、"primary1"、"primary2"、"gray1"、"gray2"
SmartArt 选项
| 选项 | 类型 | 说明 |
|---|---|---|
data | object | 树形节点数据 |
data.nodes | SmartArtNode[] | 根节点数组 |
transformation | { width, height } | 显示尺寸 |
layout | string | 布局 ID(默认:"default") |
style | string | 样式 ID(默认:"simple1") |
color | string | 配色 ID(默认:"accent1_2") |
floating | object | 浮动定位选项 |
SmartArtNode
| 属性 | 类型 | 说明 |
|---|---|---|
text | string | 显示文本 |
children | SmartArtNode[] | 子节点(可选) |