使用Google脚本循环浏览多个Google电子表格 [英] Looping through multiple google spreadsheets with google scripts
问题描述
因此,我在Google驱动器中有多个不同的电子表格(完全不同的文件,不在同一文件和不同的工作表中),并且我一直在尝试找出一种从所有电子表格中提取数据并填充其中一个的方法主表.但是我一直试图找出的问题是,我似乎找不到一种遍历所有电子表格的方法.
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 a way to pull data from all of the spreadsheets and populate one main sheet. But the problem I've been trying to figure out is that I can't seem to find a way to loop through all the spreadsheets.
我阅读了关于另一个类似问题的建议,他们说要创建一个不同的电子表格,该电子表格将所有电子表格ID存储在其中.但是我的另一个问题是,当我运行该应用程序时,我不知道有多少电子表格.
I've read a suggestion on another similar question in which they said to create a different spreadsheet that stored all the spreadsheet id's inside of it. But my other problem is I won't know how many spreadsheets there are when I run the application because more are added all the time.
因此,由于它们似乎不是遍历驱动器中所有电子表格的一种方式,因此它们是在Google脚本中进行创建的一种方式,以便在创建文件时,脚本便可以运行并能够获取新创建的文件ID?
So, since their doesn't seem to be a way to loop through all the spreadsheets in your drive, is their a way in google scripts to make it so that anytime a file is created, the script runs and is able to obtain the newly created file id?
谢谢,伊桑.
推荐答案
Google表格的MIME类型为:
Google Sheets have a MIME type of:
application/vnd.google-apps.spreadsheet
您可以遍历驱动器中的所有文件并记录所有文件的MIME类型,只是查看可能有哪些不同的MIME类型:
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());
}
};
您可以按某种MIME类型获取所有文件.此代码将驱动器中所有电子表格的名称打印到LOG.
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.
这篇关于使用Google脚本循环浏览多个Google电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!