0
votes

I am working on a script that auto uploads .xls files into google drive from gmail and I am hitting a roadblock trying to convert the .xls file into a google sheet. The code block below was adapted from the following article: https://www.labnol.org/code/20500-convert-microsoft-excel-xlsx-to-google-spreadsheet

the variable filename is a predefined global variable

Code Snippet:

function advancedDrivetest() {
  try
  { 
    var FILE = DriveApp.getFilesByName(filename).next();
    var fileID = FILE.getId();
    var FILEname = "test_convert";
    var blob = FILE.getBlob();
    var resource = {
      title: FILEname
    }
    Drive.Files.insert(resource, blob, {convert: true});
  }
  catch(f)
  {
    Logger.log(f.toString());
  }
}

Note: I have enabled the advanced drive API in resources > Advanced drive services and in my google cloud project.

The code block above returns the rather unhelpful error mentioned in the title.

1
How long have you been receiving this error? Sometimes Google is having trouble and you just need to wait. if (!GmailApp) return; checks to see if gmail is down.Stykes
This works perfectly fine in my test environment. Make sure that filename contains the .xlsx extension in its definition (for example var filename = "nameOfFile.xlsx").Rafa Guillermo
@RafaGuillermo thanks for the feedback I'll definitely try that. I'm a little confused on the syntax of how this works. Am I submitting the full name of the file to be converted or what I want the file name to be? I've seen both in my research and google's documentation is unhelpful as usual.Jakers
@Stykes unfortunately I have not gotten this to work once. None of the services involved are having downtime.Jakers
Upon further investigation there seems to be a formatting error with the files I have been trying to feed into this script. Once I tried a basic test sheet it worked with no problem. Thanks all for your time!Jakers

1 Answers

0
votes

Script was working fine but files I was giving it to convert were corrupt and could not be opened/converted by Google Drive API