0
votes

Using C# .Net Google Sheets API.

I am new to the API, so I may have missed it in the docs - but how do you find out the maximum row and column that contain a value without reading all the data in the sheet?

For example, if a sheet contains multiple values and the "last" cell in the sheet with a value is at C139 (no cells in the rows following have a value and no cells in any column after C have a value), then the maximum row would be 139 and the maximum column would be 2 (zero based) or 3 (one based).

I tried sheet.Properties.GridProperties.RowCount -- but that gives the TOTAL number of rows in the sheet (whether the cells have values or not).

Same goes for sheet.Properties.GridProperties.ColumnCount -- gives the TOTAL number of columns in the sheet (whether the cells have values or not).

Any links or ideas are welcome.

1

1 Answers

0
votes

I understand that you want to know the last row of data in your Sheet. In that case, you can use a simple GET with a full range. For example let's assume that your Sheet only has two columns, in that case you can set up the range like A1:B. That range will include the full two columns, but the get will only get as far as the data goes. At this step you already have an array filled with your data range, so you only have to count the array index of the last element in order to know the last row value. If you don't know how many columns your Sheet have, you only have to modify the range in a similar way as before (i.e. A1:Z). Please ask me any doubts about this approach.