tidyverse / googlesheets4

Google Spreadsheets R API (reboot of the googlesheets package)
https://googlesheets4.tidyverse.org
Other
360 stars 53 forks source link

Draft: Initial merged cells support in `get_cells()` #290

Open tzakharko opened 1 year ago

tzakharko commented 1 year ago

Initial implementation for #289

This adds new columns n_rows and n_cols to the result of get_cells()/range_read_cells(). API response with the merged cell ranges is parsed in get_merged_ranges() and then left-joined by starting location into the cell table.

No updates to documentation, tests, or range formatting yet. Could also use error handling when implementing the join.

jennybc commented 1 year ago

I assume you've got a test sheet or two lying around with some merged cells that you are developing against.... can you share with "anyone with a link"? And share the ID here? Then I could experience this for myself. I can't really work on this feature right now, so to advance things, I have to be able to make intelligent comments with a modest amount of time/psychic energy.

tzakharko commented 1 year ago

Absolutely! Here a simple example sheet

devtools::load_all()

range_read_cells(
  "https://docs.google.com/spreadsheets/d/1wDJKdfSyvi2CCr-ZBzWslo4HQLsGAaMwpalAiq6KHws",
  discard_empty = TRUE
) %>%
dplyr::mutate(cell = purrr::map_chr(cell, "formattedValue"))

And the output

row col n_rows n_cols loc cell
1 1 1 1 A1 A1
2 2 1 1 B2 B2
3 1 1 1 A3 B3
4 2 2 2 B4 merged B4:C5
6 3 1 1 C6 C6
7 1 1 3 A7 merged A7:C7
8 1 1 1 A8 A8
9 1 3 1 A9 merged A9:A11
9 2 1 1 B9 B9
11 2 1 1 B11 B11

If you can just have a quick look and tell me whether you are ok with the general direction, I'd be happy to also add tests, documentation, missing checks etc. I kept it minimal on purpose for now. Thanks for your time!