What is the right way to put a Drive image into a Sheets cell programmatically?

前端 未结 3 477
春和景丽
春和景丽 2020-12-09 00:14

I have a WebApp that collects work site data into a Google Sheets spreadsheet and also collects work site photos into a Google Drive folder that I create for each job. Some

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-09 00:41

    Assuming you get the ID of your image in your drive, you can use a code like below to insert an image in the last row of a sheet (the url is a bit different than usual):

      ...
      var img = DriveApp.getFileById('image ID');// or any other way to get the image object
      var imageInsert = sheet.getRange(lastRow+1, 5).setFormula('=image("https://drive.google.com/uc?export=view&id='+img.getId()+'")');// in this example the image is in column E
      sheet.setRowHeight(lastRow+1, 80);// define a row height to determine the size of the image in the cell
      ...
    

    I would suggest that you carefully check the sharing properties of the files you are trying to show : they must be set to "public" of moved in a folder that is also "publicly shared"

提交回复
热议问题