Created
June 13, 2017 16:30
-
-
Save rheajt/71f786d58e61dfab70586875cca7d774 to your computer and use it in GitHub Desktop.
google apps script code to append an image to a document with the file id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onOpen() { | |
DocumentApp.getUi() | |
.createMenu('ID-TO-IMAGE') | |
.addItem('Run', 'runIdToImage') | |
.addToUi(); | |
} | |
function runIdToImage() { | |
var doc = DocumentApp.getActiveDocument(); | |
var body = doc.getBody(); | |
var tables = body.getTables(); | |
for(var i = 0; i < tables.length; i++) { | |
var idCell = tables[i] | |
.getRow(1) | |
.getCell(1); | |
var id = idCell.getText(); | |
var image = DriveApp.getFileById(id) | |
.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW); | |
var url = image.getUrl(); | |
var appendedImage = idCell.clear().appendImage(image.getBlob()); | |
var imageH = appendedImage.getHeight() / 10; | |
var imageW = appendedImage.getWidth() / 10; | |
appendedImage | |
.setHeight(imageH) | |
.setWidth(imageW) | |
.setLinkUrl(url); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment