I have a Google sheet with approaching 100 in-line images. The sheet is very slow to load. I've read that the sheet will perform better if the images are loaded as a link from a Google Drive file rather than as an embedded image in the spreadsheet.
So I would like to write a Google Apps Script which...
- looks through each cell on each worksheet;
- decides whether the cell contains an image;
- save the image to Google drive;
- get a link to the image file;
- delete the inline-image;
- reinsert the image as a link.
So far I have this...
function extract_images() {
var spreadsheet_id = "1NGtkBj7HOqf-rvV7zdRb7lrj3MRFoJH9Ulnx9YIO7Hs" // MARKS COPY OF "RAW Exam Question Reference AQA GCSE PE 9-1"
var images_folder = DriveApp.getFolderById("1nEF_E7rZmTpTif3uDS8B0Jnio1x6IaSm");
var ss = SpreadsheetApp.openById(spreadsheet_id);
var sheets = ss.getSheets();
sheets.forEach (sh => {
Logger.log("Looking through '"+sh.getName()+"'");
var w = sh.getLastColumn();
var h = sh.getLastRow();
for (i=1; i<h; i++){
for (j=1; j<w; j++){
var value = sh.getRange(i,j).getValue();
var range = sh.getRange(i,j);
if (value.valueOf().toString().startsWith("com")){
Logger.log(`Image at (${i},${j})`);
}
}
}
});
}
...which finds the images in the sheet by the cell value which, for an image, seems to have the format com.google.apps.maestro.server.beans.trix.impl.CellImageApiAdapter@ID
where the ID is a 8 character hex code.
I have tried to use this amazing library written by Kanshi TANAIKE...
https://github.com/tanaikech/DocsServiceApp
...but I can't find a way of using it to extract one image from one cell. I can only see a way of extracting all the images at once and I get an error when I try to do that "exportSizeLimitExceeded".
I feel I am very close which is frustrating. Please help!