Class CellImageBuilder  |  Apps Script  |  Google for Developers (original) (raw)

Class CellImageBuilder

Stay organized with collections Save and categorize content based on your preferences.

CellImageBuilder

Builder for [CellImage](#). This builder creates the image value needed to add an image to a cell.

Properties

Property Type Description
valueType ValueType The value type of the cell image, which is ValueType.IMAGE.

Methods

Method Return type Brief description
build() CellImage Creates the image value type needed to add an image to a cell.
getAltTextDescription() String Returns the alt text description for this image.
getAltTextTitle() String Returns the alt text title for this image.
getContentUrl() String Returns a Google-hosted URL to the image.
setAltTextDescription(description) CellImage Sets the alt-text description for this image.
setAltTextTitle(title) CellImage Sets the alt text title for this image.
setSourceUrl(url) CellImageBuilder Sets the image source URL.
toBuilder() CellImageBuilder Creates a cell image builder based on the current image properties.

Deprecated methods

Method Return type Brief description
getUrl() String Gets the image's source URL.

Detailed documentation

build()

Creates the image value type needed to add an image to a cell. The image value is built from the image properties added to the builder, such as the source URL.

Return

[CellImage](/apps-script/reference/spreadsheet/cell-image) — A representation of the image to add to a cell.


getAltTextDescription()

Returns the alt text description for this image.

Return

String — The alt text description.

Scripts that use this method require authorization with one or more of the following scopes:


getAltTextTitle()

Returns the alt text title for this image.

Return

String — The alt text title.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:


getContentUrl()

Returns a Google-hosted URL to the image. This URL is tagged with the account of the requester, so anyone with the URL effectively accesses the image as the original requester. Access to the image might be lost if the spreadsheet's sharing settings change. The returned URL expires after a short period of time.

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

Return

String — The Google-hosted URL of the image.


setAltTextDescription(description)

Sets the alt-text description for this image.

Parameters

Name Type Description
description String The new alt text description for the image.

Return

[CellImage](/apps-script/reference/spreadsheet/cell-image) — This image, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:


setAltTextTitle(title)

Sets the alt text title for this image.

Parameters

Name Type Description
title String The new alt text title for the image.

Return

[CellImage](/apps-script/reference/spreadsheet/cell-image) — This image, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:


setSourceUrl(url)

Sets the image source URL.

Parameters

Name Type Description
url String The URL for the image.

Return

[CellImageBuilder](#) — This builder, for chaining.


toBuilder()

Creates a cell image builder based on the current image properties. Use [setSourceUrl(url)](#setSourceUrl%28String%29) to set the source URL of the new image. Then you can add it to a cell using [Range.setValue(value)](/apps-script/reference/spreadsheet/range#setValue%28Object%29) or [Range.setValues(values)](/apps-script/reference/spreadsheet/range#setValues%28Object%29).

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

Return

[CellImageBuilder](#) — A builder that creates an image value type based on the given image properties.

Deprecated methods

getUrl()

Deprecated. For most newly inserted images, the source URL is unavailable.

Gets the image's source URL. Returns an empty string if the URL is unavailable. For most newly inserted images, the source URL is unavailable regardless how the image is inserted.

Return

String — The image's source URL if available; returns an empty string otherwise.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-12-09 UTC.