我已经构建了一个从多个电子表格中提取并计算总值的脚本。基本上发生的情况是多个员工将为特定客户输入在特定任务上执行的时间。然后我想计算在主电子表格上为特定客户完成了多少工作并提取一些分析。
因此,在主电子表格上,每个客户都有一个选项卡。此函数从主电子表格中获取工作表名称并创建所有客户名称的数组。我这样做的原因是,如果创建了一个新选项卡,该客户名称将自动包含在客户数组中。
function getCurrentCustomers() {
var sheets = servicesSpreadsheet.getSheets();
for (var i=0 ; i < sheets.length ; i++) {
if (sheets[i].getName() != "Services" && sheets[i].getName() != "Employee Files") {
currentCustomers.push(sheets[i].getName());
};
};
};
Run Code Online (Sandbox Code Playgroud)
下一个函数查看特定 Google Drive 文件夹中的所有文件并返回数组中的 ID。这允许我创建存储在此特定文件夹中的员工电子表格的副本,并且该电子表格的值将在更改时自动计算。
function listFilesInFolder() {
var folder = DriveApp.getFolderById("0B7zrWIHovJrKVXlsaGx0d2NFT2c");
var contents = folder.getFiles();
var cnt = 0;
var file;
while (contents.hasNext()) {
//Finds the file in the specified folder
var file = contents.next();
//Increases the count
cnt++;
//Gets the Id of the file
data …Run Code Online (Sandbox Code Playgroud)