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

136
Views
Tipo de script VLookup que elimina todos los datos en la columna (Appscript, Gsheet)

Buenas tardes,

Actualmente estoy desarrollando una base de datos en las hojas de Google que estoy tratando de llenar con datos de otro GSheet usando un script que actúa como un VLookup

Usé el script de este comentario: https://stackoverflow.com/a/60266697/19427703

El problema al que me enfrento es que cuando ejecuto mi script, se borran todos los datos (incluso cuando los datos no coinciden). Me gustaría que mi secuencia de comandos deje los datos en la celda cuando la ID no coincida.

Apreciaría cualquier ayuda,

Gracias de antemano, aquí está mi código:

 const ss = SpreadsheetApp.getActive(); /** * @param {GoogleAppsScript.Spreadsheet.Sheet} fromSht -Sheet to import from * @param {GoogleAppsScript.Spreadsheet.Sheet} toSht -Sheet to import to * @param {Number} fromCompCol -Column number of fromSht to compare * @param {Number} toCompCol -Column number of toSht to compare * @param {Number} fromCol -Column number of fromSht to get result * @param {Number} toCol -Column number of toSht to get result */ function Refresh( fromSht = ss.getSheetByName('Sheet1'), toSht = ss.getSheetByName('Sheet2'), fromCompCol = 1, toCompCol = 7, fromCol = 2, toCol = 2 ) { const toShtLr = toSht.getLastRow(); const toCompArr = toSht.getRange(2, toCompCol, toShtLr - 1, 1).getValues(); const fromArr = fromSht.getDataRange().getValues(); fromCompCol--; fromCol--; /*Create a hash object of fromSheet*/ const obj1 = fromArr.reduce((obj, row) => { let el = row[fromCompCol]; el in obj ? null : (obj[el] = row[fromCol]); return obj; }, {}); //Paste to column toSht .getRange(2, toCol, toShtLr - 1, 1) .setValues(toCompArr.map(row => (row[0] in obj1 ? [obj1[row[0]]] : [null]))); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

null se establece aquí, si la row[0] no está en el objeto hash:

setValues(toCompArr.map(row => (row[0] in obj1 ? [obj1[row[0]]] : [null]))); }

Probar

 setValues(toCompArr.map(row => (row[0] in obj1 ? [obj1[row[0]]] : row)));
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!