📎 Para ordenar todas las columnas por columna de la hoja activa en dos clics mediante un Google Apps Script. El cual crea un menú denominado «🛠️ Tools» y tres submenús. La primera vez solicitara permisos. Después ordena cada columna.
En caso de querer deshacer el ordenamiento. 🖰 Ir a barra de iconos » ⮌ Deshacer ( 🖮 Ctrl + Z )
Submenú «⬇️ A to Z All columns sort ascending» en orden ascendente. Excepto las filas y columnas que estén inmovilizadas.
Submenú «⬆️ Z to A All columns sort descending» en orden descendente. Excepto las filas y columnas que estén inmovilizadas.
Submenú «🔐 Invalidate authorization» Invalida permisos otorgados por los Standalone Scripts. Similar a Google Account: Security Review: Remove access.
💭 Recuerda:
Para ordenar todas las columnas puedes utilizar la opción «Ordenar intervalo por columna»
🖰 » Seleccionar columna » Ir a Menú » ᛨ☰ Ordenar intervalo » Ordenar intervalo por columna.
💡 Propuesta:
/**
* The event handler triggered when opening the spreadsheet.
* Function show menu.
* @param {Event} e The onOpen event.
*/
function onOpen(e){
/* Create a menu and two submenu. */
SpreadsheetApp.getUi()
.createMenu('🛠️ Tools')
.addItem('⬇️ A to Z All columns sort ascending', 'sortColumnAllAscending')
.addItem('⬆️ Z to A All columns sort descending', 'sortColumnAllDescending')
.addItem('🔐 Invalidate authorization','invalidateAuthorization')
.addToUi();
} /* End function onOPen */
/**
* Calling the sortColumnAllByColumn function.
* Sorts all columns by column in ascending order.
*/
function sortColumnAllAscending(){
sortColumnAllByColumn(true)
} /* End sortColumnAllAscending()*/
/**
* Calling the sortColumnAllByColumn function.
* Sorts all columns by column in descending order.
*/
function sortColumnAllDescending(){
sortColumnAllByColumn(false)
} /* End sortColumnAllDescending */
/**
* Function sort all columns independent.
* Not sort rows and columns frozen.
* Sheet active asc.
* @param {Boolean} blnAsc sort ascending true or descendente false.
* Predetermined true.
*/
function sortColumnAllByColumn(blnAsc = true) {
/** Get the class of the active spreadsheet */
const classSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();
/**Get the class of the active sheet. */
const classSheet = classSpreadsheet.getActiveSheet();
/** Get active range active. */
const getActiveRange = classSheet.getActiveRange();
/** Get a number of frozen rows. */
const intFrozenRows = classSheet.getFrozenRows();
/** Get a number of frozen columns. */
const intFrozenColumns = classSheet.getFrozenColumns();
/** Get max columns sheet active. */
const intMaxColumns = classSheet.getMaxColumns();
/** Get max rows sheet active. */
const intMaxRows = classSheet.getMaxRows();
/** Get the column number to sort from. Excluding frozen columns. */
let intSortRowFrom = intFrozenRows + 1;
/** Get the row number to sort from. Excluding frozen rows. */
let intSortColumnFrom = intFrozenColumns + 1;
/* Loop index intSortColumnFrom to intMaxColumns. */
for (intSortColumnFrom ; intSortColumnFrom <= intMaxColumns; intSortColumnFrom++) {
/** Get the active range class.**/
let getActivateColumn = classSheet.getRange(intSortRowFrom , intSortColumnFrom, intMaxRows - intFrozenRows , 1).activate();
/* Sort column activate. */
getActivateColumn.sort({column: intSortColumnFrom, ascending: blnAsc});};/* End for */
/* Activate range previous. */
classSheet.setActiveRange(getActiveRange);
/* Message in emergent window. Bottom right sample. */
classSpreadsheet.toast('All columns by column.','Sort')
}/* End function sortColumnIndependent */
/**
* Invalidates the authorization.
* @see Method invalidateAuth():
* https://developers.google.com/apps-script/reference/script/script-app#invalidateauth
*/
function invalidateAuthorization(){
/* Invalidate authorization */
ScriptApp.invalidateAuth();
} /* End invalidateAuthorizatio() */
📝 Propuesta detalle:
Copiar ( 🖮 Ctrl + V ) código.gs » 🖰 Ir a Menú » Extensiones » Apps Script » Pegar ( 🖮 Ctrl + C ) código.gs » 🖫 Guardar » ⭮ Actualizar hoja de cálculo de Google.
La función «onOpen(e)» es un Simple Triggers se activa al abrir Google Spreadsheet y crea un menú con submenús mediante Class Ui: Method createMenu().
La función «sortColumnAllAscending()» se activa a través del submenú. A su vez esta hace llamada la función genérica «sortColumnAllByColumn()» incluyendo el parámetro «true»
La función «sortColumnAllDescending()» se activa a través del submenú. A su vez esta hace llamada la función genérica «sortColumnAllByColumn()» incluyendo el parámetro «false»
La función «sortColumnAllByColumn(blnAsc)» contiene la Class Range: Method sort() ordena cada columna de la hoja activa Class SpreadsheetApp: Method getActiveSheet() utilizando la variable «booAsc» para ejecutar el orden. pero antes activa la columna. Similar a seleccionar el rango de la columna con Class Range: Method active() de la hoja activa. Excluye las primeras filas por Class Sheet: Method getFrozenRows() y columnas por Class Sheet: Method getFrozenColumns() inmovilizas. Class Sheet: Method setActiveRange() nos posiciona en el rango que anteriormente estábamos con Class Spreadsheet: Method getActiveRange() el cual la hemos almacenado en una variable. Al terminar la ejecución muestra un mensaje temporizado. Parte inferior derecha mediante Class Spreadsheet: Method toast().
La función «invalidateAuthorization» se activa al hacer clic en el submenú «🔐 Invalidate authorization» y retira los permisos ejecutando Class ScriptApp: Method invalidateAuth().
📷 Resultados:
📺 Demo:
📚 Referencias:
📎 Para ordenar todas las incluso las ocultas, en dos clics. Mediante un Google Apps Script. El cual crea un menú denominado «🛠️ Tools» y tres submenús. La primera vez solicitara permisos. Después ordena cada columna.
En caso de querer deshacer el ordenamiento. 🖰 Ir a barra de iconos » ⮌ Deshacer ( 🖮 Ctrl + Z )
Submenú «➡️Sheets Sort A to Z» en orden ascendente. Incluso hojas ocultas.
Submenú «⬅️Sheets Sort Z to A» en orden descendente. Incluso hojas ocultas.
Submenú «🔐InvalidateAuthorization» Invalida permisos otorgados por los Standalone Scripts. Similar a Google Account: Security Review: Remove access.
💭 Recuerda:
Para ordenar todas las hojas puedes mover cada pestaña con el cursor.
🖰🠝 » Ir a Menú » 🖿 Hojas ocultas » Mostrar » por cada hoja oculta.
🖰🠝 » Presionar pestaña con el cursor de cada pestaña » ✣ Mover pestaña » Deja de presionar cursor.
💡 Propuesta:
/**
* The event handler triggered when opening the spreadsheet.
* Create menu and submenus.
* @param {event} e The onOpen event.
* @see Trigger onOPen(e):
* https://developers.google.com/apps-script/guides/triggers#onopene
*/
function onOpen(e) {
/* Create menu and submenús. */
SpreadsheetApp.getUi().createMenu('⚒️Tools')
.addItem('➡️Sheets Sort A to Z', 'sortSheetsAscending')
.addItem('⬅️Sheets Sort Z to A', 'sortSheetsDescending')
.addItem('🔐InvalidateAuthorization', 'invalidateAuthorization')
.addToUi();
} /* End onOPen(e) */
/**
* Calling the sortSheets() function.
* Sorts all sheets ascending order.
*/
function sortSheetsAscending() {
sortSheets(true)
} /* End sortSheetsAscending() */
/**
* Calling the sortSheets() function.
* Sorts all sheets descending order.
*/
function sortSheetsDescending() {
sortSheets(false)
} /* End sortSheetsDescending() */
/**
* Function sort all sheets.
* Yes sort sheets hiddens.
* @param {boolean} blnAsc sort ascending true or descendente false.
* Predetermined true.
*/
function sortSheets(blnAsc = true) {
/** Get Class Spreadsheet */
const classSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();
/** Get active Class Sheet active */
const getSheetActive = classSpreadsheet.getActiveSheet();
/** Get active range active. */
const getActiveRange = classSpreadsheet.getActiveRange();
/** Get Array class Sheets */
const classSheets = classSpreadsheet.getSheets();
/** Create array all sheet.
* [.][0] sheet name.
* [.][1] statu Hidden.
* [.][2] class sheet.
*/
const sheetNames = classSheets.map(function (classSheet) {
/** text statu hidden */
let statuHidden = classSheet.isSheetHidden();
/* if hidden the show. */
if (statuHidden) { classSheet.showSheet(); }
/* set value array. */
return [classSheet.getSheetName(), statuHidden, classSheet];
});
/* Modify array ascending */
sheetNames.sort();
/* Modify array descending if false parameter. */
if (!blnAsc) { sheetNames.reverse(); }
/* Modify position sheets all ascending or descending. */
sheetNames.forEach(function (sheetName, index) {
/** Get new position sheet. */
let intNewPositionSheet = parseInt(index + 1);
/** if different previous position then move sheet. */
if (sheetName[2].getIndex() !== intNewPositionSheet) {
/* sheet activate. */
sheetName[2].activate();
/* Move sheet orden. */
classSpreadsheet.moveActiveSheet(intNewPositionSheet);
/* Apply all changes. */
SpreadsheetApp.flush();
} /* End if classSheetname.getIndex() !== intNewPositionSheet) */
}); /* End sheetNames.forEach */
/* hidden sheets store */
sheetNames.forEach(function (classSheet) {
/** text statu hidden */
if (classSheet[1]) { classSheet[2].hideSheet(); }
}); /* End sheetNames forEach */
/* Apply all changes */
SpreadsheetApp.flush();
/* Activate sheet previous*/
classSpreadsheet.setActiveSheet(getSheetActive);
/* Activate range previous. */
classSpreadsheet.setActiveRange(getActiveRange);
/* Message in emergent window. Bottom right sample. */
classSpreadsheet.toast('All sheets and sheet hidden', 'Sort')
}/* End sortSheets() */
/**
* Invalidates o valid the authorization.
* @see Method invalidateAuth():
* https://developers.google.com/apps-script/reference/script/script-app#invalidateauth
*/
function invalidateAuthorization() {
ScriptApp.invalidateAuth();
} /* End invalidateAuthorizatio() */
📝 Propuesta detalle:
Copiar ( 🖮 Ctrl + V ) código.gs » 🖰 Ir a Menú » Extensiones » Apps Script » Pegar ( 🖮 Ctrl + C ) código.gs » 🖫 Guardar » ⭮ Actualizar hoja de cálculo de Google.
La función «onOpen(e)» es un Simple Triggers se activa al abrir Google Spreadsheet y crea un menú y submenús mediante Class Ui: Method createMenu().
La función «sortSheetsAscending()» se activa a través del primer submenú. A su vez esta hace una llamada la función genérica «sortSheets()» incluyendo el parámetro «true»
La función «sortSheetsDescending()» se activa a través del segundo submenú. A su vez esta hace una llamada la función genérica «sortSheets()» incluyendo el parámetro «false»
La función «sortSheets(blnAsc)» obtenemos todas las hojas mediante Class Spreadsheet: Method getSheets(). Creamos una matriz que contiene el nombre de cada hoja Class Sheet: Method getSetName(), el valor booleano si la hoja está oculta Class Sheet: Method isSheetHidden(), además si es verdadero la muestra con Class Sheet: Method showSheet() y por finalmente almacenamos la clase de cada hoja Class Sheet: Method getSheets()[]. Después ordena la matriz ascendentemente y si el parámetro «blnAsc» es falso invierte dicha matriz. Ahora si el orden no es el correcto de cada hoja. Activamos la hoja Class Sheet: Method activate() y la desplazamos a su nueva posición con Class Spreadsheet: Method moveActiveSheet(). Recorremos todas las hojas otra vez para ocultar en caso de que en un principio estaban ocultas Class Sheet: Method hiddenSheet(). Recuperamos la hoja activa y rango activo previo Class Spreadsheet: Method setActiveSheet() y Class Spreadsheet: Method setActiveRange(). Al terminar la ejecución muestra un mensaje temporizado. Parte inferior derecha mediante Class Spreadsheet: Method toast().
La función «invalidateAuthorization» se activa al hacer clic en el tercer submenú y retira los permisos. Ejecutando Class ScriptApp: Method invalidateAuth().
📷 Resultado(s):
📺 Demo:
📎 Para mostrar o ocultar las hojas a la vez, en dos clics. Mediante un Google Apps Script. El cual crea un menú denominado «🛠️ Tools» y tres submenús. La primera vez solicitara permisos. Después muestra o oculta las hojas.
En caso de querer deshacer. 🖰 Ir a barra de iconos » ⮌ Deshacer ( 🖮 Ctrl + Z )
Submenú «🗀 Show sheet(s)» muestra las hojas ocultas y almacena los nombres de las hojas.
Submenú «🖿 Hidden sheet(s)» oculta las hojas. Que se han almacenado previamente cuando se activa el submenú mostrar hojas.
Submenú «🔐InvalidateAuthorization» Invalida permisos otorgados por los Standalone Scripts. Similar a Google Account: Security Review: Remove access.
💭 Recuerda:
Para mostrar las hojas ocultas.
🖰 » Ir a Menú » 🖿 Hojas ocultas » Mostrar » por cada hoja oculta.
Para ocultar las hojas.
🖰 » Ir a pestaña » Icono desplegable ⏷ » Ocultar hoja » por cada hoja.
💡 Propuesta:
/*
[Google Spreadsheet Apps Script] 🗀 Mostrar || 🖿 Ocultar. Hojas ocultas a la vez.
https://sites.google.com/view/auba/hoja-calculo-google/apps-script#h.voaxo8za8t7v
*/
/**
* The event handler triggered when opening the spreadsheet.
* Create menu and submenus.
* @param {event} e The onOpen event.
* @link
* https://developers.google.com/apps-script/guides/triggers#onopene
*/
function onOpen(e) {
/** Get Class Ui.
* @link
* https://developers.google.com/apps-script/reference/base/ui
*/
let classUi = SpreadsheetApp.getUi();
/** Get Class Menu.
* @link
* https://developers.google.com/apps-script/reference/base/menu
*/
let classMenu = classUi.createMenu('⚒️Tools');
/* Methods create submenus. */
classMenu.addItem('🗀 Show sheet(s)', 'showSheets');
classMenu.addItem('🖿 Hidden sheet(s)', 'hiddenSheets');
classMenu.addItem('🔐 Invalidate Authorization', 'invalidateAuthorization');
classMenu.addToUi();
} /* End onOPen(e) */
/**
* Calling the sheetsShowHidden() function.
* Show hide sheets.
*/
function showSheets() {
sheetsShowHidden('show')
} /* End showSheets() */
/**
* Calling the sheetsShowHidden() function.
* Hidden sheets shown.
*/
function hiddenSheets() {
sheetsShowHidden('hidden')
} /* End hiddenSheets() */
/**
* Function show or hidden sheets.
* @param {String} [strState='show'] 'show' or 'hidden' the sheets.
* Predetermined 'show.
*/
function sheetsShowHidden(strState = 'show') {
/** Get Class Spreadsheet.
* @link
* https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet
*/
const classSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();
/**
* Get Array class Sheets.
* @link
* https://developers.google.com/apps-script/reference/spreadsheet/sheet
*/
const classSheets = classSpreadsheet.getSheets();
/**
* Class Properties.
* @link
* https://developers.google.com/apps-script/reference/properties/properties-service
*/
const classDocumentProperties = PropertiesService.getDocumentProperties();
/** Get name key property. */
const nameKey = 'hiddenSheetStored';
/**
* Reserved variable sheets name.
* @return string or string[]
*/
var getSheetNames;
/*---- Block show ----*/
if (strState === 'show') {
/*
Create array sheets name hide.
return string[].
*/
getSheetNames = classSheets.map(function (classSheet) {
/** Reserved variable sheet name */
let srtSheetName;
/* if hiddenig set the sheet name else void. */
if (classSheet.isSheetHidden()) {
/* set sheet name, yes hide */
srtSheetName = classSheet.getSheetName();
} else {
/* set void, not hide. */
srtSheetName = '';
} /* End if */
return srtSheetName;
}); /* End classSheets.forEach() */
/* Modify array, not value void. */
getSheetNames = getSheetNames.filter(String);
/* exist hidden sheet. Show and store */
if (getSheetNames.length !== 0) {
/* Explore array show sheets. */
classSheets.forEach(function (classSheet) { classSheet.showSheet(); });
/* Transform array to string. */
getSheetNames = getSheetNames.toString();
/* Save store hide sheets name . */
classDocumentProperties.setProperty(nameKey, getSheetNames);
} /* end if getSheetNames.length !== 0 */
} /* End if (strState === 'show') */
/*---- Block hidden ----*/
if (strState === 'hidden') {
/* Get store hide sheets name previous or void. */
getSheetNames = classDocumentProperties.getProperty(nameKey) || '';
/* there are sheets name? */
if (getSheetNames === '') {
/* Transform string to array void. */
getSheetNames = [];
} else {
/* Transform string to array. */
getSheetNames = getSheetNames.split(',');
/* Explore array sheets name. */
getSheetNames.forEach(function (sheetName) {
/** Get class sheet by name.
* @link
* https://developers.google.com/apps-script/reference/spreadsheet/sheet
*/
let classSheetName = classSpreadsheet.getSheetByName(sheetName);
/* if name sheet exist then hidden. */
if (classSheetName) { classSheetName.hideSheet(); }
}); /* End forEach() */
/* Delete store hide sheets name . */
classDocumentProperties.setProperty(nameKey, '');
}
} /* End strState === 'hidden' */
/* Message in emergent window. Bottom right sample. */
classSpreadsheet.toast(getSheetNames.length === 0 ? 'There is not' : getSheetNames, `Sheet(s) ${strState}`)
}/* End sheetsShowHidden() */
/**
* Invalidates the authorization.
* @link
* https://developers.google.com/apps-script/reference/script/script-app#invalidateauth
*/
function invalidateAuthorization() {
ScriptApp.invalidateAuth();
} /* End invalidateAuthorizatio() */
📝 Propuesta detalle:
Copiar ( 🖮 Ctrl + V ) código.gs » 🖰 Ir a Menú » Extensiones » Apps Script » Pegar ( 🖮 Ctrl + C ) código.gs » 🖫 Guardar » ⭮ Actualizar hoja de cálculo de Google.
La función «onOpen(e)» es un Simple Triggers se activa al abrir Google Spreadsheet y crea un menú y tres submenús mediante Class Ui: Method createMenu().
La función «showSheets()» se activa a través del primer submenú. A su vez esta hace una llamada la función genérica «sheetsShowHidden()» incluyendo el parámetro «'show'»
La función «hiddenSheets()» se activa a través del segundo submenú. A su vez esta hace una llamada la función genérica «sheetsShowHidden()» incluyendo el parámetro «'hidden'»
La función «sheetsShowHidden(strState)» obtenemos todas las hojas mediante Class Spreadsheet: Method getSheets(). Obtenemos las propiedades de almacén Class Properties: Method getDocumentProperties(). Si el parámetro «strState» es igual a «'show'» entonces guardamos en un variable matriz «getSheetNames» memorizamos los nombres de las hojas ocultas. Después mostramos las hojas con Class Sheet: Method showSheet(). la variable matriz la convertimos en cadena y la almacenamos con un nombre clave en Class Properties: Method setProperty(). Si el parámetro «strState» es igual a «hidden'» recuperamos los nombres de las hojas almacenadas con el nombre clave mediante Class Properties: Method getProperties() en caso de no haber retorna cadena vacía. Está variable de cadena la convertimos en matriz. Adquirimos la clase de cada hoja por su nombre Class Spreadsheet: Method getSheetByName(). Si existe la hoja entonces la ocultamos Class Sheet: Method hiddenSheet(). Al terminar la ejecución muestra un mensaje temporizado. Parte inferior derecha mediante Class Spreadsheet: Method toast().
La función «invalidateAuthorization» se activa al hacer clic en el tercer submenú y retira los permisos. Ejecutando Class ScriptApp: Method invalidateAuth().
📷 Resultado(s):
📺 Demo: