5

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;)

miodf
  • 524
  • 3
  • 9
  • 21

1 Answers1

5

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

Serge insas
  • 45,904
  • 7
  • 105
  • 131
  • Thank you very much for your help. I went trough it but it is too much for me. No disrespect, but by luck do you know someone or someplace (like donationcoder ..) where I could pay to get it done and move on something else ? Many thanks. ;) – miodf Aug 19 '14 at 08:22
  • I'll give it a try and suggest a code... but right now I don't have time so give me a few hours ;-) – Serge insas Aug 19 '14 at 09:01
  • Hello Serge, I guess that this should helps https://code.google.com/p/google-apps-script-issues/issues/detail?id=1019#c20 Thanks ;) – miodf Sep 25 '14 at 16:46
  • Mmmmh, I'm afraid I forgot this... sorry...:-) I'll do it tonight. – Serge insas Sep 25 '14 at 17:37
  • I hope this edit will allow you to complete your project, deleting the files once converted is straightforward: xFile.setTrashed(true); – Serge insas Sep 26 '14 at 17:11
  • Thank you very much Serge. I have tested the code and it seems that "contains" search only in the beginning of the title (see "[1] The contains operator only performs prefix matching for a title. For example, the title "HelloWorld" would match for title contains 'Hello' but not title contains 'World'." of https://developers.google.com/drive/web/search-parameters?hl=ja ). As a workaround I have modified the code to `var files = DriveApp.getFolderById('0Bzz_oyNohY-wQVZBMTFnV1R1ZEk').searchFiles('title != "nothing"');`. – miodf Oct 08 '14 at 18:14
  • The only thing that didn't work was that it created the converted files in the root folder of my google drive. Thanks again. ;) – miodf Oct 08 '14 at 18:15
  • Fyi: To get the converted files into a folder follow these guidelines https://stackoverflow.com/questions/44207511/google-apps-scripts-how-to-save-files-from-root-to-a-specific-folder – miodf Sep 07 '17 at 18:21