Created
February 27, 2025 14:23
-
-
Save phillypb/63a62ea8ddf82cf5a99cabeee067fa49 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function replaceTextToImage() { | |
// ******************** COMPLETE THESE ITEMS ******************** | |
var searchText = ""; | |
var imageURL = ""; | |
var rowHeight = 100; | |
var columnWidth = 100; | |
// ******************** COMPLETE THESE ITEMS ******************** | |
// get spreadsheet | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
// get Data sheet | |
var dataSheet = ss.getSheetByName('Data'); | |
// build image | |
var image = SpreadsheetApp | |
.newCellImage() | |
.setSourceUrl(imageURL) | |
.build(); | |
// create TextFinder process to get all Ranges that need changing | |
var textFinder = dataSheet.createTextFinder(searchText).findAll(); | |
// loop through each TextFinder item ***************************** | |
textFinder.forEach(function getCell(word) { | |
// use TextFinder to get Row & Column numbers | |
var row = word.getRow(); | |
var col = word.getColumn(); | |
// get relevant cell via Range | |
var cell = dataSheet.getRange(row, col); | |
// insert image | |
cell.setValue(image); | |
// OPTIONAL: change cell size | |
dataSheet.setRowHeight(row, rowHeight); | |
dataSheet.setColumnWidth(col, columnWidth); | |
// OPTIONAL: centre image | |
cell.setVerticalAlignment("middle"); | |
cell.setHorizontalAlignment("center"); | |
}); | |
// loop through each TextFinder item ***************************** | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment