Created
March 11, 2018 20:58
-
-
Save Willshaw/ace45d8a48ecd7af60ef4018fa4d7083 to your computer and use it in GitHub Desktop.
script to take text from a google spreadsheet and save it as the description on a pdf in google drive
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
/* | |
this script relies on a spreadsheet being called "test desc" and a pdf being called "test.pdf" | |
there needs to be a description in cell A1 of "test desc" | |
*/ | |
function setNewDescription(file_id,description){ | |
var file_by_id = DriveApp.getFileById(file_id); | |
Logger.log(file_by_id.getDescription()); | |
file_by_id.setDescription(description); | |
Logger.log(file_by_id.getDescription()); | |
} | |
function getDescriptionFromSpreadsheet() { | |
Logger.log('load file'); | |
var files = DriveApp.getFilesByName('test desc'); | |
while (files.hasNext()) { | |
var spreadsheet = SpreadsheetApp.open(files.next()); | |
var sheet = spreadsheet.getSheets()[0]; | |
Logger.log(sheet.getName()); | |
// only after 1 file | |
break; | |
} | |
var range = sheet.getRange("A1"); | |
// The row and column here are relative to the range | |
// getCell(1,1) in this code returns the cell at B2, B2 | |
var cell = range.getCell(1, 1); | |
var description = cell.getValue() | |
Logger.log('Cell value: ', description); | |
var files = DriveApp.getFilesByName('test.pdf'); | |
while (files.hasNext()) { | |
var file = files.next(); | |
var file_id = file.getId(); | |
} | |
setNewDescription( file_id, description ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment