ruby - How can I assign a new value to an attribute for my Spreadsheet::Format in Rails? -
i trying format spreadsheet way want using spreadsheet
gem in rails. however, can't seem modify existing format i've created. hoping point out i'm doing wrong, and/or point me in right direction. thanks!
# create 2 formats alternating rows primary_format = spreadsheet::format.new color: :black, weight: :normal, size: 10, pattern_fg_color: :xls_color_42, pattern: 1, bottom: :thin, left: :thin, top: :thin, right: :thin, border_color: :white alternate_format = spreadsheet::format.new color: :black, weight: :normal, size: 10, pattern_fg_color: :xls_color_43, pattern: 1, bottom: :thin, left: :thin, top: :thin, right: :thin, border_color: :white # write out document, , text align center columns (1 , 4,5) search_result_records.each_with_index |player, index| # add row format (0..5).each |i| if (index+1).even? if == 1 || >= 4 primary_format.horizontal_align = :center else primary_format.horizontal_align = :left end sheet_results.row(index+1).set_format(i, primary_format) else if == 1 || >= 4 alternate_format.horizontal_align = :center else alternate_format.horizontal_align = :left end sheet_results.row(index+1).set_format(i, alternate_format) end end sheet_results.row(index+1).push "#{player.last_name}, #{player.first_name}", "#{player.try(:position).try(:abbreviation)}", "#{player.try(:school).try(:short_name)}", "#{player.try(:club).try(:name)}", player.try(:draft_year), player.try(:age) end
now, i'm trying change horizontal_align
attribute on format alter between "left" , "center"- when necessary. ends happening becomes "center" aligned.
Comments
Post a Comment