elixir_google_spreadsheets
elixir_google_spreadsheets copied to clipboard
Let read one row with `read_rows`
Sometimes we compute ranges (for eg. see below, chunking to read a great number of rows), and one range ends up containing only one row. In this case it is handy not to have to conditionally use read_row
but just read this range of one row with read_rows
.
Example of chunking where we can end up we only a range of one row:
{:ok, rows_number} = GSS.Spreadsheet.rows(sheetPid)
1..rows_number
|> Enum.chunk_every(250)
|> Enum.reduce([], fn indexes_chunk, rows ->
start_range = List.first(indexes_chunk)
end_range = List.last(indexes_chunk)
Logger.info("Reading #{start_range}:#{end_range} rows from Sheet")
{:ok, chunk_rows} =
GSS.Spreadsheet.read_rows(
sheetPid,
start_range,
end_range,
timeout: 20000
)
rows ++ chunk_rows
end)
I've tested this PR in a project, seems to be working as intended.