SKRIPT
Generování osvědčení
Generování osvědčení
function Osvedceni_MK() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('AKT');
var data = sheet.getDataRange().getValues();
var targetSheet = ss.getSheetByName('Osv_MK');
var folderId = "1ia4SMTci34Y6-J7fmkl1tZ-PoJmD5oxf";
var folder = DriveApp.getFolderById(folderId);
for (var i = 0; i < data.length; i++) {
if (data[i][5] === true) { // check if checkbox in column F is checked
var row = data[i];
sheet.getRange(1, 1, 1, row.length).setValues([row]);
sheet.getRange('F1').clearContent();
// Generate the filename
var filename = sheet.getRange('A1').getValue() + " - MK - osvedceni";
// Save the target sheet as a PDF
var url = 'https://docs.google.com/spreadsheets/d/' + ss.getId() + '/export?';
var exportOptions =
'exportFormat=pdf&format=pdf' +
'&size=letter' +
'&portrait=true' +
'&fitw=true' +
'&scale=1' + // Ensure content fits to one page
'&sheetnames=false&printtitle=false&pagenumbers=false' +
'&gridlines=false' +
'&fzr=false' +
'&gid=' + targetSheet.getSheetId();
var token = ScriptApp.getOAuthToken();
Utilities.sleep(2000)
var blob = UrlFetchApp.fetch(url + exportOptions, {
headers: {
'Authorization': 'Bearer ' + token
}
}).getBlob().setName(filename);
Utilities.sleep(2000)
folder.createFile(blob);
}
}
}