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

122
Views
Google App Script: el número de filas en los datos no coincide con el número de filas en el rango

Estoy escribiendo un script de aplicación de Google y me he quedado atascado. Soy un principiante.

Tengo un .csv de nuestro sql sever con 943 filas que se carga en mi unidad de Google. Este script toma el contenido del .csv y lo mueve a una hoja de Google para usarlo en mi sitio web.

Funciona siempre que el número de filas en el csv no cambie. A medida que se agregan o eliminan elementos de nuestra tienda web, el script no funcionará y arrojará el error:

"Excepción: el número de filas en los datos no coincide con el número de filas en el rango. Los datos tienen 943 pero el rango tiene 944".

 function CSVCopyPaste(sourcelink,sourcerange,destilink,destisheet,destirange {
 
 //Source link
 var file = DriveApp.getFilesByName('CommercialAvailability.csv').next();
 var csvData = Utilities.parseCsv(file.getBlob().getDataAsString());

 // Destination
 var ss = SpreadsheetApp.openByUrl(destilink);
 var sheet = ss.getSheetByName(destisheet);

 // transfer to destination range
 sheet.getRange(destirange).clearContent();
 sheet.getRange(destirange).setValues(csvData);
}

La segunda función se llama CommercialAvailability y es la función que estoy ejecutando para lograr el resultado. Está:

 function CommercialAvailability() {
 SettlemyreCSVCopyPaste(
 "https://drive.google.com/file/d/1-V040x0t6SWT14xx6N22MlVFhHnj9XE4",
 "A3:C",
 "https://docs.google.com/spreadsheets/d/1s8kzVxmJ6v3akpoZ8N2VoGMZ90U2kozlSXdRHUU2BAg/edit#gid=0",
 "Commercial Availability",
 "B6:D945"
 )
}

¡Cualquier ayuda con esto sería muy apreciada!

Gracias,

Alex

almost 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Alex, el problema es que tu rango es fijo (B6:D945) pero el tamaño de los datos en el CSV es variable.

Probar:

 function CSVCopyPaste(sourcelink,sourcerange,destilink,destisheet,destirangestart) {
 
 //Source link
 var file = DriveApp.getFilesByName('CommercialAvailability.csv').next();
 var csvData = Utilities.parseCsv(file.getBlob().getDataAsString());

 //we need to check if the CSV is not empty
 if (csvData.length > 0){
 // Destination
 var ss = SpreadsheetApp.openByUrl(destilink);
 var sheet = ss.getSheetByName(destisheet);
 var rangestart = sheet.getRange(destirangestart);
 var writeRange = sheet.getRange(rangestart.getRow(),rangestart.getColumn(),csvData.length,csvData[0].length);
 var clearRange = sheet.getRange(rangestart.getRow(),rangestart.getColumn(),sheet.getMaxRows()-rangestart.getRow(),csvData[0].length);

 // transfer to destination range
 clearRange.clearContent();
 writeRange.setValues(csvData);
 }
}

function CommercialAvailability() {
 CSVCopyPaste(
 "https://drive.google.com/file/d/1-V040x0t6SWT14xx6N22MlVFhHnj9XE4",
 "A3:C",
 "https://docs.google.com/spreadsheets/d/1s8kzVxmJ6v3akpoZ8N2VoGMZ90U2kozlSXdRHUU2BAg/edit#gid=0",
 "Commercial Availability",
 "B6"
 )
}

Tenga en cuenta que no lo he probado. Además, tiene argumentos no utilizados en CSVCopyPaste de los que quizás desee deshacerse.

almost 4 years ago · Santiago Trujillo 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!