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

apply_styles method on sheet #9

Closed
westonganger opened this issue Jun 18, 2016 · 11 comments

Comments

Projects
None yet
2 participants
@westonganger
Copy link
Contributor

commented Jun 18, 2016

In my gem SpreadsheetArchitect I have the ability to create axlsx sheets individually. I was wondering if we can get the workbook.apply_styles to also be available as sheet.apply_styles so that I can apply the styling before returning the sheet.

@sakovias

This comment has been minimized.

Copy link
Collaborator

commented Jun 18, 2016

If you work with vanilla axlsx, you probably still need to call axlsx.serialize <my_workbook> when you're done with the whole workbook (all the worksheets included) to have it processed and saved as .xlsx file. If I understand it correctly, axlsx sets styles on the entire workbook, which is something I can't change.

As far as axlsx_styler goes, I think there's an opportunity to hide the call workbook.apply_styles from the end user. Would it solve your problem? Fell free to use examples to help me understand where your problem is.

@westonganger

This comment has been minimized.

Copy link
Contributor Author

commented Jun 18, 2016

I think hiding that might solve the issue. How would it work though?

@sakovias

This comment has been minimized.

Copy link
Collaborator

commented Jun 18, 2016

It's possible that we can patch axlsx.serialize from this gem's side, but I don't know for sure yet.

@westonganger

This comment has been minimized.

Copy link
Contributor Author

commented Jun 18, 2016

I like that idea. Make sure to also patch the to_stream method. I use this method instead of serialize so that I don't have to save to a file.

@westonganger

This comment has been minimized.

Copy link
Contributor Author

commented Jun 19, 2016

We could do it like this:

module AxlsxStyler
  module Axlsx
    module Package

      original_serialize = instance_method(:serialize)

      define_method :serialize do
        @workbook.apply_styles
        original_serialize.bind(self).()
      end

      original_to_stream = instance_method(:to_stream)

      define_method :to_stream do
        @workbook.apply_styles
        original_to_stream.bind(self).()
      end

    end
  end
end

I read this method of patching from this stackoverflow post http://stackoverflow.com/questions/4470108/when-monkey-patching-a-method-can-you-call-the-overridden-method-from-the-new-i

@sakovias

This comment has been minimized.

Copy link
Collaborator

commented Jun 19, 2016

Thanks for the example. I will look at it some time next week.

In the meantime it would be great to know what is the root cause of your problems. workbook.apply_styles should work, as all styles (even in the original axlsx) are defined on the workbook, not on its worksheets.

@westonganger

This comment has been minimized.

Copy link
Contributor Author

commented Jun 19, 2016

Sorry I should have mentioned that its not an issue. I was just wondering if that method could possibly done on the sheet level but you say that's not possible so that's okay with me.

@sakovias

This comment has been minimized.

Copy link
Collaborator

commented Jun 19, 2016

Ah, good. I'm just going to close this one then.

@sakovias sakovias closed this Jun 19, 2016

@westonganger

This comment has been minimized.

Copy link
Contributor Author

commented Jun 19, 2016

Are you still going to try and hide the call to apply_styles?

@sakovias

This comment has been minimized.

Copy link
Collaborator

commented Jun 19, 2016

I thought to slack away for a bit, but you're puting me on the spot 😄

Could you please review this change?

@sakovias

This comment has been minimized.

Copy link
Collaborator

commented Jun 19, 2016

Also, if you want to make your own PR, please feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.