根据条件格式颜色从单元格中清除注释
Clear note from cells based on conditional formatting color
我有一个 Google Sheet 脚本可以清除 sheet 中的所有笔记,该脚本每天都会触发 运行。我真的希望它只是在当天有条件格式化为绿色的单元格中“清除注释”。作为背景信息,附加组件会自动将注释添加到各个单元格,但是当单元格再次变为绿色时,我希望清除附加到该单元格的注释。这可能吗?我已经提供了到目前为止的代码,但与数组 getRange 部分混淆了。谢谢!
function cleargreens() {
var sheet1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Overview");
var data1 = sheet1.getDataRange().getValues(); //2D array of sheet1 cell values
var bg;
for(var i=1; i<data1.length; i++)
{
bg = sheet1.getRange(i+1, 2).getBackground();
if(bg == "#b7e1cd") //this is the conditional green color code
{
sheet1.getRange(i+1, 3).clearNote();
}
My spreadsheet, although the colors I will be searching for will only be in columns E to H
如果您的所有单元格都可能有需要在背景颜色为绿色时删除的注释 - 那么您需要实现一个嵌套循环,它遍历行和列:
function cleargreens() {
var sheet1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Overview");
var data1 = sheet1.getDataRange().getValues(); //2D array of sheet1 cell values
var bg;
//iterates through rows
for(var i=1; i<data1.length; i++)
{
//iterates through columns
for(var j=1; j<data1[0].length; j++)
{
var cell=sheet1.getRange(i+1, j);
bg = cell.getBackground();
if(bg == "#b7e1cd") //this is the conditional green color code
{
cell.clearNote();
}
}
}
}
至于您的困惑,请注意范围是具有行和列索引的二维数组。
我有一个 Google Sheet 脚本可以清除 sheet 中的所有笔记,该脚本每天都会触发 运行。我真的希望它只是在当天有条件格式化为绿色的单元格中“清除注释”。作为背景信息,附加组件会自动将注释添加到各个单元格,但是当单元格再次变为绿色时,我希望清除附加到该单元格的注释。这可能吗?我已经提供了到目前为止的代码,但与数组 getRange 部分混淆了。谢谢!
function cleargreens() {
var sheet1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Overview");
var data1 = sheet1.getDataRange().getValues(); //2D array of sheet1 cell values
var bg;
for(var i=1; i<data1.length; i++)
{
bg = sheet1.getRange(i+1, 2).getBackground();
if(bg == "#b7e1cd") //this is the conditional green color code
{
sheet1.getRange(i+1, 3).clearNote();
}
My spreadsheet, although the colors I will be searching for will only be in columns E to H
如果您的所有单元格都可能有需要在背景颜色为绿色时删除的注释 - 那么您需要实现一个嵌套循环,它遍历行和列:
function cleargreens() {
var sheet1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Overview");
var data1 = sheet1.getDataRange().getValues(); //2D array of sheet1 cell values
var bg;
//iterates through rows
for(var i=1; i<data1.length; i++)
{
//iterates through columns
for(var j=1; j<data1[0].length; j++)
{
var cell=sheet1.getRange(i+1, j);
bg = cell.getBackground();
if(bg == "#b7e1cd") //this is the conditional green color code
{
cell.clearNote();
}
}
}
}
至于您的困惑,请注意范围是具有行和列索引的二维数组。