首页 > 解决方案 > 当我调用电子表格名称时,自动电子邮件发票错误

问题描述

我正在尝试自动化我的 Google 表格,以便每个月发送到我的电子邮件。但看起来我在调用电子表格时遇到了问题

  var ss = SpreadsheetApp.getActiveSpreadsheet().getName("Invoice test");   
  var filename = "Current Month " + ss.getName();
  var SendBook = ss.copy(filename);
  var ToUser = "example@gmail.com";
  MailApp.sendEmail({
    to: ToUser,
    subject: 'Invoice for last month',
    body: 'Hi! I have attached my invoice for this month. ',
    attachments: [SendBook.getBlob().setName(filename)]
  });
}

如果我删除“ .getName("Invoice test");”,我会在一封电子邮件中收到所有电子表格,我只想要第一页。

标签: google-apps-scriptgoogle-sheets

解决方案


代替

var ss = SpreadsheetApp.getActiveSpreadsheet().getName("Invoice test");

经过

var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Invoice test"); 

文档或仅选择第一张纸:

var ss = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];

文件


推荐阅读