[英]I want to hide Columns on each sheet according to a value in Cells in row 1
I get an error every time I try this here is what I am using. 每次尝试使用此功能时,都会收到错误消息。 I get this error:
我收到此错误:
TypeError: Cannot find function hideColumns in object Sheet,Sheet,Sheet,Sheet,Sheet."
I am not very familiar with scripts and cant seem to get this to work. 我对脚本不是很熟悉,并且似乎无法使它正常工作。
function Hide() {
// get active spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
// look at all sheets
var sheet = ss.getSheets();
// get data
var data = ss.getDataRange();
// get number of columns
var lastCol = data.getLastColumn()+1;
Logger.log(lastCol);
// itterate through columns
for(var i=1; i<lastCol; i++) {
if(data.getCell(1, i).getValue()[0] == '*') {
sheet.hideColumns(i);
}
}
}
Could some one help me? 有人可以帮我吗?
I am assuming, you are using this reference . 我假设您正在使用此参考 。 I guess, you want to do the following:
我想,您想执行以下操作:
*
then hide that column. *
则隐藏该列。 I am not familiar with Google Apps Services, but I think your code should look like this: 我对Google Apps Services不熟悉,但是我认为您的代码应如下所示:
function Hide() {
// get active spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
// look at all sheets
//var sheet = ss.getSheets();
// get data
var data = ss.getDataRange();
//get the sheet this range belongs to.
var sheet = data.getSheet();
// get number of columns
var lastCol = data.getLastColumn()+1;
Logger.log(lastCol);
// itterate through columns
for(var i=1; i<lastCol; i++) {
if(data.getCell(1, i).getValue()[0] == '*') {
sheet.hideColumns(i);
}
}
}
Since .getSheets
return an Array of Sheet
objects you can not call that function. 由于
.getSheets
返回一个Sheet
对象数组 ,因此您无法调用该函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.