Looping through multiple google spreadsheets with google scripts

前端 未结 2 834
故里飘歌
故里飘歌 2021-01-15 20:46

So I have multiple different spreadsheets inside of google drive (completely different files, not in the same file and different sheets), and I\'ve been trying to figure out

2条回答
  •  臣服心动
    2021-01-15 21:24

    Google Sheets have a MIME type of:

    application/vnd.google-apps.spreadsheet

    You can loop through all the files in your drive and log the MIME types of all the files, just to see what different MIME types might be:

    function getAllSheets() {
     // Log the name of every file in the user's Drive.
     var files = DriveApp.getFiles();
       while (files.hasNext()) {
         var file = files.next();
         Logger.log(file.getMimeType());
     }
    };
    

    You can get all files by a certain MIME type. This code prints the names of all the spreadsheets in your drive to the LOG.

    function getAllSheets() {
     // Log the name of every file in the user's Drive.
     var files = DriveApp.getFilesByType("application/vnd.google-apps.spreadsheet")
       while (files.hasNext()) {
         var file = files.next();
         Logger.log(file.getName());
     }
    };
    

    So, you can iterate through all the spreadsheets in your drive, or in a specific folder.

提交回复
热议问题