【问题标题】:trying to convert xls to google spreadsheet using google app script and getting "Empty response" error尝试使用谷歌应用脚​​本将 xls 转换为谷歌电子表格并出现“空响应”错误
【发布时间】:2017-06-01 23:57:35
【问题描述】:

我正在尝试使用以下代码将 xls 文件转换为 google 电子表格:

  var searchFor ="fullText contains 'theFile.xls' and '" + FolderId + "' in parents";  
  var files = DriveApp.searchFiles(searchFor); 
  var file = files.next().getBlob();  
  var convertedFileinfo = {
    title: 'theFile',
    parents:[{id: FolderId}]
  };
  Drive.Files.insert(convertedFileinfo, file, {
    convert: true,
    uploadType:'resumable'
  })

但我在 Drive.Files.insert 行上收到“空响应”错误...

我做错了什么?

【问题讨论】:

    标签: excel google-apps-script google-sheets drive


    【解决方案1】:

    接下来的变化怎么样?

    发件人:

    Drive.Files.insert(convertedFileinfo, file, {
      convert: true,
      uploadType:'resumable'
    })
    

    收件人:

    Drive.Files.insert(convertedFileinfo, file, {
      convert: true
    })
    

    【讨论】:

    • @Luis Gómez Guzmán 在我的环境中,它运行良好。您能否确认它是否在Advanced Google Services 和 Google API 控制台启用了 Drive API?如果这也已经完成了,我很抱歉。
    • 是的,我添加了uploadType:'resumable' 参数,因为 xls 文件大约有 26 Mb。它适用于大约 5 Mb 的文件...
    • @Luis Gómez Guzmán 在我的环境中,大约 5.4MB 是 Drive API v2 和 v3 从 xls 转换为电子表格的限制。很抱歉,我无法为您提供帮助。
    【解决方案2】:

    我终于用 copy 让它工作了:

      var searchFor ="fullText contains 'theFile.xls' and '" + FolderId + "' in parents"; 
      var files = DriveApp.searchFiles(searchFor); 
      var xlsFile = files.next();    
      Drive.Files.copy({}, xlsFile.getId(), {convert: true}); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-30
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多