如何使用复选框隐藏Google表格中的列 [英] How to hide columns in Google Sheet with checkboxes
本文介绍了如何使用复选框隐藏Google表格中的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以帮助我弄清楚如何通过使用Google表格中的复选框来隐藏/取消隐藏列.
Could someone help me figure out how to be able to hide/unhide columns by using a checkbox in Google Sheets.
例如,该复选框位于N4
中,而我想隐藏/取消隐藏从O
到R
的列:
For example, the checkbox is located in N4
and I want to hide/unhide column from O
to R
:
谢谢!
推荐答案
答案:
您需要使用onEdit()
触发器.
Answer:
You need to use an onEdit()
trigger.
function onEdit(e) {
if (e.range.getA1Notation() != "N4") return;
if (e.value == "TRUE") {
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().hideColumns(15, 4);
}
else if (e.value == "FALSE") {
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().showColumns(15, 4);
}
}
功能下降:
- 检查是否已编辑的单元格为
N4
- 如果不是
N4
,则什么也不做.
- Checks to see if the edited cell was
N4
- If it isn't
N4
, do nothing.
- 如果该值为true(选中了复选框),则将列
O
至R
隐藏. - 如果该值为false(未选中复选框),则显示
O
至R
列.
- If the value is true (checkbox is checked), then hide columns
O
toR
. - If the value is false (checkbox is unchecked), then show columns
O
toR
.
如果您希望相反,则在条件中交换
"TRUE"
和"FALSE"
值.If you wish it to be the other way around then swap the
"TRUE"
and"FALSE"
values in the conditional.希望对您有帮助!
- 事件对象|应用脚本Google Developers
- 简单触发器|应用脚本Google Developers
- 课程表:
hideColumns(columnIndex, numColumns)
- 课程表:
showColumns(columnIndex, numColumns)
- Event Objects | Apps Script | Google Developers
- Simple Triggers | Apps Script | Google Developers
- Class Sheet:
hideColumns(columnIndex, numColumns)
- Class Sheet:
showColumns(columnIndex, numColumns)
这篇关于如何使用复选框隐藏Google表格中的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- If it isn't
- 如果不是
查看全文