[英]Google Spreadsheet, Checking the name of the sheet with a cell in a sheet
I have a Google spreadsheet with 3 sheets. 我有一个包含3张纸的Google电子表格。
In the first sheet I have a resume of the two other sheet. 在第一张纸上,我有另外两张纸的简历。 This sheet has a column "C" where the name of the sheet corresponding to the resume is written.
该工作表具有一列“ C”,其中写有与简历相对应的工作表名称。
Now I want a script that checks the name of the sheets and color the corresponding cell in column "C" into red if the name matches with the one in column "C". 现在,我需要一个脚本来检查工作表的名称,如果名称与“ C”列中的单元格匹配,则将“ C”列中的相应单元格上色为红色。
I have written this code but doesn't seem to be working! 我已经编写了这段代码,但似乎没有用!
function myFunction() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
var ss = SpreadsheetApp.getActiveSpreadsheet();
var columnC = sheet.getRange (1, 3, sheet.getLastRow(), 1);
var Cvalues = columnC.getValues();
var allSheets = ss.getSheets();
var allSheetNames = new Array();
for (var i = 0; i < allSheets.length; i++)
{
allSheetNames.push(allSheets[i].getName());
}
for (var j=0 ; j < Cvalues.length; j++)
{
if (Cvalues[j][0] == allSheets) {
sheet.getRange( j, 1, 1, 1).setBackgroundColor('red');}
}
}
Problem here: 问题在这里:
if (Cvalues[j][0] == allSheets) {
Your allSheets
is an array, so the value in Cvalues[j][0]
can never be equal to it. 您的
allSheets
是一个数组,因此Cvalues[j][0]
值永远不能等于它。 What you probably want it to determine if Cvalues[j][0]
appears anywhere in allSheets
. 您可能希望它确定
Cvalues[j][0]
出现在allSheets
中的任何地方。 Here's how you'd do that: 这是您的处理方式:
if (allSheets.indexOf(Cvalues[j][0]) !== -1) {
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.