文字的樣式。
如果對應的 TextRange
跨越多個文字執行,這個類別中的讀取方法會傳回 null
,而這些執行作業對於呼叫的讀取方法具有不同的值。為避免這種情況,請使用 TextRange.getRuns()
方法傳回的 TextRange
查詢文字樣式。
如果您使用的方法會編輯圖案中的文字配合效果,則套用至文字樣式的所有自動調整設定都會停用。
方法
內容詳盡的說明文件
getBackgroundColor()
getBaselineOffset()
傳回文字在一般位置中的垂直偏移;如果文字有多種樣式,則傳回 null
。
回攻員
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
getFontFamily()
傳回文字的字型系列;如果文字有多種樣式,則傳回 null
。
回攻員
String
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
getFontSize()
傳回點中的文字字型大小;如果文字有多種樣式,則傳回 null
。
回攻員
Number
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
getFontWeight()
傳回文字的字型粗細;如果文字有多種樣式,則傳回 null
。
權重為 100 和 900 (含) 之間的倍數。這個範圍對應於 CSS 2.1 規格第 15.6 節中所述的數值,但不允許使用非數值。大於或等於 700 的權重會視為粗體,因此 isBold()
會傳回 true
。預設值為 400 (「normal」)。
回攻員
Integer
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
getForegroundColor()
getLink()
傳回文字中的 Link
;如果沒有連結,或連結位於文字部分,或有多個連結,則傳回 null
。呼叫 hasLink()
,判斷文字是否沒有連結。
var textLink = shape.getText().getTextStyle().getLink(); if (textLink != null) { Logger.log('Shape text has a link of type: ' + textLink.getLinkType()); }
回攻員
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
hasLink()
isBackgroundTransparent()
如果文字背景為透明,true
會傳回 false
;如果不是,則傳回 null
。
回攻員
Boolean
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
isBold()
如果文字呈現為粗體,true
會傳回 false
;如果文字有多種樣式,則傳回 null
。
回攻員
Boolean
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
isItalic()
如果文字是斜體,會傳回 true
;如果不是斜體,則傳回 false
;如果文字有多種樣式,則傳回 null
。
回攻員
Boolean
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
isSmallCaps()
如果文字有小大寫字母,傳回 true
;如果不是,則傳回 false
;如果文字有多種樣式,則傳回 null
。
回攻員
Boolean
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
isStrikethrough()
如果文字有加上刪除線,則傳回 true
;如果不是,則傳回 false
;如果文字有多種樣式,則傳回 null
。
回攻員
Boolean
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
isUnderline()
如果文字加上底線,則傳回 true
;如果沒有加上底線,則傳回 false
;如果文字有多種樣式,則傳回 null
。
回攻員
Boolean
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
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 | ThemeColorType |
回攻員
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
setBackgroundColorTransparent()
setBaselineOffset(offset)
設定文字相對於一般位置的垂直位移。
參數
名稱 | 類型 | 說明 |
---|---|---|
offset | TextBaselineOffset |
回攻員
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
setBold(bold)
setFontFamily(fontFamily)
setFontFamilyAndWeight(fontFamily, fontWeight)
設定文字的字型系列和粗細。
權重為 100 和 900 (含) 之間的倍數。這個範圍對應於 CSS 2.1 規格第 15.6 節中所述的數值,但不允許使用非數值。大於或等於 700 的權重會視為粗體,因此 isBold()
會傳回 true
。預設值為 400 (「normal」)。
參數
名稱 | 類型 | 說明 |
---|---|---|
fontFamily | String | |
fontWeight | Integer |
回攻員
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
setFontSize(fontSize)
setForegroundColor(foregroundColor)
setForegroundColor(red, green, blue)
setForegroundColor(hexColor)
setForegroundColor(color)
將文字的前景顏色設為指定的 ThemeColorType
。
參數
名稱 | 類型 | 說明 |
---|---|---|
color | ThemeColorType |
回攻員
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
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. text.getTextStyle().setLinkSlide(0);
參數
名稱 | 類型 | 說明 |
---|---|---|
slideIndex | Integer | 投影片的索引值 (從零開始)。 |
回攻員
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
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. var slide = presentation.getSlides()[0]; text.getTextStyle().setLinkSlide(slide);
參數
名稱 | 類型 | 說明 |
---|---|---|
slide | Slide | 要連結的「Slide 」。 |
回攻員
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
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. text.getTextStyle().setLinkSlide(SlidesApp.SlidePosition.FIRST_SLIDE);
參數
名稱 | 類型 | 說明 |
---|---|---|
slidePosition | SlidePosition | 相對 SlidePosition 。 |
回攻員
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
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. text.getTextStyle().setLinkUrl("https://slides.google.com");
參數
名稱 | 類型 | 說明 |
---|---|---|
url | String | 網址字串。 |
回攻員
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations