我是一個想成為開發人員的人,他試圖弄清楚如何根據單擊的復選框隱藏一組列。
有人愿意幫忙處理這個代碼嗎?
我有 12 張不同的作業表(每個月一張),我想用單擊中的復選框隱藏 AH 列。
理想情況下,我可以在每張紙上實施。

鏈接到電子表格
uj5u.com熱心網友回復:
有幾種方法可以做到。
其中最簡單和最推薦的是對這些列進行分組,它的用途與您正在尋找的用途幾乎相同。
如果您愿意為此使用 appscript。操作方法如下:- 從電子表格中打開腳本編輯器。宣告onEdit簡單觸發器,該觸發器將在每次編輯作業表時運行。因此,無論何時您單擊 I1 上的復選框,都會觸發此功能。當觸發器觸發時,Apps 腳本將一個事件物件作為引數傳遞給函式,通常稱為e。對于這個物件,我們將擁有完成任務所需的資訊,并將我們的操作限制在那些月份的作業表和屬于它的范圍內。
這是代碼,我盡力解釋代碼中發生的事情:-
function onEdit(e)
{
var rangeEdited = e.range; // This will us range which is edited
var sheetEdited = rangeEdited.getSheet().getName() // from range we can get the sheetName which is edited
var mySheets = ["Jan List","Feb List"] // Put all the month sheet name in this array where you want to have this functionality
var rowEdited = rangeEdited.getRow() // From Range we can get Row which is edited
var columnEdited = rangeEdited.getColumn() // From Range we can get Column which is edited
if(mySheets.indexOf(sheetEdited) > -1) // Now we want to only restrict the operation on those sheets,so if other sheet is edited, we shouldn't run our hide function
{
if(rowEdited === 1 && columnEdited === 9) // we're further restricting the range of operation to run this function when only I1 is edited that is Row:- 1 and Col:- 9
{
hideUnhide(sheetEdited) // calling our hide function within OnEdit and passing sheetName as an argument in it
}
}
}
function hideUnhide(sheetEdited) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ssname = ss.getSheetByName(sheetEdited) // accessing the sheet which is edited
var isItHidden = ssname.isColumnHiddenByUser(1) // checking if range is already hidden
if(isItHidden === false) // if No, hide that range
{
ssname.hideColumns(1, 6)
}
else // if Yes, unhide that range
{
var hideThisRange = ssname.getRange('A:H')
ssname.unhideColumn(hideThisRange)
}
}
檔案:- AppScript 事件
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/392669.html
上一篇:應用程式腳本中不同列(不同行)中具有相同值的顏色單元格
下一篇:行的連接塊
