4
votes

The basic way to do that is turn conversion on when uploading files into Google Drive.

Another way is to select the xls file in the folder and convert it one by one by hand.

But if one has already many xls files uploaded in a folder, it may be faster to convert them with Google Apps Script than re-uploading again the files.

In my case:

  • once converted, I need to delete the xls files
  • all xls files are below the limits : "Uploaded spreadsheet files that are converted to the Google spreadsheets format can’t be larger than 100 MB, and need to be under 400,000 cells and 256 columns per sheet." https://support.google.com/drive/answer/37603?hl=en

Thanks in advance;)

1
The added JavaScript tag is not a good idea, this is very specific to Google-Apps-Script and Drive.Serge insas
Thanks. I have removed it.;)miodf
Thanks, I was actually looking just for your first sentence solution: spreadsheetpoint.com/convert-excel-to-google-sheetsPedro Reis

1 Answers

4
votes

you should use the Advanced Drive Service, file update

This service must be enabled before use but the doc is pretty clear.


EDIT (following your comments)

(sorry for the long delay, I forgot this post)

This code will convert every XLS files in your drive to Google spreadsheet format (as long as their names have an .xls extension)

You must authorize the Drive extended ressource + API console (follow the instructions from the ressource/advanced services menu, see illustration below)

function importXLS(){
  var files = DriveApp.searchFiles('title contains ".xls"');// you can also use a folder as starting point and get the files in that folder... use only DriveApp method here.
  while(files.hasNext()){
    var xFile = files.next();
    var name = xFile.getName();
    if (name.indexOf('.xls')>-1){ // this check is not necessaey here because I get the files with a search but I left it in case you get the files differently...
      var ID = xFile.getId();
      var xBlob = xFile.getBlob();
      var newFile = { title : name+'_converted',
                     key : ID
                    }
      file = Drive.Files.insert(newFile, xBlob, {
        convert: true
      });
    }
  }
}

enter image description here