文字樣式。
如果對應的 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 和 900) 之間的 100 倍數。這個範圍對應至 CSS 2.1 規格第 15.6 節所述的數值,且不允許非數值。如果權重大於或等於 700,系統會視為粗體,此時 isBold() 會傳回 true。預設值為 400 (「normal」)。
回攻員
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 - This TextStyle,用於鏈結。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
setBackgroundColorTransparent()
setBaselineOffset(offset)
設定文字相對於正常位置的垂直位移。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
offset | Text | 要設定的基準偏移。 |
回攻員
TextStyle - This 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 - This 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 - This TextStyle,用於鏈結。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
setLinkSlide(slide)
將指定 Slide 的 Link 設為指定投影片 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 - This TextStyle,用於鏈結。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
setLinkSlide(slidePosition)
設定連結後,文字樣式會加上底線,並採用 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 - This 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 - This TextStyle,用於鏈結。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations