I want to read a sheet and i want to know it's dimensions (number of columns, number of rows).
What is the easiest way to obtain these? From
Get get = Sheets.getSheetsService().spreadsheets().values().get(spreadsheetId, sheetRange);
I want to know the number of columns, that contain data, I don't want the actual size of the sheet, since there might be lots of empty cells.
Is this possible in any way?
When you say you "don't want the actual size of the sheet, since there might be lots of empty cells." Not sure if you mean you just want the max data range,
last row
andlast col
with data? or just the count of rows and columns with dataIf last row/col data range, you can use spreadsheets.values.get() and find the
length
of the returned values for rows and then the largestarray.length
in the list for thelast column
with data. This works because returned values exclude extra empty rows and cols:Example using google apps script & javascript that can be tested in google apps script
[hoping you can get an idea of the process - haven't used Java in awhile and didnt want it to be a point of confusion]
edit: An easy way to get the columns would be to add
majorDimension
parameter inSheets.Spreadsheets.Values.get("ID","SN", {majorDimension: "COLUMNS"})
then thearr.length
returns the column lengthFrom there you could filter out the empty columns or rows that are between the ones which contain data - to get a count of only data rows/cols; as far as I am aware there is no way to get that count from the API itself.