Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @frozen_rows to easily check/modify #391

Open
janpeterka opened this issue Feb 8, 2021 · 0 comments
Open

Add @frozen_rows to easily check/modify #391

janpeterka opened this issue Feb 8, 2021 · 0 comments

Comments

@janpeterka
Copy link

Background:
I'm managing data in our company, and one of the use cases is exporting data to google sheet. Other persons are allowed to work with those spreadsheets, which sometimes leads to errors. I did run multiple times into
Google::Apis::ClientError: badRequest: Invalid requests[0].updateSheetProperties: Sorry, it is not possible to delete all non-frozen rows.
because someone froze the header row for filtering.
So, I would like to easily unfreeze rows before updating data.
That led me to add @frozen_rows to the Worksheet class working the same way as @max_col and @max_row, easily allowing me to check or change this property.

Suggestion
Add @frozen_rows to Worksheet class

  • add frozen_rows attr_reader and setter
    attr_reader :frozen_rows

    def frozen_rows=(rows)
      @frozen_rows = rows
      @meta_modified = true
    end
  • add to save->add_request->grid_properties
    # Saves your changes made by []=, etc. to the server.
    def save
      sent = false

      if @meta_modified
        add_request({
          update_sheet_properties: {
            properties: {
              sheet_id: sheet_id,
              title: title,
              index: index,
              grid_properties: {row_count: max_rows, column_count: max_cols, frozen_row_count: frozen_rows },
            },
            fields: '*',
          },
        })
      end
  ...
  • add to set_properties
def set_properties(properties)
      @properties = properties
      @title = @remote_title = properties.title
      @index = properties.index
      if properties.grid_properties.nil?
        @max_rows = @max_cols = 0
        @frozen_rows = 0
      else
        @max_rows = properties.grid_properties.row_count
        @max_cols = properties.grid_properties.column_count
        @frozen_rows = properties.grid_properties.frozen_row_count
      end
      @meta_modified = false
    end

Would like the insight from other devs on:

  • is there a simple way to do this in my code without changing gem?
    • I didn't find any, that's why I started changing gem code
  • is there a reason not to add this to gem?
    • I realize it adds code, but as ruby is about developer comfort, I find it a worthy tradeoff
    • I also realize that maybe it would make sense to do a more general solution for editing properties (I'm not adding frozen_cols as I don't need that now), but I'm quite new to ruby development and not feeling comfortable with finding abstractions for this.
  • is there a way to add this to code in a better way?
@janpeterka janpeterka changed the title Add frozen_rows to easily check/modify Add @frozen_rows to easily check/modify Feb 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant