diff options
| author | Randy Morgan <[email protected]> | 2012-03-14 23:06:38 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-03-14 23:06:38 +0900 |
| commit | fa847fbe3b0b4b6ef3bee9b770b891798d16275c (patch) | |
| tree | 91f94c25622e44215bba30e74e32626e5abb7101 | |
| parent | f9f5f3c9486a8202f1639dfe91e4e3410b1ee857 (diff) | |
| download | caxlsx-fa847fbe3b0b4b6ef3bee9b770b891798d16275c.tar.gz caxlsx-fa847fbe3b0b4b6ef3bee9b770b891798d16275c.zip | |
code formatting.
| -rw-r--r-- | lib/axlsx/stylesheet/styles.rb | 44 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_cell.rb | 1 |
2 files changed, 22 insertions, 23 deletions
diff --git a/lib/axlsx/stylesheet/styles.rb b/lib/axlsx/stylesheet/styles.rb index 955a8b1e..309e2842 100644 --- a/lib/axlsx/stylesheet/styles.rb +++ b/lib/axlsx/stylesheet/styles.rb @@ -120,7 +120,7 @@ module Axlsx end # Drastically simplifies style creation and management. - # @return [Integer] + # @return [Integer] # @option options [String] fg_color The text color # @option options [Integer] sz The text size # @option options [Boolean] b Indicates if the text should be bold @@ -133,13 +133,13 @@ module Axlsx # @option options [String] font_name The name of the font to use # @option options [Integer] num_fmt The number format to apply # @option options [String] format_code The formatting to apply. If this is specified, num_fmt is ignored. - # @option options [Integer] border The border style to use. + # @option options [Integer] border The border style to use. # @option options [String] bg_color The background color to apply to the cell # @option options [Boolean] hidden Indicates if the cell should be hidden # @option options [Boolean] locked Indicates if the cell should be locked # @option options [Hash] alignment A hash defining any of the attributes used in CellAlignment # @see CellAlignment - # + # # @example You Got Style # require "rubygems" # if that is your preferred way to manage gems! # require "axlsx" @@ -165,15 +165,15 @@ module Axlsx # ws = p.workbook.add_worksheet # # # define your styles - # title = ws.style.add_style(:bg_color => "FFFF0000", + # title = ws.style.add_style(:bg_color => "FFFF0000", # :fg_color=>"#FF000000", - # :border=>Axlsx::STYLE_THIN_BORDER, + # :border=>Axlsx::STYLE_THIN_BORDER, # :alignment=>{:horizontal => :center}) # # date_time = ws.style.add_style(:num_fmt => Axlsx::NUM_FMT_YYYYMMDDHHMMSS, # :border=>Axlsx::STYLE_THIN_BORDER) # - # percent = ws.style.add_style(:num_fmt => Axlsx::NUM_FMT_PERCENT, + # percent = ws.style.add_style(:num_fmt => Axlsx::NUM_FMT_PERCENT, # :border=>Axlsx::STYLE_THIN_BORDER) # # currency = ws.style.add_style(:format_code=>"¥#,##0;[Red]¥-#,##0", @@ -190,7 +190,7 @@ module Axlsx # f = File.open('example_you_got_style.xlsx', 'w') # p.serialize(f) def add_style(options={}) - + numFmtId = if options[:format_code] n = @numFmts.map{ |f| f.numFmtId }.max + 1 numFmts << NumFmt.new(:numFmtId => n, :formatCode=> options[:format_code]) @@ -198,19 +198,19 @@ module Axlsx else options[:num_fmt] || 0 end - + borderId = options[:border] || 0 raise ArgumentError, "Invalid borderId" unless borderId < borders.size - + fill = if options[:bg_color] color = Color.new(:rgb=>options[:bg_color]) pattern = PatternFill.new(:patternType =>:solid, :fgColor=>color) - fills << Fill.new(pattern) + fills << Fill.new(pattern) else 0 end - + fontId = if (options.values_at(:fg_color, :sz, :b, :i, :u, :strike, :outline, :shadow, :charset, :family, :font_name).length) font = Font.new() [:b, :i, :u, :strike, :outline, :shadow, :charset, :family, :sz].each { |k| font.send("#{k}=", options[k]) unless options[k].nil? } @@ -218,27 +218,27 @@ module Axlsx font.name = options[:font_name] unless options[:font_name].nil? fonts << font else - 0 + 0 end - + applyProtection = (options[:hidden] || options[:locked]) ? 1 : 0 - + xf = Xf.new(:fillId => fill, :fontId=>fontId, :applyFill=>1, :applyFont=>1, :numFmtId=>numFmtId, :borderId=>borderId, :applyProtection=>applyProtection) xf.applyNumberFormat = true if xf.numFmtId > 0 xf.applyBorder = true if borderId > 0 - + if options[:alignment] xf.alignment = CellAlignment.new(options[:alignment]) end - + if applyProtection xf.protection = CellProtection.new(options) end - + cellXfs << xf end - + # Serializes the styles document # @return [String] def to_xml() @@ -253,7 +253,7 @@ module Axlsx end private - # Creates the default set of styles the exel requires to be valid as well as setting up the + # Creates the default set of styles the exel requires to be valid as well as setting up the # Axlsx::STYLE_THIN_BORDER def load_default_styles @numFmts = SimpleTypedList.new NumFmt, 'numFmts' @@ -274,8 +274,8 @@ module Axlsx @borders = SimpleTypedList.new Border, 'borders' @borders << Border.new black_border = Border.new - [:left, :right, :top, :bottom].each do |item| - black_border.prs << BorderPr.new(:name=>item, :style=>:thin, :color=>Color.new(:rgb=>"FF000000")) + [:left, :right, :top, :bottom].each do |item| + black_border.prs << BorderPr.new(:name=>item, :style=>:thin, :color=>Color.new(:rgb=>"FF000000")) end @borders << black_border @borders.lock @@ -300,4 +300,4 @@ module Axlsx end end end - + diff --git a/test/workbook/worksheet/tc_cell.rb b/test/workbook/worksheet/tc_cell.rb index 04fa28f8..e111f7cd 100644 --- a/test/workbook/worksheet/tc_cell.rb +++ b/test/workbook/worksheet/tc_cell.rb @@ -21,7 +21,6 @@ class TestCell < Test::Unit::TestCase assert_equal(@c.value, 1.0, "type option is applied and value is casted") end - def test_style_date_data c = Axlsx::Cell.new(@c.row, Time.now) assert_equal(Axlsx::STYLE_DATE, c.style) |
