Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function manual() {
- const ui = SpreadsheetApp.getUi();
- const driveFolder = ui.prompt("Enter google drive folder id").getResponseText().trim()
- const imageType = `image/${ui.prompt("Enter image type: (png / jpeg / gif / svg").getResponseText().toLowerCase().trim()}`
- const mode = Number(ui.prompt("Image mode ( https://support.google.com/docs/answer/3093333?hl=en )").getResponseText().trim());
- const size = (mode == 4) ? ui.prompt("Set height and width comma separated (63,44)").getResponseText().trim() : null;
- const onOff = ui.prompt("If you want a on / off switch enter a cell notation (A1) if not leave blank").getResponseText().trim();
- const images = DriveApp.getFolderById(driveFolder).getFilesByType(imageType);
- _processImages(images, mode, onOff, size);
- }
- function _processImages(images, mode, onOff, size) {
- const output = [];
- const heightWith = (size) ? size.split(",") : null
- while (images.hasNext()) {
- const file = images.next();
- file.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW)
- const downloadUrl = file.getDownloadUrl();
- if (onOff) {
- output.push([`=IF(${onOff} = TRUE,IMAGE("${downloadUrl}",${mode}${(size) ? `,${heightWith[0]},${heightWith[1]}` : ''})`])
- } else {
- output.push([`=IMAGE("${downloadUrl}",${mode}${(size) ? `,${heightWith[0]},${heightWith[1]}` : ''})`])
- }
- }
- if (onOff) {
- SpreadsheetApp.getActiveSheet().getRange(1, 1).insertCheckboxes();
- SpreadsheetApp.getActiveSheet().getRange(2, 1, output.length, 1).setFormulas(output);
- } else {
- SpreadsheetApp.getActiveSheet().getRange(1, 1, output.length, 1).setFormulas(output);
- }
- SpreadsheetApp.getUi().alert(`Processed ${output.length} images`)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement