12 KiB
文字参数 (Text Props)
文字参数来自 TextPropsOptions(继承 TextBaseProps、PositionProps、ObjectNameProps)和 TextGlowProps,用于 slide.addText() 方法。
基础文字属性 (TextBaseProps)
-
align:水平对齐方式
- 类型:
'left' | 'center' | 'right' | 'justify' - 取值范围:
left、center、right、justify - 默认值:
'left'
- 类型:
-
bold:粗体样式
- 类型:
boolean - 取值范围:
true/false - 默认值:
false
- 类型:
-
breakLine:添加换行符
- 类型:
boolean - 取值范围:
true/false - 默认值:
false
- 类型:
-
bullet:添加标准或自定义项目符号
- 类型:
boolean | BulletOptions - 取值范围:
true— 使用标准项目符号false— 无项目符号- 对象 — 自定义项目符号配置
- 默认值:
false - 子参数:
- bullet.type:项目符号类型
- 类型:
'bullet' | 'number' - 取值范围:
bullet、number - 默认值:
'bullet'
- 类型:
- bullet.characterCode:项目符号字符代码(Unicode)
- 类型:
string - 示例:
'25BA'(U+25BA 黑色右指向指针)
- 类型:
- bullet.indent:缩进量(项目符号与文字之间的距离,单位 pt)
- 类型:
number - 取值范围:任意正整数
- 默认值:
27
- 类型:
- bullet.numberType:编号类型
- 类型:
string - 取值范围:
alphaLcParenBoth|alphaLcParenR|alphaLcPeriod|alphaUcParenBoth|alphaUcParenR|alphaUcPeriod|arabicParenBoth|arabicParenR|arabicPeriod|arabicPlain|romanLcParenBoth|romanLcParenR|romanLcPeriod|romanUcParenBoth|romanUcParenR|romanUcPeriod
- 类型:
- bullet.numberStartAt:编号起始值
- 类型:
number - 取值范围:任意正整数
- 默认值:
1
- 类型:
- bullet.type:项目符号类型
- 类型:
-
color:文字颜色
- 类型:
Color(HexColor | ThemeColor) - 取值范围:6 位十六进制颜色值(不含
#)或主题色(tx1、tx2、bg1、bg2、accent1–accent6) - 示例:
'FF0000'、pptx.SchemeColor.text1
- 类型:
-
fontFace:字体名称
- 类型:
string - 示例:
'Arial'、'微软雅黑'
- 类型:
-
fontSize:字号
- 类型:
number - 取值范围:
1–400(pt) - 示例:
12、24
- 类型:
-
highlight:文字高亮颜色
- 类型:
HexColor - 格式:6 位十六进制颜色值(不含
#) - 示例:
'FFFF00'(黄色)
- 类型:
-
italic:斜体样式
- 类型:
boolean - 取值范围:
true/false - 默认值:
false
- 类型:
-
lang:语言
- 类型:
string - 取值范围:ISO 639-1 标准语言代码
- 默认值:
'en-US' - 示例:
'fr-CA'
- 类型:
-
softBreakBefore:在文字内容前添加软换行(Shift+Enter)
- 类型:
boolean - 取值范围:
true/false - 默认值:
false - 始于:v3.5.0
- 类型:
-
tabStops:制表位
- 类型:
Array<{ position: number, alignment?: 'l' | 'r' | 'ctr' | 'dec' }> - 说明:PowerPoint 段落 > 制表位 > 制表位位置
- 示例:
[{ position: 1 }, { position: 3 }] - 子参数:
- position:制表位位置(英寸)
- alignment:对齐方式(可选),
'l'(左)、'r'(右)、'ctr'(居中)、'dec'(小数点)
- 类型:
-
textDirection:文字方向
- 类型:
'horz' | 'vert' | 'vert270' | 'wordArtVert' - 取值范围:
horz— 水平vert— 旋转 90 度vert270— 旋转 270 度wordArtVert— 堆叠
- 默认值:
'horz'
- 类型:
-
transparency:透明度
- 类型:
number - 取值范围:
0–100(百分比) - 默认值:
0
- 类型:
-
underline:下划线属性
- 类型:
{ style?: string, color?: Color } - 子参数:
- underline.style:下划线样式
- 类型:
string - 取值范围:
'dash'|'dashHeavy'|'dashLong'|'dashLongHeavy'|'dbl'|'dotDash'|'dotDashHeave'|'dotDotDash'|'dotDotDashHeavy'|'dotted'|'dottedHeavy'|'heavy'|'none'|'sng'|'wavy'|'wavyDbl'|'wavyHeavy'
- 类型:
- underline.color:下划线颜色
- 类型:
Color
- 类型:
- underline.style:下划线样式
- 类型:
-
valign:垂直对齐
- 类型:
'top' | 'middle' | 'bottom' - 取值范围:
top、middle、bottom - 默认值:
'top'
- 类型:
文字专有属性 (TextPropsOptions 特有)
-
baseline:基线偏移
- 类型:
number
- 类型:
-
charSpacing:字符间距
- 类型:
number
- 类型:
-
fit:文本适配方式
- 类型:
'none' | 'shrink' | 'resize' - 取值范围:
none— 不自动调整shrink— 溢出时缩小文字resize— 调整形状以适配文字
- 默认值:
'none' - 始于:v3.3.0
- 类型:
-
fill:形状填充
- 类型:
ShapeFillProps - 子参数:
- fill.color:填充颜色
- 类型:
Color - 格式:
HexColor(6 位十六进制无#)或ThemeColor
- 类型:
- fill.transparency:透明度
- 类型:
number - 取值范围:
0–100 - 默认值:
0
- 类型:
- fill.type:填充类型
- 类型:
'none' | 'solid' - 默认值:
'solid'
- 类型:
- fill.color:填充颜色
- 类型:
-
flipH:水平翻转
- 类型:
boolean - 取值范围:
true/false - 默认值:
false
- 类型:
-
flipV:垂直翻转
- 类型:
boolean - 取值范围:
true/false - 默认值:
false
- 类型:
-
glow:发光效果
- 类型:
TextGlowProps - 子参数:
- glow.color:发光颜色
- 类型:
HexColor - 格式:6 位十六进制(无
#)
- 类型:
- glow.opacity:不透明度
- 类型:
number - 取值范围:
0.0–1.0
- 类型:
- glow.size:发光大小
- 类型:
number - 单位:pt
- 类型:
- glow.color:发光颜色
- 类型:
-
hyperlink:超链接
- 类型:
HyperlinkProps - 子参数:
- hyperlink.slide:链接到页码
- 类型:
number
- 类型:
- hyperlink.url:链接 URL
- 类型:
string
- 类型:
- hyperlink.tooltip:超链接提示
- 类型:
string
- 类型:
- hyperlink.slide:链接到页码
- 类型:
-
indentLevel:缩进层级
- 类型:
number
- 类型:
-
isTextBox:是否为文本框
- 类型:
boolean
- 类型:
-
line:线条(边框/轮廓线)
- 类型:
ShapeLineProps - 子参数(继承
ShapeFillProps):- line.color:线条颜色
- 类型:
Color
- 类型:
- line.transparency:线条透明度
- 类型:
number - 取值范围:
0–100
- 类型:
- line.type:填充类型
- 类型:
'none' | 'solid'
- 类型:
- line.width:线条宽度
- 类型:
number - 单位:pt
- 默认值:
1
- 类型:
- line.dashType:虚线类型
- 类型:
string - 取值范围:
'solid' | 'dash' | 'dashDot' | 'lgDash' | 'lgDashDot' | 'lgDashDotDot' | 'sysDash' | 'sysDot' - 默认值:
'solid'
- 类型:
- line.beginArrowType:起点箭头类型
- 类型:
'none' | 'arrow' | 'diamond' | 'oval' | 'stealth' | 'triangle'
- 类型:
- line.endArrowType:终点箭头类型
- 类型:
'none' | 'arrow' | 'diamond' | 'oval' | 'stealth' | 'triangle'
- 类型:
- line.color:线条颜色
- 类型:
-
lineSpacing:行间距(固定值)
- 类型:
number - 单位:pt
- 说明:PowerPoint 段落 > 缩进和间距 > 行距 > "固定值"
- 示例:
28
- 类型:
-
lineSpacingMultiple:行间距(倍数)
- 类型:
number - 取值范围:
0.0–9.99 - 单位:百分比倍数
- 说明:PowerPoint 段落 > 缩进和间距 > 行距 > "多倍行距"
- 示例:
1.5(1.5 倍行距) - 始于:v3.5.0
- 类型:
-
margin:边距
- 类型:
Margin(number | [number, number, number, number]) - 单位:pt
- 说明:PowerPoint 设置形状格式 > 形状选项 > 大小与属性 > 文本框 > 左右上下边距
- 默认值:PowerPoint 默认 "常规" 边距
- 示例:
0(四边统一)、[10, 5, 10, 5](上、右、下、左)
- 类型:
-
outline:文字轮廓
- 类型:
{ color: Color, size: number } - 子参数:
- outline.color:轮廓颜色
- 类型:
Color
- 类型:
- outline.size:轮廓大小
- 类型:
number - 单位:pt
- 类型:
- outline.color:轮廓颜色
- 类型:
-
paraSpaceAfter:段后间距
- 类型:
number
- 类型:
-
paraSpaceBefore:段前间距
- 类型:
number
- 类型:
-
placeholder:占位符类型
- 类型:
string - 示例:
'body'
- 类型:
-
rectRadius:圆角矩形半径
- 类型:
number - 取值范围:
0.0–1.0 - 默认值:
0 - 说明:仅适用于
ROUNDED_RECTANGLE形状
- 类型:
-
rotate:旋转角度
- 类型:
number - 取值范围:
-360–360(度) - 默认值:
0
- 类型:
-
rtlMode:从右向左模式
- 类型:
boolean - 取值范围:
true/false - 默认值:
false
- 类型:
-
shadow:阴影
- 类型:
ShadowProps - 子参数:
- shadow.type:阴影类型
- 类型:
'outer' | 'inner' | 'none' - 默认值:
'none'
- 类型:
- shadow.opacity:不透明度
- 类型:
number - 取值范围:
0.0–1.0
- 类型:
- shadow.blur:模糊
- 类型:
number - 取值范围:
0–100(pt) - 默认值:
0
- 类型:
- shadow.angle:角度
- 类型:
number - 取值范围:
0–359(度) - 默认值:
0
- 类型:
- shadow.offset:偏移距离
- 类型:
number - 取值范围:
0–200(pt) - 默认值:
0
- 类型:
- shadow.color:阴影颜色
- 类型:
HexColor - 格式:6 位十六进制(无
#)
- 类型:
- shadow.rotateWithShape:阴影是否随形状旋转
- 类型:
boolean - 默认值:
false
- 类型:
- shadow.type:阴影类型
- 类型:
-
shape:形状名称
- 类型:
SHAPE_NAME - 说明:将文字转为指定形状
- 类型:
-
strike:删除线
- 类型:
boolean | 'dblStrike' | 'sngStrike' - 取值范围:
true(单删除线)、false、'dblStrike'(双删除线)、'sngStrike'(单删除线)
- 类型:
-
subscript:下标
- 类型:
boolean - 取值范围:
true/false - 默认值:
false
- 类型:
-
superscript:上标
- 类型:
boolean - 取值范围:
true/false - 默认值:
false
- 类型:
-
vert:垂直文字模式
- 类型:
string - 取值范围:
'eaVert'|'horz'|'mongolianVert'|'vert'|'vert270'|'wordArtVert'|'wordArtVertRtl'
- 类型:
-
wrap:文字自动换行
- 类型:
boolean - 取值范围:
true/false - 默认值:
true - 始于:v3.3.0
- 类型:
位置属性 (PositionProps)
-
x:水平位置
- 类型:
Coord(number |${number}%``) - 单位:英寸(number)或百分比(
'50%')
- 类型:
-
y:垂直位置
- 类型:
Coord - 单位:英寸或百分比
- 类型:
-
w:宽度
- 类型:
Coord - 单位:英寸或百分比
- 类型:
-
h:高度
- 类型:
Coord - 单位:英寸或百分比
- 类型:
对象名称属性 (ObjectNameProps)
- objectName:对象名称
- 类型:
string - 说明:替代默认的 "Object N" 名称,在 PowerPoint 选择窗格中显示
- 默认值:
'Object 1' - 始于:v3.10.0
- 类型:
TextProps
- text:文字内容
- 类型:
string
- 类型:
- options:文字选项
- 类型:
TextPropsOptions
- 类型:
已废弃参数
以下参数已废弃,建议使用替代参数:
| 已废弃参数 | 替代参数 | 废弃版本 |
|---|---|---|
autoFit |
fit |
v3.3.0 |
shrinkText |
fit |
v3.3.0 |
inset |
margin |
v3.10.0 |
lineDash |
line.dashType |
v3.3.0 |
lineHead |
line.beginArrowType |
v3.3.0 |
lineSize |
line.width |
v3.3.0 |
lineTail |
line.endArrowType |
v3.3.0 |