Google 表格 - 条件自定义公式

问题描述 投票:0回答:1

我使用什么条件公式来仅突出显示“开始”和“结束”日期列之间的单元格,并使用从“状态”列中选择的颜色。例如,当状态为“暂停”时,“开始”和“结束”日期之间的单元格会突出显示为橙色。

google-sheets google-sheets-formula conditional-formatting
1个回答
0
投票

使用数据验证更改自动应用背景:


正如 ztiaa 所提到的,实现此目的的一种方法是为每个单元格创建 6 个条件格式规则。我知道这可能会很累。我已经为您的项目创建了一个脚本,它将为您进行自动更改。由于我只能目测您想要的颜色,所以我的颜色设置略有不同。


代码示例:


function onEdit(e) {

const colorMap = [["PLANNED", '\\\#0b5394'],["ON HOLD", '\\\#e69138'],["ASSIGNED", '\\\#e06666'],["IN PROGRESS", '\\\#b4a7d6'],["READY", '\\\#34a853'],["PUBLISHED", '\\\#783f04']];// Map for your Color var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheetByName("Sheet1");// Simple Declaration for your Google Sheet. Please change this according to your Sheet Name. var changeRow = e.range.getRow(); var changedCol = e.range.getColumn(); // Detect Columns and Row for validation purposes that it will only act when change are made on the right column and rows. if (changedCol == 2) { var statusValues = e.range.getValue(); for(i = 0; i < colorMap.length; i++) { if (statusValues == colorMap[i][0]) {

sheet.getRange(changeRow, 6, 1, 2).setBackground(colorMap[i][1]); // Applies changes of the Background } } } }

© www.soinside.com 2019 - 2024. All rights reserved.