【发布时间】:2017-04-04 19:57:12
【问题描述】:
只是尝试获取当前的电子表格选项卡并将其作为 *.csv 文件邮寄到某个地址。我已经经历了大量先前的问题,但还没有找到答案。这改编自成功发送 PDF 文件。唯一的问题是我需要 CSV 而不是 PDF。
function mailCSV() {
// Get the currently active spreadsheet URL (link)
// Or use SpreadsheetApp.openByUrl("<<SPREADSHEET URL>>");
// Send the CSV of the spreadsheet to this email address
var email_send_address = "email@emailsample.com";
var email_subject ='subject'
// Get the currently active spreadsheet URL (link)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var url = "http://spreadsheets.google.com/feeds/download/spreadsheets/Export?key="+ ss + "&exportFormat=csv";
//var csv = DriveApp.getFileById(ss.getId()).getAs('application/csv').getBytes();
//var attachCSV = {fileName: email_subject,content:url,mimeType:'application/csv'};
var res = UrlFetchApp.fetch(url);
var attachments = [{fileName:"dg_request.csv", content: res.getContent(),mimeType:"application/vnd.csv"}];
MailApp.sendEmail(email_send_address, email_subject, {attachments: attachments});
// MailApp.sendEmail(email_send_address, email_subject, {attachments:[attachCSV]});
}
【问题讨论】:
标签: csv google-sheets gmail-api google-sheets-api