He intentado eliminar las hojas existentes cuyos nombres coinciden con un criterio, pero sigo encontrándome con el siguiente error y no puedo averiguar por qué.
El código que estoy ejecutando:
const SS = SpreadsheetApp.getActiveSpreadsheet(); const allSheets = SS.getSheets(); const category = 'Block-A'; const newSheetName = 'BOQ ' + category; for (let a = 0; a < allSheets.length; a++) { let existingSheetName = allSheets[a].getName(); if (existingSheetName == newSheetName) { SS.deleteSheet(allSheets[a]); } } El error: Sheet xxxxxxxxxx not found
Aprecio tu ayuda.
antonio
Después de leer los comentarios sobre la pregunta, esto es lo que funcionó para mí:
Primero, asegúrese de que los nombres de las hojas estén en la lista. En mi caso, obtuve una columna de categorías de clientCategories cuyo valor se convertiría en un nombre de hoja:
let sheetsToDel = []; for (let a = 0; a < clientCategories.length; a++) { sheetsToDel.push('BOQ ' + clientCategories[a]) }Luego, revisaría todas las hojas y las eliminaría:
for (let a = 0; a < allSheets.length; a++) { const sheetName = allSheets[a].getName() for (let r = 0; r < sheetsToDel.length; r++) { if (sheetName == sheetsToDel[r]) { SS.deleteSheet(allSheets[a]); } } }Puede haber muchas mejores maneras de hacerlo, pero esto es lo que obtuve.