0

我在 Google Drive 电子表格中有一个简单的电子表格,其中包含 colA 中的名称列表。ColB 到 ColJ 填写空白单元格。

当没有通过 ColJ 在 ColB 中输入数据时,我想更改 ColA 中单元格的背景颜色,但我看不到这样做的方法。

4

2 回答 2

1

您会认为条件格式会提供此功能,但它不允许您引用其他单元格。(与 Excel 不同。)

这是一个可以完成这项工作的脚本。(如果您不熟悉 Google Apps 脚本,请阅读此介绍。)

/**
 * The onEdit() function, when defined, is automatically invoked whenever the
 * spreadsheet is edited. (Not every change is an "edit".)
 *
 * If all of the "fill in the blanks" columns are empty, set the
 * background color of the name column in that row.
 */
function onEdit(event) {
  var row = event.range.getRow();
  var sheet = event.range.getSheet();
  var cellA = sheet.getRange(row,1);
  // Get the range of cells B-J that make up the "fill in the blanks" range...
  var fillInTheBlanks = sheet.getRange(row, 2, 1, 9)
                             .getValues()[0]  // ... get values in 0-th row
                             .join('');       // ... and join into one string

  // Check that string - if it is empty, the range was blank,
  // and we should set the background color to, say, yellow.
  if (fillInTheBlanks.length == 0) {
    cellA.setBackground("yellow");
  }
  // On the other hand, if the string was NOT blank, there is something
  // in the "fill in the blanks" range, so we will clear the background.
  else {
    cellA.setBackground("white");
  }
}

/**
 * The onOpen() function, when defined, is automatically invoked whenever the
 * spreadsheet is opened.
 *
 * Iterates through all rows in spreadsheet, faking onEdit triggers, as if
 * each name has been edited.
 */
function onOpen() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet();
  var lastRow = sheet.getLastRow();
  for (var row=1; row <= lastRow; row++) {
    onEdit({range:sheet.getRange('A'+row)});
  }
};
于 2013-05-29T03:01:47.687 回答
0

从 ColumnA 清除格式,选择 ColumnA 和格式,条件格式...,如果... 则设置单元格格式自定义公式为

=and(A1<>"",counta(B1:J1)=0)

然后选择填充选择和Done

于 2017-06-06T02:25:35.187 回答