转换为AppScript:根据一天中的日期和时间的条件格式
我正在为Gsheets的大学做学习策划师。我读到,在Gsheets的内置条件格式中,细胞边框无法格式化。这就是为什么我想转换我的con。格式化为应用程序脚本,但是我只知道非常基本的应用程序脚本对我来说很难。
这三个条件格式规则(应用于列g& h,i& j&k& l分别):
=AND($D2=TODAY(); MOD(NOW();1)<TIME(12;0;0))
=AND($D2=TODAY(); MOD(NOW();1)>TIME(12;0;0);MOD(NOW();1)<TIME(18;0;0))
=AND($D2=TODAY(); MOD(NOW();1)>TIME(18;0;0))
d列包含日期,并且该规则颜色cellis g&amp; h如果是在下午12点之前,颜色列i&amp;下午12点和下午6点,以及颜色列K&amp; l如果是下午6点。
正如我还想为边框上色(没有应用程序脚本的情况下,这是不可能的),有人可以帮助我实现此应用程序脚本吗?
I am making a study planner for university in Gsheets. I read that in Gsheets' inbuilt Conditional Formatting, the cell border cannot be formatted. That's why I want to convert my cond. formatting to Apps Script, however this particular case is difficult to me as I only know very basic Apps Script.
The three Conditional Formatting rules are (applied to columns G&H, I&J and K&L respectively):
=AND($D2=TODAY(); MOD(NOW();1)<TIME(12;0;0))
=AND($D2=TODAY(); MOD(NOW();1)>TIME(12;0;0);MOD(NOW();1)<TIME(18;0;0))
=AND($D2=TODAY(); MOD(NOW();1)>TIME(18;0;0))
Column D contains dates, and this rule colors cells G&H if it's before 12pm, colors columns I&J if it's between 12pm and 6pm, and colors columns K&L if it is past 6pm.
As I want to color the borders also, which is not possible without Apps Script, could someone help me to implement this is Apps Script?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我了解,您创建的公式已经返回
true
和false
值,对吗?然后,根据其所包含的价值,将样式应用于它们非常容易。您只需要浏览这些值,检查它们是否包含
true
或false
,然后根据该条件应用样式。Extensions&gt;应用脚本
。从此处,如 @ruben 在评论中提到,您将必须查看应用程序的应用程序脚本文档以应用您想要的样式。
应该澄清的是,这不是最有效的方法,但我认为这是对Google Apps脚本工作方式的很好介绍。要优化此脚本,您应该研究如何使用 >批处理操作 工作并从那里转换脚本。
文档
setBorder(顶部,左,底部,右,垂直,水平,颜色,样式)
From what I understand the formulas you have created already return a
TRUE
andFALSE
value, right?Then it is very easy to apply a style to them depending on the value they contain. You simply have to go through the values, check if they contain
TRUE
orFALSE
, and apply the styles depending on that condition.Extensions > Apps Script
.From here, as @Ruben mentions in the comment, you will have to review the Apps Script documentation to apply the styles you want.
It should be clarified that this is not the most efficient way to do it, but I think it is a good introduction to how Google Apps Script works. For an optimization of this Script you should study how to use
batch operation
works and transform the script from there.Documentation
setBorder(top, left, bottom, right, vertical, horizontal, color, style)
尝试(根据需要适应条件,颜色和范围的范围)
启用Google Sheets API服务
Try (adapt conditions, colors and limits of range as necessary)
enable google sheets api servide