Class TextStyle

TextStyle

文字的樣式。

如果對應的 TextRange 跨越多個文字執行,這個類別中的讀取方法會傳回 null,而這些執行作業對於呼叫的讀取方法具有不同的值。為避免這種情況,請使用 TextRange.getRuns() 方法傳回的 TextRange 查詢文字樣式。

如果您使用的方法會編輯圖案中的文字配合效果,則套用至文字樣式的所有自動調整設定都會停用。

方法

方法傳回類型簡短說明
getBackgroundColor()Color傳回文字的背景顏色;如果文字有多種樣式,則傳回 null
getBaselineOffset()TextBaselineOffset傳回文字在一般位置中的垂直偏移;如果文字有多種樣式,則傳回 null
getFontFamily()String傳回文字的字型系列;如果文字有多種樣式,則傳回 null
getFontSize()Number傳回點中的文字字型大小;如果文字有多種樣式,則傳回 null
getFontWeight()Integer傳回文字的字型粗細;如果文字有多種樣式,則傳回 null
getForegroundColor()Color傳回文字的前景顏色;如果文字有多種樣式,則傳回 null
getLink()Link傳回文字中的 Link;如果沒有連結,或連結位於文字部分,或有多個連結,則傳回 null
hasLink()Boolean如果文字中有連結,則傳回 true;如果文字不是連結,則傳回 false;如果連結位於文字部分或有多個連結,則傳回 null
isBackgroundTransparent()Boolean如果文字背景為透明,true 會傳回 false;如果不是,則傳回 null
isBold()Boolean如果文字呈現為粗體,true會傳回 false;如果文字有多種樣式,則傳回 null
isItalic()Boolean如果文字是斜體,會傳回 true;如果不是斜體,則傳回 false;如果文字有多種樣式,則傳回 null
isSmallCaps()Boolean如果文字有小大寫字母,傳回 true;如果不是,則傳回 false;如果文字有多種樣式,則傳回 null
isStrikethrough()Boolean如果文字有加上刪除線,則傳回 true;如果不是,則傳回 false;如果文字有多種樣式,則傳回 null
isUnderline()Boolean如果文字加上底線,則傳回 true;如果沒有加上底線,則傳回 false;如果文字有多種樣式,則傳回 null
removeLink()TextStyle移除 Link
setBackgroundColor(color)TextStyle設定文字的背景顏色。
setBackgroundColor(red, green, blue)TextStyle將文字的背景顏色設為從 0 到 255 之間的指定 RGB 值。
setBackgroundColor(hexColor)TextStyle將文字的背景顏色設為指定的十六進位顏色字串。
setBackgroundColor(color)TextStyle將文字的背景顏色設為指定的 ThemeColorType
setBackgroundColorTransparent()TextStyle將文字背景顏色設為透明。
setBaselineOffset(offset)TextStyle設定文字相對於一般位置的垂直位移。
setBold(bold)TextStyle設定文字是否應以粗體顯示。
setFontFamily(fontFamily)TextStyle設定文字的字型系列。
setFontFamilyAndWeight(fontFamily, fontWeight)TextStyle設定文字的字型系列和粗細。
setFontSize(fontSize)TextStyle設定文字的字型大小,以點為單位。
setForegroundColor(foregroundColor)TextStyle設定文字的前景顏色。
setForegroundColor(red, green, blue)TextStyle將文字的前景顏色設為指定的 RGB 值,範圍從 0 到 255。
setForegroundColor(hexColor)TextStyle將文字的前景顏色設為指定的十六進位顏色字串。
setForegroundColor(color)TextStyle將文字的前景顏色設為指定的 ThemeColorType
setItalic(italic)TextStyle設定文字是否採用斜體。
setLinkSlide(slideIndex)TextStyle使用投影片的索引 (從零開始),將 Link 設為指定的 Slide
setLinkSlide(slide)TextStyleLink 設為指定的 Slide,連結是由指定的投影片 ID 設定。
setLinkSlide(slidePosition)TextStyle使用投影片的相對位置,將 Link 設為指定的 Slide
setLinkUrl(url)TextStyleLink 設為指定的非空白網址字串。
setSmallCaps(smallCaps)TextStyle設定文字是否以小大寫字母顯示。
setStrikethrough(strikethrough)TextStyle設定文字是否啟用。
setUnderline(underline)TextStyle設定文字是否加上底線。

內容詳盡的說明文件

getBackgroundColor()

傳回文字的背景顏色;如果文字有多種樣式,則傳回 null

回攻員

Color

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

getBaselineOffset()

傳回文字在一般位置中的垂直偏移;如果文字有多種樣式,則傳回 null

回攻員

TextBaselineOffset

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • 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()

傳回文字的前景顏色;如果文字有多種樣式,則傳回 null

回攻員

Color

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

傳回文字中的 Link;如果沒有連結,或連結位於文字部分,或有多個連結,則傳回 null。呼叫 hasLink(),判斷文字是否沒有連結。

var textLink = shape.getText().getTextStyle().getLink();
if (textLink != null) {
  Logger.log('Shape text has a link of type: ' + textLink.getLinkType());
}

回攻員

Link

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

如果文字中有連結,則傳回 true;如果文字不是連結,傳回 false;如果連結位於文字部分或有多個連結,則傳回 null

換行字元不能設定連結。因此,如果 TextRange 包含換行字元,這個方法一律會傳回 nullfalse

回攻員

Boolean

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

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

移除 Link

移除連結後,文字上的超連結前景顏色和底線樣式都會移除。如果可能的話,這些樣式就會與連結前的文字相符。

text.getTextStyle().removeLink();

回攻員

TextStyle


setBackgroundColor(color)

設定文字的背景顏色。

參數

名稱類型說明
colorColor

回攻員

TextStyle

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setBackgroundColor(red, green, blue)

將文字的背景顏色設為從 0 到 255 之間的指定 RGB 值。

參數

名稱類型說明
redInteger
greenInteger
blueInteger

回攻員

TextStyle

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setBackgroundColor(hexColor)

將文字的背景顏色設為指定的十六進位顏色字串。

十六進位字串必須採用「#RRGGBB」的格式。舉例來說,粉紅色的表示法為「#FFC0CB」。

參數

名稱類型說明
hexColorString

回攻員

TextStyle

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setBackgroundColor(color)

將文字的背景顏色設為指定的 ThemeColorType

參數

名稱類型說明
colorThemeColorType

回攻員

TextStyle

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setBackgroundColorTransparent()

將文字背景顏色設為透明。

回攻員

TextStyle

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setBaselineOffset(offset)

設定文字相對於一般位置的垂直位移。

參數

名稱類型說明
offsetTextBaselineOffset

回攻員

TextStyle

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setBold(bold)

設定文字是否應以粗體顯示。

變更文字的粗體度會更新用於轉譯文字的字型粗細。

參數

名稱類型說明
boldBoolean

回攻員

TextStyle

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setFontFamily(fontFamily)

設定文字的字型系列。

參數

名稱類型說明
fontFamilyString

回攻員

TextStyle

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setFontFamilyAndWeight(fontFamily, fontWeight)

設定文字的字型系列和粗細。

權重為 100 和 900 (含) 之間的倍數。這個範圍對應於 CSS 2.1 規格第 15.6 節中所述的數值,但不允許使用非數值。大於或等於 700 的權重會視為粗體,因此 isBold() 會傳回 true。預設值為 400 (「normal」)。

參數

名稱類型說明
fontFamilyString
fontWeightInteger

回攻員

TextStyle

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setFontSize(fontSize)

設定文字的字型大小,以點為單位。

參數

名稱類型說明
fontSizeNumber

回攻員

TextStyle

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setForegroundColor(foregroundColor)

設定文字的前景顏色。

參數

名稱類型說明
foregroundColorColor

回攻員

TextStyle

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setForegroundColor(red, green, blue)

將文字的前景顏色設為指定的 RGB 值,範圍從 0 到 255。

參數

名稱類型說明
redInteger
greenInteger
blueInteger

回攻員

TextStyle

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setForegroundColor(hexColor)

將文字的前景顏色設為指定的十六進位顏色字串。

十六進位字串必須採用「#RRGGBB」的格式。舉例來說,粉紅色的表示法為「#FFC0CB」。

參數

名稱類型說明
hexColorString

回攻員

TextStyle

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setForegroundColor(color)

將文字的前景顏色設為指定的 ThemeColorType

參數

名稱類型說明
colorThemeColorType

回攻員

TextStyle

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setItalic(italic)

設定文字是否採用斜體。

參數

名稱類型說明
italicBoolean

回攻員

TextStyle

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

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);

參數

名稱類型說明
slideIndexInteger投影片的索引值 (從零開始)。

回攻員

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.
var slide = presentation.getSlides()[0];
text.getTextStyle().setLinkSlide(slide);

參數

名稱類型說明
slideSlide要連結的「Slide」。

回攻員

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.
text.getTextStyle().setLinkSlide(SlidesApp.SlidePosition.FIRST_SLIDE);

參數

名稱類型說明
slidePositionSlidePosition相對 SlidePosition

回攻員

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.
text.getTextStyle().setLinkUrl("https://slides.google.com");

參數

名稱類型說明
urlString網址字串。

回攻員

TextStyle

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setSmallCaps(smallCaps)

設定文字是否以小大寫字母顯示。

參數

名稱類型說明
smallCapsBoolean

回攻員

TextStyle

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setStrikethrough(strikethrough)

設定文字是否啟用。

參數

名稱類型說明
strikethroughBoolean

回攻員

TextStyle

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setUnderline(underline)

設定文字是否加上底線。

參數

名稱類型說明
underlineBoolean

回攻員

TextStyle

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations