Write the google sheet script for border the image
Assistant
Google Sheets doesn't have a built-in feature to apply borders directly around images inserted in cells, and the Apps Script API doesn't provide direct methods to manipulate image borders either.
However, there are a couple of workarounds you can implement using Google Apps Script:
Option 1: Insert Image in a Cell and Add Cell Borders
If your images are inserted inside cells (using Insert > Image in cell), you can add borders to the cells containing these images. This doesn't put a border on the image itself but around the cell holding the image, which visually looks similar.
Here’s a simple script that applies borders to all cells in a specified range (e.g., that contain images):
function addBordersToImageCells() {
// Change these to your sheet name and range where images in cells are located
var sheetName = 'Sheet1';
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
// For example, range with in-cell images
var range = sheet.getRange("B2:D10");
// Set border on entire range
range.setBorder(true, true, true, true, true, true, 'black', SpreadsheetApp.BorderStyle.SOLID);
}
This script adds solid black borders around all cells in the specified range, which can help your images stand out.
Option 2: Insert Image as Drawing and Add a Border Shape (More Complex)
If your images are inserted over the grid (Insert > Image > Image over cells), there's no API method to manipulate them or add borders directly via Apps Script. A complex workaround would be:
Insert a rectangle shape (or drawing) behind the image.
Adjust size and position of both the shape border and the image.
However, Google Sheets scripting API has limited support for manipulating drawings and images over cells, making this approach difficult and fragile.
Summary
You can programmatically add borders around cells containing images (Option 1).
You cannot add a border directly on images inserted over cells via Apps Script.
If you want to automate images with borders, consider inserting them inside cells and then bordering those cells.
If you want me to help you write a script specific to your sheet or range, please share details like your sheet name, image locations, or how your images are inserted.