diff options
| author | Randy Morgan <[email protected]> | 2012-03-27 11:02:04 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-03-27 11:02:04 +0900 |
| commit | 7cdd465b283bb74ccaa6e7037f6937bf1c207e1e (patch) | |
| tree | 12c925ee0c1aacc2a4aca97ef5b793874d24cbcc /lib | |
| parent | 5ac9c5c94c396295136eec1ab117c3544795d9eb (diff) | |
| download | caxlsx-7cdd465b283bb74ccaa6e7037f6937bf1c207e1e.tar.gz caxlsx-7cdd465b283bb74ccaa6e7037f6937bf1c207e1e.zip | |
properly render inline colors
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/axlsx/stylesheet/color.rb | 6 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/cell.rb | 26 |
2 files changed, 20 insertions, 12 deletions
diff --git a/lib/axlsx/stylesheet/color.rb b/lib/axlsx/stylesheet/color.rb index a4942724..5d3e60ca 100644 --- a/lib/axlsx/stylesheet/color.rb +++ b/lib/axlsx/stylesheet/color.rb @@ -63,9 +63,9 @@ module Axlsx def to_xml_string str = ["<color "] - str << "tint='%s' " % tint if @tint - str << "rgb='%s' " % rgb if @rgb - str << "auto='%s'" % auto if @auto + self.instance_values.each do |key, value| + str << "%s='%s' " % [key, value] + end str << "/>" str.join end diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb index ba9cf8b5..46f6bac3 100644 --- a/lib/axlsx/workbook/worksheet/cell.rb +++ b/lib/axlsx/workbook/worksheet/cell.rb @@ -84,12 +84,6 @@ module Axlsx end - def set_run_style( validator, attr, value) - return unless INLINE_STYLES.include?(attr.to_s) - Axlsx.send(validator, value) unless validator == nil - self.instance_variable_set :"@#{attr.to_s}", value - @is_text_run = true - end # The inline font_name property for the cell # @return [String] attr_reader :font_name @@ -291,11 +285,17 @@ module Axlsx str = [] if is_text_run? keys = self.instance_values.reject{|key, value| value == nil }.keys & INLINE_STYLES - keys.delete ['font_name', 'value', 'type'] + keys.delete ['value', 'type'] str << "<r><rPr>" - str << "<rFont val='%s'/>" % @font_name if @font_name keys.each do |key| - str << "<%s val='%s'/>" % [key, self.instance_values[key]] + case key + when 'font_name' + str << "<rFont val='%s'/>" % @font_name if @font_name + when 'color' + str << self.instance_values[key].to_xml_string + else + "<%s val='%s'/>" % [key, self.instance_values[key]] + end end str << "</rPr>" str << "<t>%s</t>" % value.to_s @@ -406,6 +406,14 @@ module Axlsx private + # Utility method for setting inline style attributes + def set_run_style( validator, attr, value) + return unless INLINE_STYLES.include?(attr.to_s) + Axlsx.send(validator, value) unless validator == nil + self.instance_variable_set :"@#{attr.to_s}", value + @is_text_run = true + end + # @see ssti def ssti=(v) Axlsx::validate_unsigned_int(v) |
