Show / Hide a spreadsheet row when clicked

0

I am working with a spreadsheet to have a more web style and I need to show details of some fields only when the user requires it. I can show a hidden row with sheet.showRows(3) but I can not hide it using:

var clic=0;
function mostrarDetalle(){
 var sheet = spreadSheet.getSheetByName("Hoja 1");
 if (clic==0){
  sheet.showRows(3); 
  clic = 1;
 }else{
  sheet.hideRows(3);
  clic = 0; 
 }
}

Only this works for me:

var sRows = sheet.showRows(3) || sheet.hideRows(3);

but it is hidden automatically and I need the user to control when it should be hidden, can you help me?

    
asked by Karen Lewis 27.08.2018 в 16:29
source

1 answer

1

About the code in question

Since global variables are "reinitialized" each time the script is executed, they are not appropriate as persistent storage between one execution and another.

Overview

As mentioned in the question, the methods to hide or show a row by its row number are

  • showRows (numfila)
  • hideRows (numfila)

Unfortunately neither the Spreadsheet service nor the Google Sheets API include methods to indicate whether the row is visible or hidden.

Provisional solutions

On the side of the spreadsheet

  • A column could be used to maintain a value indicating whether the row has been visible or hidden
  • You could use formulas such as =SUBTOTAL(102,A1) which will return 1 if A1 has a numeric value and is visible and 0 if it has a numerical value and is hidden.

On the Google Apps Script side

You could use document properties to save the status of the row

Unfortunately, the previous provisional solutions are not reliable because they depend on the user to use the spreadsheet in an appropriate way, as the case may be.

    
answered by 01.09.2018 в 22:07