PPTX
线条与连接符
在元素之间添加线条和连接符形状
使用 line 属性绘制直线,使用 connector 属性绘制带箭头的连接线。
线条形状
线条使用起止点坐标:
{
"slides": [
{
"children": [
{
"line": {
"x1": 50,
"y1": 120,
"x2": 800,
"y2": 120,
"outline": { "color": "4472C4", "width": 2 }
}
}
]
}
]
}
import { generatePresentation } from "@office-open/pptx";
generatePresentation({
slides: [
{
children: [
{
line: {
x1: 50,
y1: 120,
x2: 800,
y2: 120,
outline: { color: "4472C4", width: 2 },
},
},
],
},
],
});
垂直线
{
"slides": [
{
"children": [
{
"line": {
"x1": 200,
"y1": 150,
"x2": 200,
"y2": 450,
"outline": { "color": "ED7D31", "width": 2 }
}
}
]
}
]
}
import { generatePresentation } from "@office-open/pptx";
generatePresentation({
slides: [
{
children: [
{
line: {
x1: 200,
y1: 150,
x2: 200,
y2: 450,
outline: { color: "ED7D31", width: 2 },
},
},
],
},
],
});
对角线
{
"slides": [
{
"children": [
{
"line": {
"x1": 250,
"y1": 150,
"x2": 750,
"y2": 450,
"outline": { "color": "70AD47", "width": 3 }
}
}
]
}
]
}
import { generatePresentation } from "@office-open/pptx";
generatePresentation({
slides: [
{
children: [
{
line: {
x1: 250,
y1: 150,
x2: 750,
y2: 450,
outline: { color: "70AD47", width: 3 },
},
},
],
},
],
});
带箭头的连接符
连接符支持箭头端点:
{
"slides": [
{
"children": [
{
"connector": {
"x1": 50,
"y1": 130,
"x2": 400,
"y2": 130,
"endArrowhead": "triangle",
"outline": { "color": "4472C4", "width": 2 }
}
},
{
"connector": {
"x1": 50,
"y1": 200,
"x2": 400,
"y2": 200,
"beginArrowhead": "triangle",
"endArrowhead": "triangle",
"outline": { "color": "ED7D31", "width": 2 }
}
}
]
}
]
}
import { generatePresentation } from "@office-open/pptx";
generatePresentation({
slides: [
{
children: [
{
connector: {
x1: 50,
y1: 130,
x2: 400,
y2: 130,
endArrowhead: "triangle",
outline: { color: "4472C4", width: 2 },
},
},
{
connector: {
x1: 50,
y1: 200,
x2: 400,
y2: 200,
beginArrowhead: "triangle",
endArrowhead: "triangle",
outline: { color: "ED7D31", width: 2 },
},
},
],
},
],
});
箭头类型
| 值 | 说明 |
|---|---|
"triangle" | 实心三角形 |
"stealth" | 隐形箭头 |
"diamond" | 菱形 |
"oval" | 椭圆形 |
"open" | 开放箭头 |
"none" | 无箭头 |
箭头还支持尺寸控制:
{
"slides": [
{
"children": [
{
"connector": {
"x1": 500,
"y1": 410,
"x2": 800,
"y2": 410,
"endArrowhead": "triangle",
"arrowheadWidth": "large",
"arrowheadLength": "large",
"outline": { "color": "ED7D31", "width": 2 }
}
}
]
}
]
}
import { generatePresentation } from "@office-open/pptx";
generatePresentation({
slides: [
{
children: [
{
connector: {
x1: 500,
y1: 410,
x2: 800,
y2: 410,
endArrowhead: "triangle",
arrowheadWidth: "large",
arrowheadLength: "large",
outline: { color: "ED7D31", width: 2 },
},
},
],
},
],
});
line 选项
| 属性 | 类型 | 说明 |
|---|---|---|
x1 | number | 起始 X 坐标 |
y1 | number | 起始 Y 坐标 |
x2 | number | 结束 X 坐标 |
y2 | number | 结束 Y 坐标 |
fill | FillOptions | 线条填充 |
outline | OutlineOptions | 轮廓(颜色、宽度、虚线样式) |
connector 选项
| 属性 | 类型 | 说明 |
|---|---|---|
x1 | number | 起始 X 坐标 |
y1 | number | 起始 Y 坐标 |
x2 | number | 结束 X 坐标 |
y2 | number | 结束 Y 坐标 |
fill | FillOptions | 线条填充 |
outline | OutlineOptions | 轮廓(颜色、宽度、虚线样式) |
beginArrowhead | ArrowheadType | 起始箭头 |
endArrowhead | ArrowheadType | 结束箭头 |
arrowheadWidth | "small" | "medium" | "large" | 箭头宽度 |
arrowheadLength | "small" | "medium" | "large" | 箭头长度 |
OutlineOptions
| 属性 | 类型 | 说明 |
| ----------- | --------------------------------------------------------------------- | ----------------- | -------- |
| color | string | 十六进制颜色 |
| width | number | UniversalMeasure | 线条宽度 |
| dashStyle | "solid" \| "dash" \| "dashDot" \| "lgDash" \| "sysDot" \| "sysDash" | 虚线样式 |