Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
script to take text from a google spreadsheet and save it as the description on a pdf in google drive
/*
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
You can’t perform that action at this time.