1

My script inserts a PNG image in the spreadsheet by insertImage() function.

  const Sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
  const File = DriveApp.getFileById("**********");     // PNG file in Google Drive
  const Blob = File.getBlob();
  Sheet.insertImage(Blob, 1, 9, 20, 30).setHeight(100).setWidth(100);
}

It seems to work fine, but if I export the spreadsheet to PDF, the image doesn't appear in the PDF. After reloading the spreadsheet on the browser, I can export to PDF with the image with no problem. How can I export to PDF with the image without reloading the spreadsheet? (SpreadsheetApp.flush() didn't help it.)

fujimu
  • 11
  • 1
  • About `but if I export the spreadsheet to PDF, the image doesn't appear in the PDF.`, can I ask you about the detail of it? – Tanaike Oct 23 '21 at 07:43
  • Just a guess. Resizing can cause the glitches. Try to exclude the `.setHeight(100).setWidth(100)`. – Yuri Khristich Oct 23 '21 at 12:42
  • @Tanaike, it means to exec [File]-[Download]-[PDF document (.pdf)] . – fujimu Oct 24 '21 at 14:10
  • 3
    @yuri, deleting setHeight and setWidth doesn't solve the problem. But your idea was a big hint! By changing the parameters from insertImage(Blob, 1, 9, 20, 30) to insertImage(Blob, 1, 9, 0, 0) , exporting succeeded! We shouldn't use offsets to export the spreadsheet to other file format. Anyway, thank! – fujimu Oct 24 '21 at 14:16
  • Well. Good finding. Thank you too. – Yuri Khristich Oct 24 '21 at 14:43

0 Answers0