Can we hide column in sheet using google apps scri

2019-08-25 03:11发布

问题:

I want to share the sheet with others but i also want them to not able to see some columns. Is there any way out to solve this using google apps script or if any alternate option for the same. Thank you.

回答1:

You should take a look at the documentation, it will help you to find the function you're looking for. In this case, you need the Sheet.hideColumns(columnIndex) method

hideColumns(columnIndex)

Hides the column at the given index.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Hides the first column
sheet.hideColumns(1);


回答2:

Very simple function

function onOpen(){
ss = SpreadsheetApp.openById( 'sheetid' ),
sheet = ss.getSheetByName('sheet_name'),
ss.getActiveCell();
sheet.hideColumns(start_column_number, end_column_number);

}