Estoy tratando de crear una secuencia de comandos en las secuencias de comandos de la aplicación de Google que me permita copiar una plantilla en una hoja nueva, agregar una fecha en el archivo, así como el título y ocultar automáticamente las hojas con más de un mes. Aquí está mi código hasta ahora y todo funciona excepto la ocultación automática de hojas (con la excepción de la hoja principal activa). Además, no soy un codificador profesional, la forma en que estoy comparando con un mes anterior probablemente no sea el mejor código, ¡si tiene algún consejo, lo agradecería!
Si es más fácil, también estaría de acuerdo si simplemente ocultara automáticamente todas las demás hojas, excepto la hoja principal cuando se ejecuta el script.
function createNewStandupSheet() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var activeSheet = ss.getActiveSheet() //Sets date var options = { day: '2-digit', month: 'short', year: 'numeric' }; var todaysDate = new Date().toLocaleDateString("en-GB", options); var data = Utilities.formatDate(new Date(), "GMT", "'Week'w"); //set month variable var today = new Date(); var m = today.getMonth(); //copy template as a new sheet var newSheet = ss.getSheetByName('DAILY STANDUP TEMPLATE').copyTo(ss); //change the new sheet's name SpreadsheetApp.flush(); newSheet.setName(data + "-" + todaysDate); var sheetname = newSheet.getName(); //Set line one value to date var cell = newSheet.getRange("C1:G1"); cell.setValue(todaysDate); //check if month is the same as current month, if its less, hide the other sheets. Then change the value to the current month after checking. var monthcell = newSheet.getRange("A50:B50"); if (monthcell < m){ hideAllSheetsExcept(sheetname) } monthcell.setValue(m) function hideAllSheetsExcept(sheetName) { var sheets=SpreadsheetApp.getActiveSpreadsheet().getSheets(); for(var i =0;i<sheets.length;i++){ Logger.log(i); if(sheets[i].getName()!=sheetName){ sheets[i].hideSheet(); } } } function createNewStandupSheet() { const mA = [...Array.from(new Array(12).keys(), x => Utilities.formatDate(new Date(new Date().getFullYear(), x, 15), Session.getScriptTimeZone(), "MMM"))];//generates an array of ["Jan","Feb"... const ss = SpreadsheetApp.getActive(); const todaysDate = new Date().toLocaleDateString("en-GB", { day: '2-digit', month: 'short', year: 'numeric' }); const data = Utilities.formatDate(new Date(), "GMT", "'Week'w"); const hdtv = new Date(new Date().getFullYear(),new Date().getMonth(),1).valueOf(); const sheetname = data + "-" + todaysDate; const nsh = ss.insertSheet(sheetname, 0, { template: ss.getSheetByName('DAILY STANDUP TEMPLATE') }); nsh.getRange("C1").setValue(todaysDate); ss.getSheets().filter(sh => sh.getName() != sheetname).forEach(sh => { if (sh.getName().match(/^Week\d{1,2}-\d{2} [a-zA-Z]{3} \d{4}/)) { let t = sh.getName().split('-')[1].toString().split(' '); let dtv = new Date(t[2],mA.indexOf(t[1]),parseInt(t[0])).valueOf(); if (dtv < hdtv) { sh.hideSheet(); } } }); } >This line matches sheet names to make sure I'm dealing with the correct sheets: if (sh.getName().match(/^Week\d{1,2}-\d{2} [a-zA-Z]{3} \d{4}/)) { >and these two lines calculate the date value of the current sheet let t = sh.getName().split('-')[1].toString().split(' '); let dtv = new Date(t[2],mA.indexOf(t[1]),parseInt(t[0])).valueOf();Apariencia de un título de hoja: