【发布时间】:2018-08-31 09:34:55
【问题描述】:
这是我创建谷歌文档的代码,将一些信息粘贴到(最终从电子表格中),将其转换为 pdf 并通过电子邮件发送给我自己。
很遗憾,驱动器中的文档显示“此文档是由 Google Apps 脚本创建的。”在其中发表评论,电子邮件中的 pdf 没有。它有正确的标题,但页面的内容丢失了。我已经尝试了几个关于堆栈溢出的示例,但到目前为止还没有一个可以工作。
var ss = SpreadsheetApp.getActive();
function onOpen(){
var ui = SpreadsheetApp.getUi();
ui.createMenu('TEST MENU') //creates main menu tab
.addItem('pdf', 'pdf')
.addToUi();
}
function pdf() {
// Create a new Google Doc named 'Hello, world!'
var doc = DocumentApp.create('Hello, world!');
// Access the body of the document, then add a paragraph.
doc.getBody().appendParagraph('This document was created by Google Apps Script.');
var pdfContent = doc.getAs('application/pdf');
var draftMail = GmailApp.createDraft('will@exampleEmail.co.uk',
'Email title', 'Pls see attached',
{
attachments: [pdfContent.getAs(MimeType.PDF)],
name: 'Converted doc content'
});
// Now send the mail
draftMail.send();
}
【问题讨论】:
-
导出前需要使用saveAndClose。
标签: javascript google-apps-script google-sheets google-docs