axlsx icon indicating copy to clipboard operation
axlsx copied to clipboard

Where to keep shared styles

Open kashifnaseer opened this issue 8 years ago • 1 comments

I've different views to export data into Excel. most of them are using same styles. Currently I'm copying all styles in all views.

My question is what is a best way to declare styles at some shared place and then re-use same styles in all views.

kashifnaseer avatar Sep 18 '17 12:09 kashifnaseer

In my app, not RoR, I just made an ExcelReport class that has a styles attribute that is a hash of styles.

        @styles = {}.tap do |style_hash|
            STYLES.each do |id, opts|
              if style_hash.include? id
                puts("Excel workbook style '#{id}' already exists, ignoring...")
                next
              end
              style_hash[id] = wb.styles.add_style opts
            end
          end

I just include a styles.rb file where team members can add styles as they please.

module ClarkKent
  module Reports
    module Excel
      STYLES = {
        default:                  { border: Axlsx::STYLE_THIN_BORDER, alignment: { horizontal: :center, vertical: :center, wrap_text: true } },
        default_unlocked:         { border: Axlsx::STYLE_THIN_BORDER, alignment: { horizontal: :center, vertical: :center, wrap_text: true }, locked: false },
        default_8:                { border: Axlsx::STYLE_THIN_BORDER, alignment: { horizontal: :center, vertical: :center, wrap_text: true }, sz: 8 },

info-rchitect avatar Nov 07 '17 12:11 info-rchitect