如果单元格与使用Apps脚本的不同工作表列表中的单元格匹配,则设置条件格式
原学程将引见假如单位格与应用Apps剧本的分歧任务表列表中的单位格婚配,则树立前提格局的处置办法,这篇学程是从其余处所瞅到的,而后减了1些海外法式员的疑问与解问,愿望能对于您有所赞助,佳了,上面开端进修吧。
成绩描写
我在1个选项卡上有1个赓续变更的数字列表,假如该单位格涌现在另外一个数字列表中、分歧的任务表中,我愿望对于其运用前提格局。
Potential Cities/Zip-Codes
List of Blocked Zip Codes
我愿望重要";潜伏乡市";任务表上的邮政编码在";阻拦的邮政编码";任务表上列出时格局化。
其目标是创立格局变动,假如用户试图输出的邮政编码被阻拦(或者在列表中),该变动将异常清晰天向用户显示。惯例前提格局没有起感化,由于复制/粘贴将笼罩CF规矩。我借须要可以或许将处理计划运用于多个分歧的任务表,这些任务表皆在依据被阻拦的单位格列表检讨其单位格。
推举谜底
您不妨为您的潜伏乡市电子表格创立installable onEdit()
trigger,该电子表格检讨阻拦的Zips任务表能否婚配,并响应天运用某种格局。
比方:
function checkForBlockedZips(e) {
// do nothing if not column D
if (e.range.getColumn() !== 四) return
// get list of zips from blocked zips sheet
const blockedZipsSsId = "your-spreadsheet-id"
const blockedZipsSs = SpreadsheetApp.openById(blockedZipsSsId)
const blockedZipsSheet = blockedZipsSs.getSheetByName("Sheet一")
const zipCodes = blockedZipsSheet.getRange("A二:A").getValues()
.flat(二)
.filter(x => x)
// check if the entered value is in the list of blocked zips
if (~zipCodes.indexOf(e.range.getValue())) {
// create cell style
const strikethrough = SpreadsheetApp.newTextStyle()
.setStrikethrough(true)
.build()
const richText = SpreadsheetApp.newRichTextValue()
.setText(e.range.getValue())
.setTextStyle(strikethrough)
.build()
// set the cell to have the desired rich text style
e.range.setRichTextValue(richText).setBackground("yellow")
}
else {
// if the value is not a blocked zip then reset the cell style
const nostrikethrough = SpreadsheetApp.newTextStyle()
.setStrikethrough(false)
.build()
const richText = SpreadsheetApp.newRichTextValue()
.setText(e.range.getValue())
.setTextStyle(nostrikethrough)
.build()
e.range.setRichTextValue(richText).setBackground("white")
}
}
留意事变:
您须要应用e.range.getValue()
而没有是e.value
,以就不妨读与复制/粘贴的值
您须要将此剧本添减到潜伏乡市任务表中,并将其受权为可装置触收器
佳了闭于假如单位格与应用Apps剧本的分歧任务表列表中的单位格婚配,则树立前提格局的学程便到这里便停止了,愿望趣模板源码网找到的这篇技巧文章能赞助到年夜野,更多技巧学程不妨在站内搜刮。