Android (Java/Kotlin) Google Sheets API: Find/Get Number of Rows

Append Rows

If you just need to append new rows, you don't need to get the number of rows.

Solution 1: Retrieve all cells of a column

val service = ...val spreadsheetId = ...val sheetName = ...val result = service.spreadsheets().values().get(spreadsheetId, "'$sheetName'!A:A").execute()Timber.d("rows=${result.getValues().size}")

NOTE: result.getValues() and result.values return different things.

NOTE: service is Sheets. Refer to Get Google Sheets service instance.

NOTE: Refer to Get Sheet Name.

Doesn't Work: gridProperties.rowCount

gridProperties.rowCount return all rows including blank rows.

val spreadsheet = service.spreadsheets().get(spreadsheetId).execute()for (sheet in spreadsheet.sheets) {    Timber.d("sheetId=${sheet.properties.sheetId}, title=${sheet.properties.title}, rows=${sheet.properties.gridProperties.rowCount}")}

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.