How to Automation Convert Excel on Drive change to Spreadsheet using Apps Script

As we know , Apps Script is program of Google Sheet the same VBA of Excel. Therefore, Today I want to introduction to everyone the method after upload excel file to Drive of Google and how to automation convert to Spreadsheet using Apps Script. Everyone see as below the code:

For example we can take the excel file name is DATA_202403.xlsx

function convertExcelToGoogleSheets_01() {

  var value = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(“Useful”).getRange(1, 1).getValue();//the value 202403 that we get from the specific sheet of spreadsheet

  let files = DriveApp.getFilesByName(“DATA_”+value+”.xlsx”);//Combine to completely the file name exist in teh drive

  let excelFile = null;

  if(files.hasNext())

    excelFile = files.next();

  else

    return null;

  let blob = excelFile.getBlob();

  let config = {

    title:  excelFile.getName(),//Export the file name the same original excel file name . We can change if we want to change it

    parents: [{id: excelFile.getParents().next().getId()}],

    mimeType: MimeType.GOOGLE_SHEETS

  };

  let spreadsheet = Drive.Files.insert(config, blob);

  return spreadsheet.id;

}

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Me on Zalo
Days :
Hours :
Minutes :
Seconds

Experience the free automation consulting service for your first 3 days use
Discount 50% After 3 Days