class Scio::Excel::SimpleStyle
SimpleStyle
tries to simplify the styles for an individual cell.
Current options are:
-
text alignment (vertical, horizontal)
-
text wrapping
-
font style (bold, italics, color)
-
background color for the cell
-
borders
Example¶ ↑
# simple center-align st1 = Scio::Excel::SimpleStyle.new(:text => {:halign => "Center"}) # wrap text to the cell st2 = Scio::Excel::SimpleStyle.new(:text => {:wrap => true}) # set background color st2.bgcolor = "#666699" # set the borders st2.borders = Scio::Excel::BORDER_ALL # set only the left & right border st1.borders = Scio::Excel::BORDER_LEFT | Scio::Excel::BORDER_RIGHT # italics st1.font[:italic] = true
Attributes
bgcolor[RW]
borders[RW]
excel_id[RW]
font[RW]
numberformat[RW]
text[RW]
Public Class Methods
new(opts = {})
click to toggle source
# File lib/dm_core/scio_excel.rb, line 437 def initialize(opts = {}) @text = opts[:text] || {} @font = opts[:font] || {} @borders = opts[:borders].nil? ? 0 : opts[:borders] @bgcolor = opts[:bgcolor] @numberformat = opts[:numberformat] end
Public Instance Methods
create(workbook)
click to toggle source
Creates the xml for the style. You should not call this directly.
# File lib/dm_core/scio_excel.rb, line 446 def create(workbook) buffer = "" xml = Builder::XmlMarkup.new(:target => buffer, :indent => 2) @excel_id = workbook.next_style_id xml.Style 'ss:ID' => @excel_id do unless @text.empty? alignment_opts = {} alignment_opts["ss:Vertical"] = @text[:valign] if !@text[:valign].nil? alignment_opts["ss:Horizontal"] = @text[:halign] if !@text[:halign].nil? alignment_opts["ss:WrapText"] = "1" if @text[:wrap] xml.Alignment alignment_opts unless alignment_opts.empty? end unless @font.empty? font_opts = {} font_opts["ss:Bold"] = "1" if @font[:bold] font_opts["ss:Italic"] = "1" if @font[:italic] font_opts["ss:Color"] = @font[:color] unless @font[:color].nil? xml.Font font_opts unless font_opts.empty? end if @borders > 0 xml.Borders do xml.Border "ss:Position" => "Bottom", "ss:LineStyle" => "Continuous", "ss:Weight" => "1" if @borders & BORDER_BOTTOM > 0 xml.Border "ss:Position" => "Left", "ss:LineStyle" => "Continuous", "ss:Weight" => "1" if @borders & BORDER_LEFT > 0 xml.Border "ss:Position" => "Right", "ss:LineStyle" => "Continuous", "ss:Weight" => "1" if @borders & BORDER_RIGHT > 0 xml.Border "ss:Position" => "Top", "ss:LineStyle" => "Continuous", "ss:Weight" => "1" if @borders & BORDER_TOP > 0 end end xml.Interior "ss:Color" => @bgcolor, "ss:Pattern" => "Solid" unless @bgcolor.nil? xml.NumberFormat "ss:Format" => @numberformat unless @numberformat.nil? end xml.target! end