简体   繁体   English

在以下所有选项卡上添加相同单元格的 Google 表格

[英]Google Sheet that adds the same cell on all the following tabs

I have a summary sheet called Summary.我有一个叫做摘要的摘要表。 I then have multiple tabs that apply to people - these are named after them eg John Smith, Will Jones, Sally Smith... I want to sum or count the same cell in each of named tabs - how do I do this automatically?然后,我有多个适用于人员的选项卡 - 这些以他们的名字命名,例如 John Smith、Will Jones、Sally Smith ...

What you can actually do is traverse all the sheets and them just sum them up.您实际上可以做的是遍历所有工作表并将它们总结起来。 The sample below shows how to sum all cell 'A1' in all sheets.下面的示例显示了如何对所有工作表中的所有单元格“A1”求和。

function sumCells() {
    const cellLocation = "A1"; 
    const ss = SpreadsheetApp.getActiveSpreadsheet();
    const sheets = ss.getSheets().filter(function (sheet) {
      return sheet.getSheetName() != "Summary";
    }); // added filter to exclude Summary sheet from the calculation

    var sum = 0;
    var sheetName, cell, value;
    sheets.forEach((sheet) => {
        sheetName = sheet.getName();
        cell = sheet.getRange(cellLocation)
        value = cell.getValue();
        sum += parseFloat(value); // if has decimal
        // sum += parseInt(value); // if has whole numbers (no decimal)
    })
    Logger.log(sum);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM