我一直在寻找适合自己情况的解决方案,但只是想出一点点我想要的东西。
正如标题所述,我想根据特定单元格的值隐藏特定列。我确实找到了一个博客,其中有一段30秒的视频,确切地显示了我想做的事,甚至一个代码片段声称它都行得通,但是对于我自己的一生,我无法实现。
这是我编辑的代码。
function HideColumns() {
//open the current spreadsheet and get the value of the named range
var ss = SpreadsheetApp.getActive();
var name = ss.getRangeByName("GameMode");
var namevalue = name.getValue();
var scheme = ss.getRangeByName("Opponent")
var schemevalue = scheme.getValue();
//check the named range and if the value is NOT equal to "Arena" then hide the requested columns
if (namevalue != "Arena") {
var sheet = ss.getSheetByName("Team Builder");
sheet.hideColumns(8);
sheet.hideColumns(9);
sheet.hideColumns(10);
sheet.hideColumns(11);
sheet.hideColumns(12);
sheet.hideColumns(13);
sheet.hideColumns(14);
}
//OTHERWISE make sure the colums are showing
else if (namevalue == "Arena") {
var sheet = ss.getSheetByName("Team Builder");
sheet.showColumns(8);
sheet.showColumns(9);
sheet.showColumns(10);
sheet.showColumns(11);
sheet.showColumns(12);
sheet.showColumns(13);
sheet.showColumns(14);
}
}