【问题标题】:Export Google Sheet as .xlsx and send file to server将 Google Sheet 导出为 .xlsx 并将文件发送到服务器
【发布时间】:2021-04-16 16:13:44
【问题描述】:

我的公司在 Google 表格中管理非机密信息。每天,我都会将该表格导出为 .xlsx 格式,然后将其上传到各种服务以进行数据联合。

通常,可以使用“发布到网络”功能自动执行此类过程。但出于安全原因,该选项对所有用户都是锁定的。

不过,我确实拥有 Google Apps 脚本的完全权限。所以,我想为此写一个脚本。细节无所谓。不知何故,我需要按计划导出工作表并将其发送到 AWS 服务器,在那里可以自动检索它。

在 AWS 方面,我可以轻松设置电子邮件服务器、FTP 服务器、rclone 等。我只需要先弄清楚在 Google 方面该做什么。

这个可以吗?

到目前为止我所尝试的:

Export a Google Sheet to Google Drive in Excel format with Apps Script

function makeCopy() {
  var formattedDate = Utilities.formatDate(new Date(), "CET", "yyyy-MM-dd' 'HH:mm");
  var name = "Backup Copy " + formattedDate;
  var destination = DriveApp.getFolderById("1vFL98cgKdMHLNLSc542pUt4FMRTthUvL");

  // Added
  var sheetId = "2SqIXLiic6-gjI2KwQ6OIgb-erbl3xqzohRgE06bfj2c";
  var url = "https://docs.google.com/spreadsheets/d/" + sheetId + "/export?format=xlsx&access_token=" + ScriptApp.getOAuthToken();
  var blob = UrlFetchApp.fetch(url).getBlob().setName(name + ".xlsx"); // Modified
  destination.createFile(blob);
}

--- 或 ---

function convertSheetToXLSX() {
  var sheetId = "2SqIXLiic6-gjI2KwQ6OIgb-erbl3xqzohRgE06bfj2c";
  var spreadsheetName = "My Spreadsheet";
  var destination = DriveApp.getFolderById("1vFL98cgKdMHLNLSc542pUt4FMRTthUvL");
  var url = "https://docs.google.com/feeds/download/spreadsheets/Export?key=" + sheetId + "&exportFormat=xlsx";  
  var params = {
    method      : "get",
    headers     : {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
    muteHttpExceptions: true
  };
  var blob = UrlFetchApp.fetch(url, params).getBlob();
  blob.setName(spreadsheetName + ".xlsx");
  destination.createFile(blob);
}

我已经从上面发布的 URL 中尝试了这些脚本,但结果是“发生了未知错误,请稍后再试。”

【问题讨论】:

  • 欢迎来到Stack Overflow。请按照How to Ask 中的建议,展示您尝试过的内容并简要说明您的搜索工作。
  • 对不起,我刚刚添加了我已经尝试过的内容。碰巧,我尝试了 Cooper 分享的方法。
  • 首先,我深表歉意,我的回答对您的情况没有用处。关于I have tried the above script but it results in "An unknown error has occurred, please try again later.",不幸的是,根据您的问题,我无法理解您当前的脚本。我为此道歉。为了正确了解您当前的脚本和情况,您可以将当前脚本添加到您的问题中以复制问题吗?借此,我想确认一下。
  • 问题出在哪里,因为我刚刚使用了由 MattMcCode 编写的脚本并添加了一个简单的对话框 ui,效果很好。它在我之前给你的同一个链接上

标签: google-apps-script google-sheets


【解决方案1】:

看看this thread。这是关于发送PDF格式的电子表格,但是如果您将ExportOptions更改为xlsx,您应该可以做到。

【讨论】:

    猜你喜欢
    • 2013-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-27
    相关资源
    最近更新 更多