Skip to content

Instantly share code, notes, and snippets.

@zverok
Last active December 23, 2015 17:59
Show Gist options
  • Save zverok/6672636 to your computer and use it in GitHub Desktop.
Save zverok/6672636 to your computer and use it in GitHub Desktop.
# определяем основные стили
TABLE_BORDER_STYLE = {:style => :dotted, :color => '000000'}
TONALITY_STYLE = {:alignment => {:horizontal => :center, :vertical => :center}, :b => true, :sz => 18}
STYLES = {
:default => {:font_name => 'Calibri', :sz => 9},
:header => {:sz => 11},
:title => {:sz => 18, :alignment => {:horizontal => :center, :vertical => :center}},
:footer => {:sz => 11},
:separating_line => {:border => {:edges => [:bottom], :color => '000000', :style => :hair}},
:bold => {:b => true},
:hyperlink => {:i => true, :u => true},
:table_cell => {:alignment => {:wrap_text => true, :vertical => :top}},
:table_header => {:alignment => {:wrap_text => true, :horizontal => :center, :vertical => :center}, :b => true},
:border_inside => {:border => TABLE_BORDER_STYLE},
:border_at_top => {:border => TABLE_BORDER_STYLE.merge(:edges => [:bottom, :left, :right])},
:border_at_left => {:border => TABLE_BORDER_STYLE.merge(:edges => [:bottom, :top, :right])},
:border_at_top_left => {:border => TABLE_BORDER_STYLE.merge(:edges => [:bottom, :right])},
-1 => TONALITY_STYLE.merge(:fg_color => "FF5A5A"),
0 => TONALITY_STYLE.merge(:fg_color => "A4A4A4"),
+1 => TONALITY_STYLE.merge(:fg_color => "339966"),
}
# склеивалка нужного стиля
def make_style(*names)
@workbook_styles ||= {}
style = names.inject({}){|res, n|
s = STYLES[n] or raise(ArgumentError, "Неизвестное имя стиля: #{n.inspect}")
res.merge(s)
}
style_title = style.to_a.sort.map{|k,v| "#{k}:#{v}"}.join("/")
(@workbook_styles[style_title] ||= @workbook.styles.add_style(style))
end
# составляем нужный стиль для ячейки из нескольких:
make_style(:default, :header, :bold)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment