我一直在嘗試解決這個問題,但我是編程新手。我想通過作業表發送帶有發票附件的電子郵件。該表包含所有必要的資訊,例如發票編號、發票檔案名、檔案驅動器 ID、客戶電子郵件等。
我為此使用的代碼是從另一個有效的應用程式腳本中回收的。它似乎無法在我在這里嘗試的修改中幸存下來。
function invoiceDispatcher() {
const invoiceDispatcherSheet = SpreadsheetApp.openById("SPREADSHEETID").getSheetByName("invoicedispatcherlog");
let emailTemplate = HtmlService.createTemplateFromFile("invoiceEmailTemplate");
let invoiceNumber = 0;
let invoiceDate = 9;
let customerEmail = 8;
let invoiceName = 1;
let invoiceFileID = 2;
let transactionData = invoiceDispatcherSheet.getRange(2,1,invoiceDispatcherSheet.getLastRow()-1,13).getValues();
let cleanData = transactionData.filter(function (cases){ return cases[11] === true});
cleanData.forEach(function(row){
emailTemplate.rn = row[invoiceNumber];
emailTemplate.rd = Utilities.formatDate(row[invoiceDate], "CEST" , "dd.MM.yyyy");
//let invoiceFileName = String(row[1]);
let invoiceFile = DriveApp.getFileById(invoiceFileID).getAs(MimeType.PDF);
//let invoiceFile = DriveApp.getFilesByName([invoiceFileName]);
let invoiceMessage = emailTemplate.evaluate().getContent();
GmailApp.sendEmail(
row[customerEmail], "Your Invoice Document " row[invoiceNumber],
"Please open this message in an HTML-compatible email client. Thank you",
{name: "Company Name", htmlBody: invoiceMessage, attachments: [invoiceFile]});
})
}
此外,我想在作業表的 K 列(Col10)中添加一個時間戳。
我確信我在這里有一些冗余,并且我還不能完全理解函式和方法如何互鎖的所有方面,但會非常感謝一些指導。如果有任何不清楚的地方,請告訴我,我是否可以提供更多資訊。
uj5u.com熱心網友回復:
嘗試這個:
function invoiceDispatcher() {
const sh = SpreadsheetApp.openById("SPREADSHEETID").getSheetByName("invoicedispatcherlog");
let t = HtmlService.createTemplateFromFile("invoiceEmailTemplate");
let transactionData = sh.getRange(2, 1, sh.getLastRow() - 1, 13).getValues();
let cleanData = transactionData.filter(function (cases) { return cases[11] == true });
cleanData.forEach(function (row) {
t.rn = row[0];
t.rd = Utilities.formatDate(row[9], "CEST", "dd.MM.yyyy");
let invoiceFile = DriveApp.getFileById(row[2]).getAs(MimeType.PDF);
let invoiceMessage = t.evaluate().getContent();
GmailApp.sendEmail(row[8], "Your Invoice Document " row[0],
"Please open this message in an HTML-compatible email client. Thank you",
{ name: "Company Name", htmlBody: invoiceMessage, attachments: [invoiceFile] });
})
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/353600.html
上一篇:取消縮短Google表格中的網址
