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

319
Views
SpreadsheetApp.getLastRows() proporciona registros vacíos y no trunca a aquellos con datos

Soy nuevo en JS y en el uso de Google App Script, así que disculpe mi falta de conocimiento de JS.

Tengo un simple script .gs para trabajar. Convierte el contenido de una celda en un hipervínculo (por ejemplo, si el texto es "blah", sería "https://example.com/blah").

El script recupera el número de filas para operar. Para una hoja, esto lo hace correctamente y lo trunca hasta la última entrada (fila=31) aunque la hoja tenga 1000 filas. Sin embargo, para otra hoja, no lo hace y devuelve 999:

Aquí está la depuración para cuando no estaba bien:

 Apr 8, 2022, 11:20:53 AM Debug doiColumn: 10 numRows: 999

Aquí está otra hoja que funcionó según lo previsto:

 Apr 8, 2022, 9:44:47 AM Debug doiColumn: 5 numRows: 31

Los documentos dicen: "Devuelve la posición de la última fila que tiene contenido".

A modo de ilustración, aquí hay un fragmento del código:

 let spreadsheet = SpreadsheetApp.getActive(); let sheet = SpreadsheetApp.getActiveSheet(); const column = getColumn(sheet, column_name); let range = sheet.getRange(2, column, sheet.getLastRow() - 1, 1) console.log(range.getValues()); const numRows = range.getNumRows(); console.log(`column: ${column} numRows: ${numRows}`)

Me gustaría asegurarme de que .getLawRow() esté truncado. De lo contrario, este script se ejecuta más de lo que debería.

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

0

Lo siento, no pude incluirlo en un comentario.

Requiere col = número de columna, sh = hoja (no el nombre), ss = hoja de cálculo (no el nombre)

 function getColumnHeight(col, sh, ss) { var ss = ss || SpreadsheetApp.getActive(); var sh = sh || ss.getActiveSheet(); var col = col || sh.getActiveCell().getColumn(); var rcA = []; if (sh.getLastRow()){ rcA = sh.getRange(1, col, sh.getLastRow(), 1).getValues().flat().reverse(); } let s = 0; for (let i = 0; i < rcA.length; i++) { if (rcA[i].toString().length == 0) { s++; } else { break; } } return rcA.length - s; //const h = Utilities.formatString('col: %s len: %s', col, rcA.length - s); //Logger.log(h); //SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(h).setWidth(150).setHeight(100), 'Col Length') }

Hay otras formas de hacerlo pero yo prefiero esta. ha sido confiable para mi

El uso de rangos como este sheet.getRange("A1:Z") también le proporcionará un montón de nulos de getLastRow() a getMaxRows() que luego deben filtrarse, pero si tiene un nulo dentro de sus datos, entonces eso también se eliminará y ahora tiene datos falsos porque esa fila que se elimina ahora estropea el orden de las filas.

about 4 years ago · Juan Pablo Isaza Report

0

Intenta reemplazar .getLastRow() por

 .getLastDataRow(column)

y agregue esta función prototipo

 Object.prototype.getLastDataRow = function(col){ var lastRow = this.getLastRow(); if (col == null){col=1} var range = this.getRange(lastRow,col); if (range.getValue() !== "") { return lastRow; } else { return range.getNextDataCell(SpreadsheetApp.Direction.UP).getRow(); } };
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!