简体   繁体   English

我想根据第一行的单元格中的值隐藏每个工作表上的列

[英]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: 我想,您想执行以下操作:

  1. Iterate all the columns in the data range. 迭代数据范围内的所有列。
  2. If the value of the first row of column equals * 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.

相关问题 我想隐藏特定单元格的表格行 - I want to hide table row of particular cells 我想根据每个过滤器过滤数据并将其复制到另一个工作表。 (谷歌应用程序脚本)? - I want to filter and copy data to another sheet according to each filter. (Google Apps Script)? 我想根据表格数据隐藏或显示按钮 - i want to hide or show button according to table data 如何根据行数隐藏整个表格 - how can i hide whole table according to row count 我想根据情况更改表格的行颜色 - I want to change row colors of a table according to the condition 如何使用谷歌脚本连接每行中的单元格? - How can I concatenate cells in each row with a google script? 我需要根据组合框值更改每个表单元格onclick - i need to change each table cell onclick according to the combobox value 我想在表格中插入一行,并用来自 HTML 个元素的信息填充新行的单元格 - I want to insert a row to a table and fill cells of the new row with information from HTML elements 根据表格的行数隐藏或显示按钮 - Hide or display a button according to row count of a table 我想根据给定的模式按每个单词的第二个字母对 arr 中的单词进行排序 - I want to sort my words from arr by 2nd letter of each word according to my given pattern
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM