2017-04-25 84 views
-1

在將轉換後的Google工作表作爲電子郵件中的附件發送之前,是否可以將轉換後的Google工作表加密爲PDF?將加密轉換後的Google工作表添加到PDF

這是我當前的代碼:它隱藏工作表,我不需要轉換並將其他工作表轉換爲PDF。我想在這裏實現的是轉換後的PDF進行密碼加密,因爲它包含一些個人信息。

function myFunction() { 
    Utilities.sleep(200); 

    var sheet=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses 1"); 
    var pdfsheet=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2"); 

    sheet.hideSheet(); 

    var substringsubject = pdfsheet.getRange("B4:B4").getValues(); 
    var substringnname = pdfsheet.getRange("B3:B3").getValues(); 
    var substringidnum = pdfsheet.getRange("B7:B7").getValues(); 

    var startRow =9; // First row of data to process B9:B9 
    var numRows =1; // Number of rows to process 

    // Fetch the range of cells B9:B9 
    var dataRange = pdfsheet.getRange(startRow, 1, numRows, 2) 

    // Fetch values for each row in the Range. 
    var data = dataRange.getValues(); 
    for (var i = 0; i < data.length; ++i) { 
    var row = data[i]; 
    var email = row[1]; 
    var emailcc = row[2]; 
    // Subject of email message 
    var subject = "USER ACCOUNT DETAILS " + substringsubject + " " + substringidnum + ""; 
    var ss= SpreadsheetApp.getActiveSpreadsheet(); 
    // Email Body can be HTML too 
    var body = '<body>' + ' Hi ' + substringnname +',<br><br>' + 
    'Please see attached file for your account details.</p>' + 
    //'<p> Click <a href="http://www.google.com">here</a> to go to google.<p>' 
    '</body>' 

    var pdf = DriveApp.getFileById(ss.getId()).getAs("application/pdf"); 
    pdf.setName(substringsubject+" "+substringidnum+" .pdf"); 
    // If allowed to send emails, send the email with the PDF attachment 
    MailApp.sendEmail({ 
     to:email, 
     cc:emailcc, 
     subject:subject, 
     htmlBody:body, 
     attachments:[pdf] 
    }); 
    sheet.showSheet(); 
    } 
} 

謝謝。

回答

1

您無法直接從Apps腳本保護您的PDF。見前面的SO question

+0

哦,我看到我認爲它會實施,因爲這是一個3年前的問題。謝謝 – kkk