在正确启动某些代码时遇到一些麻烦。我正在制作一份预算表,其中有一份概述表,其中大部分其他表格中都提供了信息,但由于每个月都有单独的表格,还有一些表单,因此需要保持跟踪所有的床单。我开始手动隐藏/显示工作表以使事情变得更容易,但是一旦我能够在概述页面上自动隐藏/显示月份,我认为如果工作表也是自动化的,那将是最好的。这导致我得到了我现有的代码,如下所示:
function onEdit(e) {
var sheet = e.source.getActiveSheet();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var January = ss.getSheetByName("January");
var February = ss.getSheetByName("February");
var March = ss.getSheetByName("March");
var April = ss.getSheetByName("April");
var May = ss.getSheetByName("May");
var June = ss.getSheetByName("June");
var July = ss.getSheetByName("July");
var August = ss.getSheetByName("August");
var September = ss.getSheetByName("September");
var October = ss.getSheetByName("October");
var November = ss.getSheetByName("November");
var December = ss.getSheetByName("December");
if (e.range.getA1Notation() !== 'A29' || sheet.getName() !== 'Overview') return;
switch (e.value) {
case 'All':
sheet.showColumns(3, 24)
January.showsheet();
February.showsheet();
March.showsheet();
April.showsheet();
May.showsheet();
June.showsheet();
July.showsheet();
August.showsheet();
September.showsheet();
October.showsheet();
November.showsheet();
December.showsheet();
break;
case 'January':
sheet.hideColumns(3, 24);
sheet.showColumns(3, 2);
January.showsheet();
February.hidesheet();
March.hidesheet();
April.hidesheet();
May.hidesheet();
June.hidesheet();
July.hidesheet();
August.hidesheet();
September.hidesheet();
October.hidesheet();
November.hidesheet();
December.hidesheet();
break;
case 'February':
sheet.hideColumns(3, 24);
sheet.showColumns(3, 4);
January.hidesheet();
February.showsheet();
March.hidesheet();
April.hidesheet();
May.hidesheet();
June.hidesheet();
July.hidesheet();
August.hidesheet();
September.hidesheet();
October.hidesheet();
November.hidesheet();
December.hidesheet();
break;
case 'March':
sheet.hideColumns(3, 24);
sheet.showColumns(5, 4);
January.hidesheet();
February.hidesheet();
March.showsheet();
April.hidesheet();
May.hidesheet();
June.hidesheet();
July.hidesheet();
August.hidesheet();
September.hidesheet();
October.hidesheet();
November.hidesheet();
December.hidesheet();
break;
case 'April':
sheet.hideColumns(3, 24);
sheet.showColumns(7, 4);
January.hidesheet();
February.hidesheet();
March.hidesheet();
April.showsheet();
May.hidesheet();
June.hidesheet();
July.hidesheet();
August.hidesheet();
September.hidesheet();
October.hidesheet();
November.hidesheet();
December.hidesheet();
break;
case 'May':
sheet.hideColumns(3, 24);
sheet.showColumns(9, 4);
January.hidesheet();
February.hidesheet();
March.hidesheet();
April.hidesheet();
May.showsheet();
June.hidesheet();
July.hidesheet();
August.hidesheet();
September.hidesheet();
October.hidesheet();
November.hidesheet();
December.hidesheet();
break;
case 'June':
sheet.hideColumns(3, 24);
sheet.showColumns(11, 4);
January.hidesheet();
February.hidesheet();
March.hidesheet();
April.hidesheet();
May.hidesheet();
June.showsheet();
July.hidesheet();
August.hidesheet();
September.hidesheet();
October.hidesheet();
November.hidesheet();
December.hidesheet();
break;
case 'July':
sheet.hideColumns(3, 24);
sheet.showColumns(13, 4);
January.hidesheet();
February.hidesheet();
March.hidesheet();
April.hidesheet();
May.hidesheet();
June.hidesheet();
July.showsheet();
August.hidesheet();
September.hidesheet();
October.hidesheet();
November.hidesheet();
December.hidesheet();
break;
case 'August':
sheet.hideColumns(3, 24);
sheet.showColumns(15, 4);
January.hidesheet();
February.hidesheet();
March.hidesheet();
April.hidesheet();
May.hidesheet();
June.hidesheet();
July.hidesheet();
August.showsheet();
September.hidesheet();
October.hidesheet();
November.hidesheet();
December.hidesheet();
break;
case 'September':
sheet.hideColumns(3, 24);
sheet.showColumns(17, 4);
January.hidesheet();
February.hidesheet();
March.hidesheet();
April.hidesheet();
May.hidesheet();
June.hidesheet();
July.hidesheet();
August.hidesheet();
September.showsheet();
October.hidesheet();
November.hidesheet();
December.hidesheet();
break;
case 'October':
sheet.hideColumns(3, 24);
sheet.showColumns(19, 4);
January.hidesheet();
February.hidesheet();
March.hidesheet();
April.hidesheet();
May.hidesheet();
June.hidesheet();
July.hidesheet();
August.hidesheet();
September.hidesheet();
October.showsheet();
November.hidesheet();
December.hidesheet();
break;
case 'November':
sheet.hideColumns(3, 24);
sheet.showColumns(21, 4);
January.hidesheet();
February.hidesheet();
March.hidesheet();
April.hidesheet();
May.hidesheet();
June.hidesheet();
July.hidesheet();
August.hidesheet();
September.hidesheet();
October.hidesheet();
November.showsheet();
December.hidesheet();
break;
case 'December':
sheet.hideColumns(3, 24);
sheet.showColumns(23, 4);
January.hidesheet();
February.hidesheet();
March.hidesheet();
April.hidesheet();
May.hidesheet();
June.hidesheet();
July.hidesheet();
August.hidesheet();
September.hidesheet();
October.hidesheet();
November.hidesheet();
December.showsheet();
break;
}
}
由于某种原因,它不太合适。不知道我做错了什么。在编码方面我不是很有经验,所以我确信它可能是非常简单的东西。这是我用代码编写的文档的空白副本的链接。
我愿意接受建议,先谢谢。