簡體   English   中英

在以下所有選項卡上添加相同單元格的 Google 表格

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

我有一個叫做摘要的摘要表。 然后,我有多個適用於人員的選項卡 - 這些以他們的名字命名,例如 John Smith、Will Jones、Sally Smith ...

您實際上可以做的是遍歷所有工作表並將它們總結起來。 下面的示例顯示了如何對所有工作表中的所有單元格“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