From 7cdd465b283bb74ccaa6e7037f6937bf1c207e1e Mon Sep 17 00:00:00 2001 From: Randy Morgan Date: Tue, 27 Mar 2012 11:02:04 +0900 Subject: properly render inline colors --- lib/axlsx/stylesheet/color.rb | 6 +++--- 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 = ["" 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 << "" - str << "" % @font_name if @font_name keys.each do |key| - str << "<%s val='%s'/>" % [key, self.instance_values[key]] + case key + when 'font_name' + str << "" % @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 << "" str << "%s" % 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) -- cgit v1.2.3