79529613

Date: 2025-03-23 20:11:41
Score: 0.5
Natty:
Report link

Modified script with Drive API v3:

Before you use this script, please enable Drive API at Advanced Google services.

Click in "Services" options on Google AppScripts and enable Drive API v3

Now add the script.

function importXLS(){
  var folderBId = "###"; // Added // Please set the folder ID of "FolderB".
  var files = DriveApp.getFolderById('1hjvNIPgKhp2ZKIC7K2kxvJjfIeEYw4BP').searchFiles('title != "nothing"');

  while(files.hasNext()){
    var xFile = files.next();
    var name = xFile.getName();

    // Check if the file has the MimeType .xslx 
    if (xFile.getMimeType() == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"){ 
      var ID = xFile.getId();
      var xBlob = xFile.getBlob();
      var newFile = {
        title : name+'_converted',
        parents: [ folderBId ] //  Added
      };
      file = Drive.Files.create(newFile, xBlob, {
        convert: true,
        mimeType: "application/vnd.google-apps.spreadsheet"
      });
      // Drive.Files.remove(ID); // Added // If you want to remove the original XLSX. 
    }
  }
}

References:

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Ericksan Pimentel