如何使用Google表格脚本计算包含特定文本的单元格的数量? [英] How to count the number of cells which contain specific text using Google Sheet Scripts?

查看:202
本文介绍了如何使用Google表格脚本计算包含特定文本的单元格的数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Google表格脚本计算包含特定文本的单元格的数量?

How to count the number of cells which contain specific text using Google sheet scripts?

当前,我正在使用以下脚本来计算包含特定文本的单元格的数量,例如,包含完整"或未完成"的单元格.

Currently I'am using the following script to count the number of cells which contain specific text, for example cells which contain: 'Complete' or 'Not Complete'.

function COUNT_TEXT_ACROSS_SHEETS(sheetNames, range, text) {
  sheetNames = sheetNames.split(',');
  var count = 0;
  sheetNames.forEach(function(sheetName) {
    var sheet = SpreadsheetApp.getActive().getSheetByName(sheetName);
    var values = sheet.getRange(range).getValues();
    values.forEach(function(row) {
      row.forEach(function(cell) {
        if (cell.indexOf(text) !== -1 ) count++;
      });
    });
  });
  return count;
};

当前脚本对包含文本完成"和不完整"的两个单元格进行计数,有一种方法可以修改脚本以仅对包含完整单词"Complete"的单元格进行计数还计算包含未完成"的单元格,因为该单元格还包含关键字"Complete"?

Currently the script counts both cells which contain the text 'Complete' and 'Not Complete' is there a way to modify the script to only count cells which contain the full word 'Complete' instead of also counting cells which contain 'Not Complete' because the cell also contains the keyword: 'Complete'?

当前脚本的用法示例:

=COUNT_TEXT_ACROSS_SHEETS("Sheet1", "C1:C1000", "NOT COMPLETE")

推荐答案

使用

用法:

=COUNT_SS()

这篇关于如何使用Google表格脚本计算包含特定文本的单元格的数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆