This Google Apps Script allows users to insert images from a specified Google Drive folder into a Google Sheet.
- Preview Sort Order: Before inserting images, you can preview the order in which files will be sorted.
- Batch Processing: The script processes images in batches to handle large numbers of files efficiently, 10 images at a time.
- Progress Tracking: A checklist shows the current stage of the process.
- Resizing: Images are automatically resized to maintain quality while keeping file sizes manageable.
- Open Google Sheets.
- Create a new Google Sheet or open an existing one.
- In your Google Sheet, click on
Extensionsin the menu bar. - Select
Apps Scriptfrom the dropdown menu. This will open the Apps Script editor in a new tab.
- In the Apps Script editor, delete any code in the
Code.gsfile under theFilessection. - Copy and paste the code from the Code.gs file in this repo into the
Code.gsfile. - Save the script by clicking the disk icon or by pressing
Ctrl + S(Cmd + Son Mac).
- In the Apps Script editor, click on the
+button next to theFilessection. - Select
HTMLand name the file "index" (must be lowercase, do not include an extension). - Delete all the automatically created code in the
index.htmlfile. - Copy and paste the code from the index.html file in this repo into the
index.htmlfile in Google App Scripts. - Save the HTML file by clicking the disk icon or by pressing
Ctrl + S(Cmd + Son Mac).
Important: This step is required to allow the app permission to read your Google Drive images and edit the Google Sheet.
- In the Apps Script editor, go to
Project Settings(gear icon on the left sidebar). - Check the box for
Show 'appsscript.json' manifest file in editor. - Go back to the
Editortab and you should now see anappsscript.jsonfile in the file list. - Click on the
appsscript.jsonfile and replace its contents with the code from the appsscript.json file in this repo. - Not necessary, but if you wish to change the timezone you can find the correct timezone code here.
- Save the manifest file by clicking the disk icon or by pressing
Ctrl + S(Cmd + Son Mac).
- Go back to your Google Sheet, you can close the Apps Script tab if you wish.
- Refresh the web page by clicking the refresh icon or by pressing
Ctrl + R(Cmd + Ron Mac). - Click on the new
Custom Toolsbutton in the menu bar (it may take a few seconds to appear). - Select
Insert Thumbnails from GDrive.
- On first run, in that Sheet, you may be prompted to authorise access to your Google Drive by the script (see Security Prompt).
- In the "Folder URL" field, enter the URL of the Google Drive folder containing the images.
- For example:
https://drive.google.com/drive/folders/1bRNBR55227gdQc-3_jhfsef_5R80RjAt< Not a real URL
- In the "Start Row" and "Start Column" fields, enter the starting row and column for the images to be inserted.
- Click
Insert Imagesto begin the process.
- Once the script starts running, you'll be able to press Stop to stop the script.
- Additionally as the script runs it'll show a checklist of progress under the Stop button.
NOTE: The script will NOT stop running if you close the window, only if you press the Stop button.
On first run, in that Sheet, you may be prompted to authorise access to your Google Drive by the script.
Up to you if you feel like the security is too permissive, the full code is here to see and audit.
If you encounter error messages about insufficient permissions or invalid scopes, such as:
https://www.googleapis.com/auth/script.scriptapp
You are receiving this error either because your input OAuth2 scope name is invalid or it refers to a newer scope that is outside the domain of this legacy API.
Or:
Exception: Specified permissions are not sufficient to call Ui.showModalDialog. Required permissions: `https://www.googleapis.com/auth/script.container.ui`
Solution: Make sure you've completed Step 5 above (adding the manifest file). These errors occur because Google has updated their OAuth requirements and the script needs explicit permission declarations in the appsscript.json manifest file.
If you encounter any other issues:
- Make sure you have the necessary permissions for both the Google Sheet and the Google Drive folder.
- Check that the folder URL is correct and accessible.
- If the script stops unexpectedly, try running it again. There may be temporary issues with Google's services.
This project is licensed under the GPLv3 License - see the LICENSE file for details.