附加 excel 工作簿或将工作表转换为 excel,然后使用 gscript 通过 gmail 发送,以便收件人可以编辑工作簿?

Attach excel workbook or convert sheets into excel, then send via gmail using gscript, so that workbook is editable by recipient?

我希望能够向我拥有的 100 多封电子邮件发送一封电子邮件,并附上附件。附件必须是供收件人使用的可编辑 excel 文件。我可以以 excel 或表格的形式访问它,以更容易的为准。

我已经尽我所能在网上找到了。我可以发送一个 PDF,我可以发送一个 Google 驱动器 link,它提供一个可编辑的表格文档;但我希望最终用户能够 access/edit 它,即使他们没有 Google 驱动器。

这位成功发送了一个可编辑的 PDF:

function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 1; // Number of rows to process
// Fetch the range of cells A2:B2
var dataRange = sheet.getRange(startRow, 1, numRows, 1);
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var emailAddress = row[0]; // First column
var message = row[1]; // Second column
var subject = 'Sending emails from a Spreadsheet'
var file = DriveApp.getFileById("xxxxxxxxx");
MailApp.sendEmail(emailAddress, subject, message, {attachments: [file]});
}
}

我尝试了这个,以便能够附加一个文档(希望是一个可编辑的 excel 文件)但是我收到一个错误代码说文档丢失了(即使它与我的文档 ID 完全相同在上面使用,有效):

function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 1; // Number of rows to process
// Fetch the range of cells A2:B2
var dataRange = sheet.getRange(startRow, 1, numRows, 1);
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var emailAddress = row[0]; // First column
var message = row[1]; // Second column
var subject = 'Sending emails from a Spreadsheet'
var file = DocumentApp.openById("xxxxxxxxx");
MailApp.sendEmail(emailAddress, subject, message, {attachments: [file]});
}
}

我想让它发送一个 excel 文件,但即使我使用与上面第一种语法相同的文档 ID,它也找不到文档。

这会发送一个 excel 文档..但收件人无法打开。这不是格式正确吗?

  function getGoogleSpreadsheetAsExcel(){
  try {
 /*var ss = SpreadsheetApp.getActive();*/
 var ss = DriveApp.getFileById("xxxxx");
var url = "https://docs.google.com/feeds/download/spreadsheets/Export? 
 key=" + ss + "&exportFormat=xlsx";
  var params = {
  method      : "get",
  headers     : {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
  muteHttpExceptions: true
 };
var blob = UrlFetchApp.fetch(url, params).getBlob(); 
blob.setName(ss.getName() + ".xlsx");
MailApp.sendEmail("xxxx", "Google Sheet to Excel", "The 
XLSX file is attached", {attachments: [blob]});
} catch (f) {
Logger.log(f.toString());
}
}

这是使用 google 脚本

从 gmail 发送带有 excel 附件的电子邮件的正确语法
function excelemail(){
var file = DriveApp.getFileById('1pJpDI2HD28_gPWGnj-emV0L4rXBBS0HC');

GmailApp.sendEmail('xxxx', 'Attachment example', 'Please see the attached file.' , {attachments: [file], name: 'Automatic Emailer Script' })
    }