SUM 不同工作表中选定的行,但工作表的数量可以增加超时

SUM selected rows in various sheets, but number of sheets can increment overtime

让我们假设我们有一个未知数量的 sheets 像 Employe1、Employe2、Employe3 随着时间的推移递增。所以以后会有Employee4,Employee5等等sheet。它们都有完全相同的列和行。当我添加新员工时,我的应用程序正在制作它们。我需要做的是对现有 sheet 报告中的所有值求和,该报告与员工 sheet 具有相同的结构。

因此,当创建新员工 X sheet 时,我需要考虑到这一点并计算报告 sheet 中的值。 这能以某种方式自动化吗?

提前致谢!

使用 Google 应用程序脚本,我设法实现了必要的目标。

function SUMALLSHEETS(range, excluded) {
    try {
        var sum = 0,
            ex = (excluded) ? Trim(excluded.split()) : false;
        SpreadsheetApp.getActive()
            .getSheets()
            .forEach(function (s) {
                if (ex && ex.indexOf(s.getName()) === -1 || !ex) {
                    s.getRange(range)
                        .getValues()
                        .reduce(function (a, b) {
                            return a.concat(b);
                        })
                        .forEach(function (v) {
                            sum += (!isNaN(parseFloat(v) && isFinite(v))) ? v : 0;
                        });
                };
            });
        return sum;
    } catch (e) {
        throw e.message;
    }
}

function Trim(v) {
    v = (v === null || typeof v == 'undefined') ? '' : v.toString();
    return v.replace(/^\s\s*/, "")
        .replace(/\s\s*$/, "");
}