Class CellImage

CellImage

代表儲存格中的圖片值。如要在儲存格中新增圖片,您必須使用 SpreadsheetApp.newCellImage()CellImageBuilder 為圖片建立新的圖片值。接著,您可以使用 Range.setValue(value)Range.setValues(values) 將圖片值新增至儲存格。

屬性

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

方法

方法傳回類型簡短說明
getAltTextDescription()String傳回這張圖片的替代文字說明。
getAltTextTitle()String傳回這張圖片的替代文字標題。
getContentUrl()String傳回 Google 代管的圖片網址。
toBuilder()CellImageBuilder根據目前的圖片屬性建立儲存格圖片建構工具。

內容詳盡的說明文件

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 代管網址。


toBuilder()

根據目前的圖片屬性建立儲存格圖片建構工具。使用 CellImageBuilder.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:建構工具,可根據指定的圖片屬性建立圖片值型別。

已淘汰的方法