我在Google云端硬盘中制作了一个Excel表格,供15个人使用。该功能是宏应从工作表中创建PDF并将其作为邮件发送给其他人。但是我想在Google云端硬盘中将其复制为PDF,我可以在其中查看所有这些人的权限,以查看所有已发送的邮件。
我必须说我是这个宏的初学者,我尝试了2个代码,但总是遇到相同的错误。
function TEST2()
{
var Datum = Utilities.formatDate(new Date(), "GMT+2", "dd.MM.YYYY HH:mm");
var as = SpreadsheetApp.getActive();
var newas = SpreadsheetApp.create("XX");
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("XX");
sheet = as.getSheetByName("XX");
sheet.copyTo(newas);
newas.getSheetByName('XX');
newas.deleteActiveSheet();
var pdf = DriveApp.getFileById(newas.getId()).getAs('application/pdf').getBytes();
var anhang = {fileName:("XX Order" + Datum + ".pdf"),content:pdf,mimeType:'application/pdf'};
var folderID = "TEST FOLDER";
var folder = DriveApp.getFolderById(folderID);
var newFile = DriveApp.createFile(folder);
newFile;
MailApp.sendEmail(
{
to: "Mail Adress",
subject: "XX Order " + Datum,
htmlBody: "XX - Order ",
attachments: anhang
})
SpreadsheetApp.getUi().alert('Mail wurde versendet ' + Datum)
//Delete the temporary sheet
DriveApp.getFileById(destSpreadsheet.getId()).setTrashed(true);
}
我总是收到相同的错误消息。该脚本无法找到具有此ID的文档。
答案 0 :(得分:0)
好,我找到了解决方案:)
var folderID = "XXX BESTELLUNG";
var folderID2 = "XXX Bestellung";
var folder = DriveApp.getFoldersByName(folderID);
var theblob = newas.getBlob().getAs('application/pdf').setName('XXX Bestellung ' + Datum);
var newFile = folder.next().getFoldersByName(folderID2).next().createFile(theblob);
在这种情况下,当我更改代码时,我会得到想要的解决方案:)