【问题标题】:Convert Google Sheets to .xls将 Google 表格转换为 .xls
【发布时间】:2014-01-13 19:04:49
【问题描述】:

谁有任何关于如何通过 Google App Script 将 Google 表格文件转换为 .xls 文件的指示?

非常感谢

这是我的理论,但逻辑有缺陷。我也尝试过 Blobs 方法,似乎大多数文件都默认为 application/pdf。

function gs2xls() {
  var gSheets = DocsList.getFilesByType('spreadsheet');
  for(var i = 0; i < gSheets.length; i++){
    var gSheetFile = gSheets[i]; //File
    var gSheetSS = SpreadsheetApp.open(gSheetFile); //Spreadsheet of gs file
    var gSheet = gSheetSS.getActiveSheet();
    var xlsSS = SpreadsheetApp.create(gSheetFile.getName() + ".xls");
    xlsSS.setActiveSheet(gSheet);
  }  
}

【问题讨论】:

标签: google-apps-script


【解决方案1】:

Google Apps 脚本不能在本机导出除 pdf 之外的任何内容,但文档 API 可以,因此您可以使用带有参数的 urlFetch 来获取您想要的内容。

代码在这篇文章中带有解释:Google apps script to email google spreadsheet excel version

效果很好。

【讨论】:

    【解决方案2】:

    这种方法永远行不通,因为: 1)您正在创建和清空谷歌电子表格,而不是 xls 类型的文件。 2)您将无效工作表设置为活动工作表(来自另一个电子表格,但 setactivesheet 不是这样做的)。

    您最多只能向用户显示一个将文件下载为 xls 的导出链接。谷歌如何制作导出链接。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-21
      • 1970-01-01
      • 1970-01-01
      • 2012-06-27
      • 2011-06-14
      • 1970-01-01
      相关资源
      最近更新 更多