文本的样式。
如果相应的 TextRange 跨越多个文本运行,并且这些运行对于所调用的读取方法具有不同的值,则此类中的读取方法会返回 null。为避免这种情况,请使用 TextRange.getRuns() 方法返回的 TextRange 查询文本样式。
如果您使用的方法会修改文字在形状中的排布方式,则应用于文字样式的任何自动调整设置都会停用。
方法
| 方法 | 返回类型 | 简介 |
|---|---|---|
get | Color|null | 返回文本的背景颜色,如果文本具有多种样式,则返回 null。 |
get | Text | 返回文本相对于其正常位置的垂直偏移量;如果文本具有多种样式,则返回 null。 |
get | String|null | 返回文本的字体系列;如果文本具有多种样式,则返回 null。 |
get | Number|null | 返回文本的字体大小(以磅为单位),如果文本具有多种样式,则返回 null。 |
get | Integer|null | 返回文本的字体粗细,如果文本具有多种样式,则返回 null。 |
get | Color|null | 返回文本的前景色,如果文本具有多种样式,则返回 null。 |
get | Link|null | 返回文本中的 Link,如果没有链接、链接位于部分文本中或有多重关联,则返回 null。 |
has | Boolean|null | 如果文本中存在链接,则返回 true;如果不存在,则返回 false;如果链接位于部分文本中或存在多个链接,则返回 null。 |
is | Boolean|null | 如果文本的背景是透明的,则返回 true;如果不是,则返回 false;如果文本具有多种样式,则返回 null。 |
is | Boolean|null | 如果文本以粗体呈现,则返回 true;如果不是,则返回 false;如果文本具有多种样式,则返回 null。 |
is | Boolean|null | 如果文本为斜体,则返回 true;如果不是,则返回 false;如果文本具有多种样式,则返回 null。 |
is | Boolean|null | 如果文本采用小型大写字母,则返回 true;否则返回 false;如果文本采用多种样式,则返回 null。 |
is | Boolean|null | 如果文本带有删除线,则返回 true;如果文本不带删除线,则返回 false;如果文本具有多种样式,则返回 null。 |
is | Boolean|null | 如果文本带有下划线,则返回 true;如果文本不带下划线,则返回 false;如果文本具有多种样式,则返回 null。 |
remove | Text | 移除 Link。 |
set | Text | 设置文字的背景颜色。 |
set | Text | 将文本的背景颜色设置为给定的 RGB 值(介于 0 到 255 之间)。 |
set | Text | 将文本的背景颜色设置为给定的十六进制颜色字符串。 |
set | Text | 将文本的背景颜色设置为给定的 Theme。 |
set | Text | 将文本的背景颜色设置为透明。 |
set | Text | 设置文本相对于其正常位置的垂直偏移量。 |
set | Text | 设置文本是否应以粗体呈现。 |
set | Text | 设置文本的字体系列。 |
set | Text | 设置文本的字体系列和粗细。 |
set | Text | 设置文字的字体大小(以磅为单位)。 |
set | Text | 设置文本的前景色。 |
set | Text | 将文本的前景色设置为给定的 RGB 值(介于 0 到 255 之间)。 |
set | Text | 将文本的前景颜色设置为给定的十六进制颜色字符串。 |
set | Text | 将文本的前景色设置为给定的 Theme。 |
set | Text | 设置文本是否为斜体。 |
set | Text | 使用幻灯片的从零开始的索引,将 Link 设置为给定的 Slide。 |
set | Text | 将 Link 设置为给定的 Slide,链接由给定的幻灯片 ID 设置。 |
set | Text | 使用幻灯片的相对位置,将 Link 设置为给定的 Slide。 |
set | Text | 将 Link 设置为给定的非空网址字符串。 |
set | Text | 设置文本是否以小型大写字母呈现。 |
set | Text | 设置文本是否带有删除线。 |
set | Text | 设置文本是否带下划线。 |
详细文档
getBackgroundColor()
getBaselineOffset()
返回文本相对于其正常位置的垂直偏移量;如果文本具有多种样式,则返回 null。
返回
TextBaselineOffset|null - 文字相对于其正常位置的垂直偏移量。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getFontFamily()
返回文本的字体系列;如果文本具有多种样式,则返回 null。
返回
String|null - 文本的字体系列。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getFontSize()
返回文本的字体大小(以磅为单位),如果文本具有多种样式,则返回 null。
返回
Number|null - 文字的字体大小(以磅为单位)。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getFontWeight()
返回文本的字体粗细,如果文本具有多种样式,则返回 null。
权重是 100 到 900(含)之间的 100 的倍数。此范围对应于 CSS 2.1 规范第 15.6 节中描述的数值,不允许使用非数值。如果权重大于或等于 700,则视为粗体,在这种情况下,isBold() 会返回 true。默认值为 400(“正常”)。
返回
Integer|null - 文本的字体粗细。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getForegroundColor()
getLink()
返回文本中的 Link,如果没有链接、链接位于部分文本中或有多重关联,则返回 null。调用 hasLink() 以确定文本是否没有链接。
const shape = SlidesApp.getActivePresentation().getSlides()[0].getShapes()[0]; const textLink = shape.getText().getTextStyle().getLink(); if (textLink != null) { Logger.log(`Shape text has a link of type: ${textLink.getLinkType()}`); }
返回
Link|null - 文本中的链接。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
hasLink()
isBackgroundTransparent()
如果文本的背景是透明的,则返回 true;如果不是,则返回 false;如果文本具有多种样式,则返回 null。
返回
Boolean|null - 文本的背景是否透明。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
isBold()
如果文本以粗体呈现,则返回 true;如果不是,则返回 false;如果文本具有多种样式,则返回 null。
返回
Boolean|null - 文本是否以粗体呈现。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
isItalic()
如果文本为斜体,则返回 true;如果不是,则返回 false;如果文本具有多种样式,则返回 null。
返回
Boolean|null - 文本是否为斜体。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
isSmallCaps()
如果文本采用小型大写字母,则返回 true;否则返回 false;如果文本采用多种样式,则返回 null。
返回
Boolean|null - 文本是否采用小型大写字母。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
isStrikethrough()
如果文本带有删除线,则返回 true;如果文本不带删除线,则返回 false;如果文本具有多种样式,则返回 null。
返回
Boolean|null - 文本是否带有删除线。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
isUnderline()
如果文本带有下划线,则返回 true;如果文本不带下划线,则返回 false;如果文本具有多种样式,则返回 null。
返回
Boolean|null - 文本是否带下划线。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
removeLink()
setBackgroundColor(color)
setBackgroundColor(red, green, blue)
setBackgroundColor(hexColor)
setBackgroundColor(color)
将文本的背景颜色设置为给定的 ThemeColorType。
参数
| 名称 | 类型 | 说明 |
|---|---|---|
color | Theme | 主题颜色类型。 |
返回
TextStyle - 此 TextStyle,用于链式调用。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
setBackgroundColorTransparent()
setBaselineOffset(offset)
设置文本相对于其正常位置的垂直偏移量。
参数
| 名称 | 类型 | 说明 |
|---|---|---|
offset | Text | 要设置的基准偏移量。 |
返回
TextStyle - 此 TextStyle,用于链式调用。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
setBold(bold)
setFontFamily(fontFamily)
setFontFamilyAndWeight(fontFamily, fontWeight)
setFontSize(fontSize)
setForegroundColor(foregroundColor)
setForegroundColor(red, green, blue)
setForegroundColor(hexColor)
setForegroundColor(color)
将文本的前景色设置为给定的 ThemeColorType。
参数
| 名称 | 类型 | 说明 |
|---|---|---|
color | Theme | 主题颜色类型。 |
返回
TextStyle - 此 TextStyle,用于链式调用。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
setItalic(italic)
setLinkSlide(slideIndex)
使用幻灯片的从零开始的索引,将 Link 设置为给定的 Slide。
设置链接会将文本的样式更改为加下划线并具有 ThemeColorType.HYPERLINK 前景色。您可以通过 setForegroundColor(hexColor) 和 setUnderline(underline) 更改此设置。
由于无法在换行符上设置链接,因此系统会忽略 TextRange 中的换行符。
// Set a link to the first slide of the presentation. const presentation = SlidesApp.getActivePresentation(); const slide = presentation.getSlides()[0]; const textRange = slide.getShapes()[0].getText(); textRange.getTextStyle().setLinkSlide(0);
参数
| 名称 | 类型 | 说明 |
|---|---|---|
slide | Integer | 幻灯片的索引(从零开始)。 |
返回
TextStyle - 此 TextStyle,用于链式调用。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
setLinkSlide(slide)
将 Link 设置为给定的 Slide,链接由给定的幻灯片 ID 设置。
设置链接会将文本的样式更改为加下划线并具有 ThemeColorType.HYPERLINK 前景色。您可以通过 setForegroundColor(hexColor) 和 setUnderline(underline) 更改此设置。
由于无法在换行符上设置链接,因此系统会忽略 TextRange 中的换行符。
// Set a link to the first slide of the presentation. const presentation = SlidesApp.getActivePresentation(); const slide = presentation.getSlides()[0]; const textRange = slide.getShapes()[0].getText(); textRange.getTextStyle().setLinkSlide(slide);
参数
| 名称 | 类型 | 说明 |
|---|---|---|
slide | Slide | 要关联的 Slide。 |
返回
TextStyle - 此 TextStyle,用于链式调用。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
setLinkSlide(slidePosition)
使用幻灯片的相对位置,将 Link 设置为给定的 Slide。
设置链接会将文本的样式更改为加下划线并具有 ThemeColorType.HYPERLINK 前景色。您可以通过 setForegroundColor(hexColor) 和 setUnderline(underline) 更改此设置。
由于无法在换行符上设置链接,因此系统会忽略 TextRange 中的换行符。
// Set a link to the first slide of the presentation. const textRange = SlidesApp.getActivePresentation().getSlides()[0].getShapes()[0].getText(); textRange.getTextStyle().setLinkSlide(SlidesApp.SlidePosition.FIRST_SLIDE);
参数
| 名称 | 类型 | 说明 |
|---|---|---|
slide | Slide | 相对 Slide。 |
返回
TextStyle - 此 TextStyle,用于链式调用。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
setLinkUrl(url)
将 Link 设置为给定的非空网址字符串。
设置链接会将文本的样式更改为加下划线并具有 ThemeColorType.HYPERLINK 前景色。您可以通过 setForegroundColor(hexColor) 和 setUnderline(underline) 更改此设置。
由于无法在换行符上设置链接,因此系统会忽略 TextRange 中的换行符。
// Set a link to the URL. const textRange = SlidesApp.getActivePresentation().getSlides()[0].getShapes()[0].getText(); textRange.getTextStyle().setLinkUrl('https://slides.google.com');
参数
| 名称 | 类型 | 说明 |
|---|---|---|
url | String | 网址字符串。 |
返回
TextStyle - 此 TextStyle,用于链式调用。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations