Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

230
Views
¿Cómo eliminar hojas según un criterio de nombre usando Google Apps Script?

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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!