- When an image is put to the sheet with
setWidth()
and setHeight()
using your script, the image is not shown.
If my understanding is correct, how about this answer?
In your script, the image is certainly put to the sheet. But the image is not shown in the sheet. I have experienced this situation. I think that this might be a bug. In that case, how about the following workarounds?
Pattern 1:
When the tab is changed, the image is shown. In this pattern, I used this. When your script is modified, it becomes as follows.
Sample script:
Before you use this script, please add one more sheet with the sheet name of "Sheet2". And this script supposes that the active sheet is not "Sheet2".
var pngUrl = "###"; // Please set this.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var activeSheet = ss.getActiveSheet();
Logger.log(activeSheet.getImages().length) // <--- 0
var image = activeSheet.insertImage(pngUrl, 1, 1).setWidth(300).setHeight(300);
Logger.log(activeSheet.getImages().length) // <--- 1 By this, it is found that the image is put.
// I added below script.
ss.getSheetByName("Sheet2").activate();
SpreadsheetApp.flush();
activeSheet.activate();
Pattern 2:
In this pattern, after the image is put, the width and height of the image are modified.
Sample script:
var pngUrl = "###"; // Please set this.
var activeSheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
activeSheet.insertImage(pngUrl, 1, 1); // Modified
var img = activeSheet.getImages()[0].setWidth(300).setHeight(300); // Added
References:
If I misunderstood your question and this was not the direction you want, I apologize.