微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

应用程序脚本 - 在 xlsx 附件中发送电子表格 修改后的脚本:参考:

如何解决应用程序脚本 - 在 xlsx 附件中发送电子表格 修改后的脚本:参考:

我目前正在使用以下脚本,但使用此脚本,整个电子表格将作为附件发送,我希望只发送 1 张“Planning Waak_Zomervakantie”表。 是否有可能?我需要在脚本中更改什么?

var MASTERSHEET_ID = '###';

function MailPlanning() {
  try {
    var ss = SpreadsheetApp.getActive();
    var url = "https://docs.google.com/Feeds/download/spreadsheets/Export?key=" + ss.getId() + "&exportFormat=xlsx";
    var sheet = ss.getSheetByName('Planning Waak_Zomervakantie');
    var range = sheet.getRange("D1:D1");
    var cell = range.getValue();
    var rangename = sheet.getRange("B1:B1");
    var name = rangename.getValue();
    var recipients = cell + "," + "waak@tempo-team.be";
    var params = {
      method: "get",headers: { "Authorization": "Bearer " + ScriptApp.getoAuthToken() },muteHttpExceptions: true
    };
    var blob = UrlFetchApp.fetch(url,params).getBlob();
    blob.setName(ss.getName() + ".xlsx");
    GmailApp.sendEmail(recipients,"Bevestiging vakantiejob WAAK komende zomervakantie 2021","Beste " + name + "," + "\n\nGoed nieuws! Je werd geselecteerd voor een vakantiejob bij WAAK." + "\nIn bijlage vind je alvast jouw planning." + "\n\nGelieve ons zo snel mogelijk te bevestigen of je deze periode kan werken via waak@tempo-team.be of 056/52 15 50." + "\n\nAlle informatie over eventuele infosessie en afdeling zullen later doorgegeven worden." + "\nVeel succes!" + "\n\nVriendelijke groeten,\n\nTempo-Team Waak" + "\nDavina en Lisa" + "\nTel: 056/52 15 50" + "\nwaak@tempo-team.be",{ noreply: true,attachments: [blob] });
  } catch (f) {
    console.log(f.toString());
  }
}

解决方法

我相信你的目标如下。

  • 您想使用 Google Apps 脚本将 Google 电子表格中的特定工作表导出为 XLSX 格式。

在这种情况下,我想建议在查询参数中添加工作表ID的信息。但是,我认为您的 https://docs.google.com/feeds/download/spreadsheets/Export?key=###&exportFormat=xlsx 端点可能有点旧。虽然我认为现在可以使用它,但我不确定什么时候会被弃用。但我不确定这种情况的细节。所以,在现阶段,我想建议使用 https://docs.google.com/spreadsheets/export?id=###&exportFormat=xlsx 的端点。这可以通过 Drive API v3 检索。当这反映到您的脚本中时,它会变成如下所示。

修改后的脚本:

从:
var url = "https://docs.google.com/feeds/download/spreadsheets/Export?key=" + ss.getId() + "&exportFormat=xlsx";
var sheet = ss.getSheetByName('Planning Waak_Zomervakantie');
到:
var sheet = ss.getSheetByName('Planning Waak_Zomervakantie');
// var url = "https://docs.google.com/feeds/download/spreadsheets/Export?key=" + ss.getId() + "&exportFormat=xlsx&gid=" + sheet.getSheetId();
var url = "https://docs.google.com/spreadsheets/export?id=" + ss.getId() + "&exportFormat=xlsx&gid=" + sheet.getSheetId();

参考:

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?