【发布时间】:2018-04-13 07:03:47
【问题描述】:
我有一个用于工作的电子表格,并且一直在努力根据特定的单元格值隐藏/显示行。
有问题的电子表格为我们的供应商创建了一份合同,并且特定的单元格值(在我的情况下为 F16)应该通过隐藏/显示带有数据的相关行来触发合同中间部分的更改。 幸运的是,所有行都可以分为三个组,因此公式/脚本的最终前提应该是:
cell F16 = "A", "B" or "C" (cell value changes by a vlookup formula in that
cell that is connected to a specific reference number)
Block1 = rows 16 to 27
Block2 = rows 28 to 39
Block3 = rows 40 to 51
if F16 = "A" - show block1, hide block2, hide block3
if F16 = "B" - hide block1, show block2, hide block3
if F16 = "C" - hide block1, hide block2, show block3
一直在玩这个:
function HideSelectedRows2() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName("Contract"); // Enter sheet name
var row = s.getRange('AM:AM')
.getValues(); // Enter column letter that has the texts "Unhide" and
"Hide until here"
// hide all rows except first
s.hideRows(2, s.getMaxRows() - 1);
for (var i = 0; i < row.length; i++) {
// then if the row says "unhide", start unhiding from that row and
unhide 1 row
if (row[i][0] == 'Unhide') {
s.showRows(i + 1);
}
// then if the row says 'Hide' start from the next row and hide until
the end
else if (row[i][0] == 'Hide') {
s.hideRows(i + 1);
}
}
}
但在每次编辑时都要不断地循环遍历行(通过 AM:AM 列,使用 If 公式创建“隐藏”和“取消隐藏”)。太烦人了,因为这些块有可编辑的区域。
希望电子表格读取起始触发器(参考编号)使用 vlookup 公式发挥它的魔力,一旦它更改单元格 F16 中的值,就会根据前提触发隐藏/取消隐藏行。然后就停在那里。
希望我说得通 帮助?想法?
【问题讨论】:
-
也许您应该考虑在脚本中执行所有这些操作并完全消除单元格公式。然后您可以更好地控制所有各个部分
标签: google-apps-script google-sheets