title: Convert any xls-xlsm files to Google Sheet format and overwrite the oldest existing GS file with that name
body: <p>I decided to open this topic because there is very little material in this regard and in my opinion many are asking the same question. I'm trying to write an script to convert an <code>.xls</code> or a <code>.xlsm</code> file stored on Google Drive to a Google Sheets file. I'm not interested in converting macros inside the <code>.xlsm</code> file, only converting the base file. This script should be able to overwrite the oldest file with the new one if it has the same name.</p>
  
  <p>The topics in which I found more material are these:</p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/26854563/how-to-automatically-import-data-from-uploaded-csv-or-xls-file-into-google-sheet">How to automatically import data from uploaded CSV or XLS file into Google Sheets</a></li>
  <li><a href="https://stackoverflow.com/questions/11681873/converting-xls-to-google-spreadsheet-in-google-apps-script">Converting .xls to google spreadsheet in google apps script</a></li>
  <li><a href="https://stackoverflow.com/questions/25368143/convert-all-xls-files-available-in-a-folder-into-google-doc-spreadsheets">Convert all xls files available in a folder into &quot;Google Doc Spreadsheets&quot;?</a></li>
  </ol>
  
  <p>these topic links inserted above are partial and in any case they do not allow the conversion of the <code>.xlsm</code> format.</p>
  
  <p>I started from this code (taken from <a href="https://stackoverflow.com/questions/26854563/how-to-automatically-import-data-from-uploaded-csv-or-xls-file-into-google-sheet/26858202#26858202">here</a>), but I don't know how to modify it to make it convert both the <code>.xls</code> and <code>.xlsm</code> files and let them overwrite them if they are already in Google Drive</p>
  
  <pre><code>/**
  * Sample use of convertExcel2Sheets() for testing
  **/
  function testConvertExcel2Sheets() {
    var xlsId = "0B9**************OFE"; // ID of Excel file to convert
    var xlsFile = DriveApp.getFileById(xlsId); // File instance of Excel file
    var xlsBlob = xlsFile.getBlob(); // Blob source of Excel file for conversion
    var xlsFilename = xlsFile.getName(); // File name to give to converted file; defaults to same as source file
    var destFolders = []; // array of IDs of Drive folders to put converted file in; empty array = root folder
    var ss = convertExcel2Sheets(xlsBlob, xlsFilename, destFolders);
  }
  </code></pre>
  
  <p>I would like to thank anyone who decided to help me and therefore to give all those who are asking the same question.</p>