Skip to content

Instantly share code, notes, and snippets.

@oshliaer
Last active May 24, 2021 10:36
Show Gist options
  • Save oshliaer/dbe99c193e5b6b0c7b61 to your computer and use it in GitHub Desktop.
Save oshliaer/dbe99c193e5b6b0c7b61 to your computer and use it in GitHub Desktop.
Batch export to PDF #gas
function onInstall(e){}
var PREFERENCES = [
{
fileId: 'ID_GOOGLE_DRIVE_TYPE_FILE',
toFolderId: 'ID_FOLDER'
},
{
fileId: 'ID_GOOGLE_DRIVE_TYPE_FILE',
toFolderId: 'ID_FOLDER'
}
]
function batch(){
for(var item in PREFERENCES){
exportToPDF_(PREFERENCES[item]['fileId'], PREFERENCES[item]['toFolderId'])
}
}
function exportToPDF_(fileId, folderId){
var source = DriveApp.getFileById(fileId)
var blob = source.getAs('application/pdf');
var file = DriveApp.createFile(blob);
file.setName(source.getName() + '.pdf');
if(folderId) {
try{
var d = DriveApp.getFolderById(folderId);
moveToFolder_(file, d);
}
catch(e){
}
}
return file;
}
function moveToFolder_(file, folder){
folder.addFile(file);
DriveApp.getRootFolder().removeFile(file);
}
@ovich89
Copy link

ovich89 commented May 24, 2021

Is ther a possibility to export only one sheet from a file with multiple sheets? This script exports all the sheets from the spreadsheet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment