如何合并脚本,以便一个停止撤消另一个 [英] How to merge scripts so one stops undoing the other
问题描述
我已经在下面编写了脚本,以隐藏所有选中了特定框的行,或者隐藏其他单元格中包含较新"一词的行.我遇到的问题是,当我运行hideReviewed_函数时,它将撤消第二个函数hideNewer_完成的隐藏行.如何混合这2个以便可以运行1个功能,它既看起来又同时隐藏两个复选框和表示较新"的项目?
I have written the script below to hid all rows that have a specific box checked or if a different cell has the word "Newer". The problem I am running into is that when I run the hideReviewed_ function it undoes the hidden rows done by the second function hideNewer_. How do I blend these 2 so that I can run 1 function and it will look and both and hid the both the checked boxes and the items that say "Newer"?
function onOpen() {
var spreadsheet = SpreadsheetApp.getActive();
var menuItems = [
{name: 'Reviewed', functionName: 'hideReviewed_'},
{name: 'Newer', functionName: 'hideNewer_'}
];
spreadsheet.addMenu('Hiding Time', menuItems);
}
function hideReviewed_() {
var s = SpreadsheetApp.getActive().getSheetByName('2 Week Snapshot');
s.showRows(1, s.getMaxRows());
s.getRange('C:C')
.getValues()
.forEach( function (r, i) {
if (r[0] == 1)
s.hideRows(i + 1);
});
}
function hideNewer_(e) {
var s = SpreadsheetApp.getActive().getSheetByName('2 Week Snapshot');
s.showRows(1, s.getMaxRows());
s.getRange('J:J')
.getValues()
.forEach( function (r, i) {
if (r[0] == 'Newer')
s.hideRows(i + 1);
});
}
推荐答案
在这里:
function hideReviewed() {
var s = SpreadsheetApp.getActive().getSheetByName('Sheet1');
s.showRows(1, s.getMaxRows());
s.getRange('C:J').getValues().forEach(function (r, i) {if (r[0] == 1 || r[7] == "Newer") s.hideRows(i + 1)});
}
所做的更改:
- 我得到了整个范围C:J
- 在if语句中,我检查r [0]是否等于1或r [7]是否等于较新".
r [0]是C列 r [7]是J列
r[0] is Column C r[7] is Column J
在一个示例电子表格中对此进行了测试,并且似乎可以正常工作. 希望这会有所帮助.
Tested this in a sample spreadsheet and seems to be working as intended. Hope this helps.
之前:
之后:
这篇关于如何合并脚本,以便一个停止撤消另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!