A continuación les presento la Guía paso a paso que te ayudaran a ahorrar tiempo para poner en practica el código Google apps script de tus tutoriales de YouTube
Revisa el vídeo
síguenos en:
const hActiva = SpreadsheetApp.getActiveSheet();
const rangoHojaActiva = hActiva.getActiveRange()
const agenda = SpreadsheetApp.getActive().getSheetByName("Agenda");
const historico = SpreadsheetApp.getActive().getSheetByName("Historico");
const img = agenda.getImages()[0];
function onSelectionChange(e) {
let fila = e.range.getRow();Logger.log(fila);
let col = e.range.getColumn(); Logger.log(col);
let hoja = e.source.getActiveSheet().getName();Logger.log(hoja);
if(hoja === "Agenda"){
//inicia if anidado
if(fila === 4 && col >= 6 && col <= 12 || fila === 13 && col >= 6 && col <= 12 || fila === 22 && col >= 6 && col <= 12 || fila === 31 && col >= 6 && col <= 12 || fila === 40 && col >= 6 && col <= 12 || fila === 49 && col >= 6 && col <= 12){
desplazamientoLOGO();
}else{
fijarLOGO();
}
}
}
function desplazamientoLOGO(){
agenda.getImages()[0].setAnchorCell(agenda.getActiveCell())
.setAnchorCellXOffset(105)
.setAnchorCellYOffset(24);
}
function fijarLOGO(){
img.setAnchorCell(agenda.getRange("J1")).setAnchorCellXOffset(10).setAnchorCellYOffset(-8);
}
function envioHistorico(){
let activa = agenda.getActiveCell().getA1Notation();Logger.log(activa);
let fila = agenda.getActiveCell().getRow();
let col = agenda.getActiveCell().getColumn();
let datos = agenda.getRange(fila+1,col,8).getValues().map(d => d[0]);//nvoArreglo
let sinFalsos = datos.filter(Boolean);//filtra falsos
//Logger.log(sinFalsos);Logger.log(sinFalsos.toString());
//SpreadsheetApp.getUi().alert("Estos datos seran enviados al historico\n" + sinFalsos );
let mt = Utilities.formatDate(new Date(), "PST", "dd-MM-yyyy HH:mm:ss");
let fecha = agenda.getActiveCell().getDisplayValue()
historico.appendRow([mt, fecha, sinFalsos.toString()]);
SpreadsheetApp.getActiveSpreadsheet().toast('\n\nDatos enviados exitosamente 🏆', 'Estatus', 5);
}
function asignaScript(){
img.assignScript("envioHistorico");
}
function limpiarRangoActivo(){
let fila = agenda.getActiveRange().getRow();//Logger.log("fila ini:" +fila);
let ufila = agenda.getActiveRange().getLastRow();//Logger.log("Ult fila:" + ufila);
let col = agenda.getActiveRange().getColumn(); //Logger.log("Col ini" + col);
let uCol = agenda.getActiveRange().getLastColumn();//Logger.log("Ult col " + uCol);
let numcols = agenda.getActiveRange().getNumColumns();Logger.log(numcols);
if(col >= 3 && fila >=4 ){
if(fila >= 4 && uCol <=4 && numcols >1|| fila <= 53 && uCol <=4 && numcols >1){
SpreadsheetApp.getUi().alert("Rango dentro de los limites\nSe borraran los datos");
rangoHojaActiva.clearContent();
}else if (numcols === 1) {
SpreadsheetApp.getUi().alert("Debe seleccionar al menos 2 columnas y seleccionó " + numcols)
}else{
SpreadsheetApp.getUi().alert("el rango excede los limites")
}
}else{
SpreadsheetApp.getUi().alert("❌ Rango INCORRECTO:\n\nEl rango a borrar debe iniciar en la col 3 y fila 4 💥" +
"\npero usted la ha iniciado en la col " +col + " y fila " +fila)
}
}
function limpiarTODO(){
hActiva.getRange("C4:D53").clearContent();
}
function mostrarVentana(){
var html = HtmlService.createHtmlOutputFromFile('guiaActual')
.setWidth(2000)
.setHeight(1200);
SpreadsheetApp.getUi().showModalDialog(html, '🚀 Guia interactiva OE');
}