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

190
Views
Compare varias cadenas en un condicional si en Hojas de cálculo de Google

Me gustaría hacer lo siguiente con Google Apps Script:

  1. Compare más de dos cadenas correspondientes a diferentes versiones del mismo modelo de automóvil
  2. Coincidir con el modelo correcto
  3. Use una plantilla de Google Doc con la información del modelo

Aquí puedes encontrar parte de mi código:

 const rows = sheet.getDataRange().getValues(); var googleDocTemplate = DriveApp.getFileById('doc ID') rows.forEach(function(row,index) { if (index === 0) return; if (row[0]) return; if (row[3]==='Toyota') return; if (row[3]==='Ford') return; if (row[3]==='Dodge') return; if (row[3]==='Changan') return; if (row[15]==='' && row[22]==='') return; //Grand i10 M/T GL, GLS or A/T GLS if ((row[4].equals('Grand i10 M/T GL') || row[4].equals('Grand i10 M/T GLS') || row[4].equals('Grand i10 A/T GLS')) && row[9]===0 && row[6]==='Electric Blue'){ googleDocTemplate = DriveApp.getFileById('doc ID'); } else if ((row[4].includes('Grand i10 M/T GL') || row[4].includes('Grand i10 M/T GLS') || row[4].includes('Grand i10 A/T GLS')) && row[9]===0 && row[6]==='Black'){ googleDocTemplate = DriveApp.getFileById('doc ID'); } else { SpreadsheetApp.getUi().alert("Hyundai model is wrong") return }

Básicamente, el código busca a través de filas en las Hojas de cálculo de Google como esta

y luego compara la cadena contenida en la celda con la cadena de referencia (p. ej., 'Grand i10 M/T GL'), pero en este caso particular, el condicional salta directamente al resto mostrando la alerta "El modelo de Hyundai es incorrecto".

Cualquier ayuda sería apreciada. ¡Gracias!

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

0

Prueba esto. No sabía cómo manejas Hyundai

 function test() { try { var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheetByName("Sheet4"); // substitute your sheet here var rows = sheet.getDataRange().getValues(); var i = 0; // i=1 skip first row? for( i=1; i<rows.length; i++ ) { // note index 3 is column D if( ( ( rows[i][3] === "Grand i10 M/T GL" ) || ( rows[i][3] === "Grand i10 M/T GLS" ) || ( rows[i][3] === "Grand i10 A/T GLS" ) ) && ( rows[i][8] === 0 ) && ( ( row[i][5] === "Electric Blue" ) || ( row[i][5] === "Black" ) ) ) { googleDocTemplate = DriveApp.getFileById('doc ID'); break; // asuming there is only one row with these attributes } else if( rows[i][2] === "Hyundai" ) { SpreadsheetApp.getUi().alert("Hyundai model is wrong"); return; } } Logger.log("row = "+(i+1)); } catch(err) { Logger.log(err); } }
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!