简体   繁体   English

Google Spreadsheet,使用工作表中的单元格检查工作表的名称

[英]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.

相关问题 Google脚本可将电子表格中的工作表复制到新电子表格,并以特定单元格命名新电子表格 - Google script to copy sheet in spreadsheet to new spreadsheet and name new spreadsheet after specific cell 如何在 Google 电子表格中获取每张工作表的名称 - How to get name of each sheet in Google Spreadsheet Google 表格:如何将电子表格文件中的单个表格另存为 PDF,其中文件名基于特定单元格内容? - Google sheets: How to save a single sheet in a spreadsheet file as PDF, where the file name is based on a certain cell content? 如何将 Google 电子表格的特定表格和 CSV 值保存在同一电子表格中另一表格的单个单元格中? - How to save a specific sheet of Google Spreadsheet a CSV values in a single cell of another sheet within the same Spreadsheet? 根据该工作表中的单元格命名工作表 - Name a sheet based on a cell in that sheet Google Sheet(脚本)将Sheet复制到另一个SpreadSheet并在目标SS中命名新工作表 - Google Sheet (Script) copy Sheet to another SpreadSheet and name new sheet in target SS Google Spreadsheet-如何将单元格数据从一张工作表复制到另一张工作表中的单元格? - Google Spreadsheet - How to copy cell data from one sheet to a cell in another sheet? 清除单元格并获取 Google 工作表名称 - Clear a cell and fetch the Google sheet name 如何制作一个按钮以跳到Google Spreadsheet中另一个工作表中的特定单元格? - How to make a button to jump to a specific cell in another sheet in Google Spreadsheet? 即使已移动工作表,也超链接到Google电子表格最左侧工作表中的单元格/行? - Hyperlink to a cell/row in the leftmost sheet of Google spreadsheet, even if sheets are moved?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM