附上 Google 幻灯片作为 pdf,在通过电子邮件发送时替换了占位符文本
Attach Google Slide as a pdf with the placeholder text replaced whilst sending by email
我已经起草了下面的代码,但是它附上了带有占位符的 pdf。
下面的代码从 google 表单中获取数据,将其填充到 google sheet 中,并用 google 中的数据替换模板上的所有占位符形式。添加了触发器 'on form submit'。
代码如下:
function DigitalReceipts() {
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Receipts").activate();
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lr = ss.getLastRow()
for (var i =2;i<lr;i++){
if(ss.getRange(i, 1).getValue()){
//Make a copy of the template file - power point
var documentId = DriveApp.getFileById('1FtgZuJb4KpChhgehPp1lIEtrsjvykAqRiYl5rL8yv2Q').makeCopy().getId();
var RV = ss.getRange(i, 2).getValue();
var DateFormat = ss.getRange(i, 4).getValue();
var Date = Utilities.formatDate(DateFormat, "GMT+0400", "dd MMM yyyy");
var Amount = ss.getRange(i, 5).getValue().toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
var Name = ss.getRange(i, 6).getValue();
var Description = ss.getRange(i, 7).getValue();
var SalesOwner = ss.getRange(i, 8).getValue();
var PaymentType = ss.getRange(i, 9).getValue();
var PaymentReference = ss.getRange(i, 10).getValue();
//Get the document body as a variable
var body = SlidesApp.openById(documentId);
body.replaceAllText('{RV}', RV);
body.replaceAllText('{Date}', Date);
body.replaceAllText('{Amount}', Amount);
body.replaceAllText('{Name}', Name);
body.replaceAllText('{Description}', Description);
body.replaceAllText('{Sales Owner}', SalesOwner);
body.replaceAllText('{Payment Type}', PaymentType);
body.replaceAllText('{Payment Reference}', PaymentReference);
DriveApp.getFileById(documentId).setName("xxx_"+Name+"_Receipt_"+RV);
//var body = DocumentApp.openById(documentId).getBody();
//body.replaceText('{RV}', RV).replaceText('{Date}', Date).replaceText('{Amount}', Amount).replaceText('{Name}', Name).replaceText('{Description}', Description).replaceText('{Sales Owner}', SalesOwner).replaceText('{Payment Type}', PaymentType).replaceText('{Payment Reference}', PaymentReference);
var receipt = body.getSlides();
var receiptNumber = 1;
//var receiptURL = body.getId()+receipt[receiptNumber-1].getObjectId();
var receiptURL = body.getUrl()+"#slide=id."+receipt[receiptNumber-1].getObjectId();
ss.getRange(i, 11).setValue(receiptURL);
var currentEmail = ss.getRange(i, 3).getValue();
var subjectLine = "PwC's Academy_"+Name+"_Receipt_"+RV;
var templateText = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Template").getRange(1, 1).getValue();
var messageBody = templateText.replace("{Name}", Name).replace("{Description}", Description).replace("{URL}", receiptURL);
//var ReceiptID = ss.getRange(i, 11).getValue();
//var ReceiptID = ReceiptURL.match(/[-\w]{25,}/);
//var ReceiptAttachment = ss.getRange(i, 11).getValue();
//var waiver = DriveApp.getFileById(ReceiptAttachment);
//var liabilityWaiver = waiver.getAs(MimeType.PDF);
var pdf = DriveApp.getFileById(documentId).getAs("application/pdf");
MailApp.sendEmail(currentEmail, subjectLine, messageBody, {attachments: pdf,
cc: 'abc@abc.com'});
}
else {}
}
}
任何 help/guidance.
将不胜感激
这个修改怎么样?
发件人:
body.replaceAllText('{Payment Reference}', PaymentReference);
DriveApp.getFileById(documentId).setName("xxx_"+Name+"_Receipt_"+RV);
收件人:
body.replaceAllText('{Payment Reference}', PaymentReference);
body.saveAndClose(); // <--- Added
DriveApp.getFileById(documentId).setName("xxx_"+Name+"_Receipt_"+RV);
参考:
如果这不能直接解决您的问题,我深表歉意。
我已经起草了下面的代码,但是它附上了带有占位符的 pdf。
下面的代码从 google 表单中获取数据,将其填充到 google sheet 中,并用 google 中的数据替换模板上的所有占位符形式。添加了触发器 'on form submit'。 代码如下:
function DigitalReceipts() {
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Receipts").activate();
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lr = ss.getLastRow()
for (var i =2;i<lr;i++){
if(ss.getRange(i, 1).getValue()){
//Make a copy of the template file - power point
var documentId = DriveApp.getFileById('1FtgZuJb4KpChhgehPp1lIEtrsjvykAqRiYl5rL8yv2Q').makeCopy().getId();
var RV = ss.getRange(i, 2).getValue();
var DateFormat = ss.getRange(i, 4).getValue();
var Date = Utilities.formatDate(DateFormat, "GMT+0400", "dd MMM yyyy");
var Amount = ss.getRange(i, 5).getValue().toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
var Name = ss.getRange(i, 6).getValue();
var Description = ss.getRange(i, 7).getValue();
var SalesOwner = ss.getRange(i, 8).getValue();
var PaymentType = ss.getRange(i, 9).getValue();
var PaymentReference = ss.getRange(i, 10).getValue();
//Get the document body as a variable
var body = SlidesApp.openById(documentId);
body.replaceAllText('{RV}', RV);
body.replaceAllText('{Date}', Date);
body.replaceAllText('{Amount}', Amount);
body.replaceAllText('{Name}', Name);
body.replaceAllText('{Description}', Description);
body.replaceAllText('{Sales Owner}', SalesOwner);
body.replaceAllText('{Payment Type}', PaymentType);
body.replaceAllText('{Payment Reference}', PaymentReference);
DriveApp.getFileById(documentId).setName("xxx_"+Name+"_Receipt_"+RV);
//var body = DocumentApp.openById(documentId).getBody();
//body.replaceText('{RV}', RV).replaceText('{Date}', Date).replaceText('{Amount}', Amount).replaceText('{Name}', Name).replaceText('{Description}', Description).replaceText('{Sales Owner}', SalesOwner).replaceText('{Payment Type}', PaymentType).replaceText('{Payment Reference}', PaymentReference);
var receipt = body.getSlides();
var receiptNumber = 1;
//var receiptURL = body.getId()+receipt[receiptNumber-1].getObjectId();
var receiptURL = body.getUrl()+"#slide=id."+receipt[receiptNumber-1].getObjectId();
ss.getRange(i, 11).setValue(receiptURL);
var currentEmail = ss.getRange(i, 3).getValue();
var subjectLine = "PwC's Academy_"+Name+"_Receipt_"+RV;
var templateText = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Template").getRange(1, 1).getValue();
var messageBody = templateText.replace("{Name}", Name).replace("{Description}", Description).replace("{URL}", receiptURL);
//var ReceiptID = ss.getRange(i, 11).getValue();
//var ReceiptID = ReceiptURL.match(/[-\w]{25,}/);
//var ReceiptAttachment = ss.getRange(i, 11).getValue();
//var waiver = DriveApp.getFileById(ReceiptAttachment);
//var liabilityWaiver = waiver.getAs(MimeType.PDF);
var pdf = DriveApp.getFileById(documentId).getAs("application/pdf");
MailApp.sendEmail(currentEmail, subjectLine, messageBody, {attachments: pdf,
cc: 'abc@abc.com'});
}
else {}
}
}
任何 help/guidance.
将不胜感激这个修改怎么样?
发件人:
body.replaceAllText('{Payment Reference}', PaymentReference);
DriveApp.getFileById(documentId).setName("xxx_"+Name+"_Receipt_"+RV);
收件人:
body.replaceAllText('{Payment Reference}', PaymentReference);
body.saveAndClose(); // <--- Added
DriveApp.getFileById(documentId).setName("xxx_"+Name+"_Receipt_"+RV);
参考:
如果这不能直接解决您的问题,我深表歉意。