From 061d16b216f14e90f535ccd36e2eb902b4af3b9e Mon Sep 17 00:00:00 2001 From: Ankur Sethi Date: Sun, 26 May 2013 13:10:40 -0300 Subject: Update bg_color in conditional formatting Conditional formatting for background color fills is different for DXF. This must be undocumented and is quite annoying. I verified the behavior in Excel 2010 Mac and Windows. I didn't understand why background colors were not being applied even though the style was being applied for conditional formatting. Looking at styles.xml I saw that it is different in a file created by Excel. I have updated the code to reflect it and tested in Mac and Windows. --- lib/axlsx/stylesheet/styles.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/axlsx/stylesheet/styles.rb b/lib/axlsx/stylesheet/styles.rb index 8cd2275c..44ccb752 100644 --- a/lib/axlsx/stylesheet/styles.rb +++ b/lib/axlsx/stylesheet/styles.rb @@ -296,9 +296,11 @@ module Axlsx def parse_fill_options(options={}) return unless options[:bg_color] color = Color.new(:rgb=>options[:bg_color]) - pattern = PatternFill.new(:patternType =>:solid, :fgColor=>color) + dxf = options[:type] == :dxf + color_key = dxf ? :bgColor : :fgColor + pattern = PatternFill.new(:patternType =>:solid, color_key=>color) fill = Fill.new(pattern) - options[:type] == :dxf ? fill : fills << fill + dxf ? fill : fills << fill end # parses Style#add_style options for borders. -- cgit v1.2.3 From 0ec328213fbe31cd4456dceecda6d7ba8d1c9021 Mon Sep 17 00:00:00 2001 From: Stefan Daschek Date: Wed, 12 Jun 2013 23:08:14 +0200 Subject: Allow overriding the 'created' timestamp in the docprops. Can be specified as option to Package#new: ``` Axlsx::Package.new :created_at => time ``` If omitted, the current time at the moment the document is serialized will be used. This change is therefore fully backward compatible. --- lib/axlsx/doc_props/core.rb | 7 ++++++- lib/axlsx/package.rb | 2 ++ test/doc_props/tc_core.rb | 7 +++++++ test/tc_package.rb | 6 ++++++ 4 files changed, 21 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/axlsx/doc_props/core.rb b/lib/axlsx/doc_props/core.rb index d71300e0..a74031f2 100644 --- a/lib/axlsx/doc_props/core.rb +++ b/lib/axlsx/doc_props/core.rb @@ -8,14 +8,19 @@ module Axlsx # Creates a new Core object. # @option options [String] creator + # @option options [Time] created def initialize(options={}) @creator = options[:creator] || 'axlsx' + @created = options[:created] end # The author of the document. By default this is 'axlsx' # @return [String] attr_accessor :creator + # Creation time of the document. If nil, the current time will be used. + attr_accessor :created + # serializes the core.xml document # @return [String] def to_xml_string(str = '') @@ -24,7 +29,7 @@ module Axlsx str << 'xmlns:dcmitype="' << CORE_NS_DCMIT << '" xmlns:dcterms="' << CORE_NS_DCT << '" ' str << 'xmlns:xsi="' << CORE_NS_XSI << '">' str << '' << self.creator << '' - str << '' << Time.now.strftime('%Y-%m-%dT%H:%M:%S') << 'Z' + str << '' << (created || Time.now).strftime('%Y-%m-%dT%H:%M:%S') << 'Z' str << '0' str << '' end diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb index df87ed12..5a5a2169 100644 --- a/lib/axlsx/package.rb +++ b/lib/axlsx/package.rb @@ -17,12 +17,14 @@ module Axlsx # # @param [Hash] options A hash that you can use to specify the author and workbook for this package. # @option options [String] :author The author of the document + # @option options [Time] :created_at Timestamp in the document properties (defaults to current time). # @option options [Boolean] :use_shared_strings This is passed to the workbook to specify that shared strings should be used when serializing the package. # @example Package.new :author => 'you!', :workbook => Workbook.new def initialize(options={}) @workbook = nil @core, @app = Core.new, App.new @core.creator = options[:author] || @core.creator + @core.created = options[:created_at] parse_options options yield self if block_given? end diff --git a/test/doc_props/tc_core.rb b/test/doc_props/tc_core.rb index cfff4d59..0eddfed7 100644 --- a/test/doc_props/tc_core.rb +++ b/test/doc_props/tc_core.rb @@ -23,6 +23,13 @@ class TestCore < Test::Unit::TestCase assert_equal(@doc.xpath('//dcterms:created').text, @time, "dcterms:created incorrect") end + def test_created_as_option + time = Time.utc(2013, 1, 1, 12, 00) + c = Axlsx::Core.new :created => time + doc = Nokogiri::XML(c.to_xml_string) + assert_equal(doc.xpath('//dcterms:created').text, time.xmlschema, "dcterms:created incorrect") + end + def test_populates_default_name assert_equal(@doc.xpath('//dc:creator').text, "axlsx", "Default name not populated") end diff --git a/test/tc_package.rb b/test/tc_package.rb index 5fd411e0..df096a31 100644 --- a/test/tc_package.rb +++ b/test/tc_package.rb @@ -105,6 +105,12 @@ class TestPackage < Test::Unit::TestCase assert(Axlsx::Package.new.workbook.worksheets.size == 0, 'Workbook should not have sheets by default') end + def test_created_at_is_propagated_to_core + time = Time.utc(2013, 1, 1, 12, 0) + p = Axlsx::Package.new :created_at => time + assert_equal(time, p.core.created) + end + def test_serialization assert_nothing_raised do begin -- cgit v1.2.3