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

284
Views
Google App Scripts genéricos para importar otras filas de hojas de cálculo en función del valor de una columna (condición)

Estoy tratando de crear una plantilla genérica que importará datos de una hoja de cálculo maestra a una hoja de cálculo secundaria según una condición.

Ejemplo: elimine todas las filas de la hoja de cálculo secundaria y, a continuación, importe todas las filas de la hoja de cálculo maestra que contengan "Sí" en la hoja de cálculo secundaria vacía.

El problema con este código es que solo funciona dentro de la misma hoja de cálculo ya que usa copyTo . Para que GAS se comunique con otras hojas de cálculo, necesito eliminar copyTo y reemplazarlo con getValues y setValues . Parece que no puedo hacer que esto funcione todavía.

Aquí está el código actual que estoy usando. ¿Cómo puedo obtener este código (o un código similar) para lograr lo que busco lograr?

 function copyRows() { //Source Info. var sourceSpreadsheet = SpreadsheetApp.openById('15a9...'); var sourceSheet = sourceSpreadsheet.getSheetByName("Sheet1"); var sourceLastRow = sourceSheet.getLastRow(); //Destination Info. var destinationSpreadsheet = SpreadsheetApp.openById('1DtL...'); var destinationSheet = destinationSpreadsheet.getSheetByName("Sheet1"); var destinationLastRow = destinationSheet.getLastRow(); //Condition to search for. for (var i = 2; i <= sourceLastRow; i++) { var cell = sourceSheet.getRange("T" + i); var val = cell.getValue(); if (val == "Yes") { var srcRange = sourceSheet.getRange("A" + i + ":Z" + i); var destinationRow = destinationSheet.getLastRow(); var destinationRange = destinationSheet.getRange("A" + (destinationRow+1) + ":Z" + (destinationRow+1)); srcRange.copyTo(destinationRange); } } };

Todas las preguntas anteriores en Stackoverflow parecen ser solo para importar datos a una nueva pestaña dentro de la misma hoja de cálculo.

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

0

Prueba esto:

 function copyRows() { const sss = SpreadsheetApp.openById('ssid'); const ssh = sss.getSheetByName("Sheet0"); const svs = ssh.getRange(2, 1, ssh.getLastRow() - 1, ssh.getLastColumn()).getValues().filter(r => r[19] == 'Yes'); const dss = SpreadsheetApp.openById('ssid'); const dsh = dss.getSheetByName("Sheet1"); dsh.getRange(2,1,dsh.getLastRow()-1,dsh.getLastColumn()).clearContent(); dsh.getRange(1, 1, svs.length, svs[0].length).setValues(svs); }
  • Filtrar
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!