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

前端 未结 3 472
春和景丽
春和景丽 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"

    0 讨论(0)
  • 2020-12-09 00:57

    We build a lot of sheets with images and use the static link available in the google album archive { https://get.google.com/albumarchive/... } rather than the dynamic link in google photos. the link in the archive normally ends in "-rw" which limits view-ability to some with whom the doc is shared with. Deleting "-rw" from the end of the link seems to help.

    0 讨论(0)
  • 2020-12-09 00:59

    I made a two lines script to use the share link of an image in Google Drive.

    1. Go to Tools > Script editor.
    2. Copy, paste the following code
    3. Save
    function DRIVE_IMAGE(link){
      return link.replace("open?", "uc?export=download&");
    }
    

    Using the script :

    1. Copy the Get shareable link of your image in Google Drive (Maybe you need to set the share preference to Public on the web).
    2. Go to a Google sheets cell.
    3. Enter the formula

      =IMAGE(DRIVE_IMAGE("COPIED_LINK"))
      
    0 讨论(0)
提交回复
热议问题