Class CellImageBuilder

CellImageBuilder

CellImage 的建構工具。這個建構工具會建立將圖片新增至儲存格所需的圖片值。

屬性

屬性類型說明
valueTypeValueType儲存格圖片的值類型,也就是 ValueType.IMAGE

方法

方法傳回類型簡短說明
build()CellImage建立將圖片新增至儲存格所需的圖片值型別。
getAltTextDescription()String傳回這張圖片的替代文字說明。
getAltTextTitle()String傳回這張圖片的替代文字標題。
getContentUrl()String傳回 Google 代管的圖片網址。
setAltTextDescription(description)CellImage設定這張圖片的替代文字說明。
setAltTextTitle(title)CellImage設定這張圖片的替代文字標題。
setSourceUrl(url)CellImageBuilder設定圖片來源網址。
toBuilder()CellImageBuilder根據目前的圖片屬性建立儲存格圖片建構工具。

內容詳盡的說明文件

build()

建立將圖片新增至儲存格所需的圖片值型別。圖片值是根據新增至建構工具的圖片屬性 (例如來源網址) 建構而成。

回攻員

CellImage:要新增至儲存格的圖片表示法。


getAltTextDescription()

傳回這張圖片的替代文字說明。

回攻員

String:替代文字說明。

授權

使用這個方法的指令碼需要下列一或多個範圍的授權:

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

getAltTextTitle()

傳回這張圖片的替代文字標題。

回攻員

String:替代文字標題。

授權

使用這個方法的指令碼需要下列一或多個範圍的授權:

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

getContentUrl()

傳回 Google 代管的圖片網址。這個網址會標記要求者的帳戶,因此只要有這個網址,就能以原始要求者的身分存取圖片。如果試算表的共用設定變更,您可能無法再存取圖片。傳回的網址會在短時間內失效。

const range = SpreadsheetApp.getActiveSpreadsheet().getRange("Sheet1!A1");
const value = range.getValue();
if (value.valueType == SpreadsheetApp.ValueType.IMAGE) {
  console.log(value.getContentUrl());
}

回攻員

String - 圖片的 Google 代管網址。


setAltTextDescription(description)

設定這張圖片的替代文字說明。

參數

名稱類型說明
descriptionString圖片的新替代文字說明。

回攻員

CellImage - 這個圖片,用於鏈結。

授權

使用這個方法的指令碼需要下列一或多個範圍的授權:

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

setAltTextTitle(title)

設定這張圖片的替代文字標題。

參數

名稱類型說明
titleString圖片的新替代文字標題。

回攻員

CellImage - 這個圖片,用於鏈結。

授權

使用這個方法的指令碼需要下列一或多個範圍的授權:

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

setSourceUrl(url)

設定圖片來源網址。

參數

名稱類型說明
urlString圖片的網址。

回攻員

CellImageBuilder:這個建構工具用於串連。


toBuilder()

根據目前的圖片屬性建立儲存格圖片建構工具。使用 setSourceUrl(url) 設定新圖片的來源網址。然後,您可以使用 Range.setValue(value)Range.setValues(values) 將其新增至儲存格。

const ss = SpreadsheetApp.getActiveSpreadsheet();
const range = ss.getRange("Sheet1!A1");
const value = range.getValue();
if (value.valueType == SpreadsheetApp.ValueType.IMAGE) {
  const newImage =
      value.toBuilder()
          .setSourceUrl(
              'https://www.gstatic.com/images/branding/productlogos/apps_script/v10/web-64dp/logo_apps_script_color_1x_web_64dp.png',
              )
          .build();
  const newRange = ss.getRange("Sheet1!A2");
  newRange.setValue(newImage);
}

回攻員

CellImageBuilder:建構工具,可根據指定的圖片屬性建立圖片值型別。

已淘汰的方法