Open Google Drive document and apply filters

Asked

Viewed 85 times

1

Hello,

I started using Google Drive to make it easier to share documents between different departments of the company but I don’t know how to create "Macros".

I wish I had a file MENU where the various departments are listed and through link open the same General file but with filters according to the department that opened it.

Example:
The Commercial Department opens the MENU and press the button Commercial and the General File is open. (So far I’ve been able to do and it works)

//Abrir Ficheiro
function AbrirComercial() {
var page =
 '<script>window.open("https://docs.google.com/spreadsheets/xxxxxxxxx"); google.script.host.close()</script>';

var interface = HtmlService
.createHtmlOutput(page)
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setWidth(1)
.setHeight(1);   
SpreadsheetApp.getUi().showModalDialog(interface, 'Abrindo... ');
}

What I’m not able to do is run the filters after opening the General File.

If you open the file and execute the function everything goes well but what I want is that after opening the General File the following filters are applied.

//Filtrar Comercial
{ var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('C4').activate();
var criteria = SpreadsheetApp.newFilterCriteria()
.setHiddenValues(['', 'Consumiveis', 'Direcção Financeira', 'Direcção Geral', 'Electricidade', 'Expansão', 'Financeiro', 'Limpeza', 'Manutenção', 'Manutenção Armazém', 'Manutenção Armazéns', 'Operações', 'Patrimonio', 'Procurement', 'Responsabilidade Técnica', 'RH', 'Segurança', 'Serviços Centrais'])
.build();
spreadsheet.getActiveSheet().getFilter().setColumnFilterCriteria(3, criteria);

 //Filtro Activos  
spreadsheet.getRange('J4').activate();
var criteria = SpreadsheetApp.newFilterCriteria()
.setHiddenValues(['#N/D', 'Desactivo'])
.build();
spreadsheet.getActiveSheet().getFilter().setColumnFilterCriteria(10, criteria);  
};

Is there any way to script while the page is loaded to only then run the filters?

Thank you.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.