如何使用复选框隐藏Google表格中的列 [英] How to hide columns in Google Sheet with checkboxes

查看:143
本文介绍了如何使用复选框隐藏Google表格中的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我弄清楚如何通过使用Google表格中的复选框来隐藏/取消隐藏列.

Could someone help me figure out how to be able to hide/unhide columns by using a checkbox in Google Sheets.

例如,该复选框位于N4中,而我想隐藏/取消隐藏从OR的列:

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(选中了复选框),则将列OR隐藏.
      • 如果该值为false(未选中复选框),则显示OR列.
      • If the value is true (checkbox is checked), then hide columns O to R.
      • If the value is false (checkbox is unchecked), then show columns O to R.

      如果您希望相反,则在条件中交换"TRUE""FALSE"值.

      If you wish it to be the other way around then swap the "TRUE" and "FALSE" values in the conditional.

      希望对您有帮助!

      • Event Objects | Apps Script | Google Developers
      • Simple Triggers | Apps Script | Google Developers
      • Class Sheet: hideColumns(columnIndex, numColumns)
      • Class Sheet: showColumns(columnIndex, numColumns)

      这篇关于如何使用复选框隐藏Google表格中的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆