diff options
| -rw-r--r-- | Gemfile | 7 | ||||
| -rwxr-xr-x | examples/example.rb | 16 | ||||
| -rw-r--r-- | lib/axlsx/drawing/chart.rb | 18 | ||||
| -rw-r--r-- | lib/axlsx/package.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/page_setup.rb | 40 | ||||
| -rw-r--r-- | test/drawing/tc_pic.rb | 4 | ||||
| -rw-r--r-- | test/tc_helper.rb | 2 | ||||
| -rw-r--r-- | test/tc_package.rb | 2 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_page_setup.rb | 6 |
9 files changed, 67 insertions, 30 deletions
@@ -1,9 +1,10 @@ -source "https://rubygems.org" +source 'https://rubygems.org' gemspec group :test do - gem "rake", ">= 0.8.7" - gem "simplecov" + gem 'rake', '>= 0.8.7' + gem 'simplecov' + gem 'test-unit' end group :profile do diff --git a/examples/example.rb b/examples/example.rb index 5eacdce9..15d34ed6 100755 --- a/examples/example.rb +++ b/examples/example.rb @@ -14,6 +14,7 @@ examples << :surrounding_border examples << :deep_custom_borders examples << :row_column_style examples << :fixed_column_width +examples << :height examples << :outline_level examples << :merge_cells examples << :images @@ -247,6 +248,21 @@ if examples.include? :fixed_column_width end end + +##Specifying Row height + +#```ruby +if examples.include? :height + wb.styles do |s| + head = s.add_style :bg_color => "00", :fg_color => "FF" + wb.add_worksheet(:name => "fixed row height") do |sheet| + sheet.add_row ["This row will have a fixed height", "It will overwite the default row height"], :height => 30 + sheet.add_row ["This row can have a different height too"], :height => 10, :style => head + end + end +end + + #```ruby if examples.include? :outline_level wb.add_worksheet(name: 'outline_level') do |sheet| diff --git a/lib/axlsx/drawing/chart.rb b/lib/axlsx/drawing/chart.rb index 1d6b9293..322f9463 100644 --- a/lib/axlsx/drawing/chart.rb +++ b/lib/axlsx/drawing/chart.rb @@ -11,6 +11,7 @@ module Axlsx # @param [GraphicalFrame] frame The frame that holds this chart. # @option options [Cell, String] title # @option options [Boolean] show_legend + # @option options [Symbol] legend_position # @option options [Array|String|Cell] start_at The X, Y coordinates defining the top left corner of the chart. # @option options [Array|String|Cell] end_at The X, Y coordinates defining the bottom right corner of the chart. def initialize(frame, options={}) @@ -20,6 +21,7 @@ module Axlsx @graphic_frame.anchor.drawing.worksheet.workbook.charts << self @series = SimpleTypedList.new Series @show_legend = true + @legend_position = :r @display_blanks_as = :gap @series_type = Series @title = Title.new @@ -71,6 +73,17 @@ module Axlsx # @return [Boolean] attr_reader :show_legend + # Set the location of the chart's legend + # @return [Symbol] The position of this legend + # @note + # The following are allowed + # :b + # :l + # :r + # :t + # :tr + attr_reader :legend_position + # How to display blank values # Options are # * gap: Display nothing @@ -126,6 +139,9 @@ module Axlsx # @param [Integer] v must be between 1 and 48 def style=(v) DataTypeValidator.validate "Chart.style", Integer, v, lambda { |arg| arg >= 1 && arg <= 48 }; @style = v; end + # @see legend_position + def legend_position=(v) RestrictionValidator.validate "Chart.legend_position", [:b, :l, :r, :t, :tr], v; @legend_position = v; end + # backwards compatibility to allow chart.to and chart.from access to anchor markers # @note This will be disconinued in version 2.0.0. Please use the end_at method def to @@ -167,7 +183,7 @@ module Axlsx str << '</c:plotArea>' if @show_legend str << '<c:legend>' - str << '<c:legendPos val="r"/>' + str << ('<c:legendPos val="' << @legend_position.to_s << '"/>') str << '<c:layout/>' str << '<c:overlay val="0"/>' str << '</c:legend>' diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb index cd03a173..8a4f29dc 100644 --- a/lib/axlsx/package.rb +++ b/lib/axlsx/package.rb @@ -314,7 +314,7 @@ module Axlsx c_types << Axlsx::Override.new(:PartName => "/xl/#{sheet.pn}", :ContentType => WORKSHEET_CT) end - exts = workbook.images.map { |image| image.extname } + exts = workbook.images.map { |image| image.extname.downcase } exts.uniq.each do |ext| ct = if ['jpeg', 'jpg'].include?(ext) JPEG_CT diff --git a/lib/axlsx/workbook/worksheet/page_setup.rb b/lib/axlsx/workbook/worksheet/page_setup.rb index fc29b0c5..9558579e 100644 --- a/lib/axlsx/workbook/worksheet/page_setup.rb +++ b/lib/axlsx/workbook/worksheet/page_setup.rb @@ -44,13 +44,13 @@ module Axlsx # Number of horizontal pages to fit on. # @note PageSetup#fit_to is the recomended way to manage page fitting as only specifying one of width/height will result in the counterpart - # being set to 1. + # being set to 1. # @return [Integer] attr_reader :fit_to_width # Orientation of the page (:default, :landscape, :portrait) # @return [Symbol] - attr_reader :orientation + attr_reader :orientation # Height of paper (string containing a number followed by a unit identifier: "297mm", "11in") # @return [String] @@ -74,18 +74,18 @@ module Axlsx #7 = Executive paper (7.25 in. by 10.5 in.) #8 = A3 paper (297 mm by 420 mm) #9 = A4 paper (210 mm by 297 mm) - #10 = A4 small paper (210 mm by 297 mm) + #10 = A4 small paper (210 mm by 297 mm) #11 = A5 paper (148 mm by 210 mm) #12 = B4 paper (250 mm by 353 mm) #13 = B5 paper (176 mm by 250 mm) #14 = Folio paper (8.5 in. by 13 in.) - #15 = Quarto paper (215 mm by 275 mm) + #15 = Quarto paper (215 mm by 275 mm) #16 = Standard paper (10 in. by 14 in.) #17 = Standard paper (11 in. by 17 in.) #18 = Note paper (8.5 in. by 11 in.) - #19 = #9 envelope (3.875 in. by 8.875 in.) - #20 = #10 envelope (4.125 in. by 9.5 in.) - #21 = #11 envelope (4.5 in. by 10.375 in.) + #19 = #9 envelope (3.875 in. by 8.875 in.) + #20 = #10 envelope (4.125 in. by 9.5 in.) + #21 = #11 envelope (4.5 in. by 10.375 in.) #22 = #12 envelope (4.75 in. by 11 in.) #23 = #14 envelope (5 in. by 11.5 in.) 24 = C paper (17 in. by 22 in.) #25 = D paper (22 in. by 34 in.) @@ -105,7 +105,7 @@ module Axlsx #40 = German standard fanfold (8.5 in. by 12 in.) #41 = German legal fanfold (8.5 in. by 13 in.) #42 = ISO B4 (250 mm by 353 mm) - #43 = Japanese double postcard (200 mm by 148 mm) + #43 = Japanese double postcard (200 mm by 148 mm) #44 = Standard paper (9 in. by 11 in.) #45 = Standard paper (10 in. by 11 in.) #46 = Standard paper (15 in. by 11 in.) @@ -116,9 +116,9 @@ module Axlsx #53 = A4 extra paper (236 mm by 322 mm) #54 = Letter transverse paper (8.275 in. by 11 in.) #55 = A4 transverse paper (210 mm by 297 mm) - #56 = Letter extra transverse paper (9.275 in. by 12 in.) - #57 = SuperA/SuperA/A4 paper (227 mm by 356 mm) - #58 = SuperB/SuperB/A3 paper (305 mm by 487 mm) + #56 = Letter extra transverse paper (9.275 in. by 12 in.) + #57 = SuperA/SuperA/A4 paper (227 mm by 356 mm) + #58 = SuperB/SuperB/A3 paper (305 mm by 487 mm) #59 = Letter plus paper (8.5 in. by 12.69 in.) #60 = A4 plus paper (210 mm by 330 mm) #61 = A5 transverse paper (148 mm by 210 mm) @@ -128,8 +128,8 @@ module Axlsx #65 = ISO B5 extra paper (201 mm by 276 mm) #66 = A2 paper (420 mm by 594 mm) #67 = A3 transverse paper (297 mm by 420 mm) - #68 = A3 extra transverse paper (322 mm by 445 mm) - #69 = Japanese Double Postcard (200 mm x 148 mm) + #68 = A3 extra transverse paper (322 mm by 445 mm) + #69 = Japanese Double Postcard (200 mm x 148 mm) #70 = A6 (105 mm x 148 mm #71 = Japanese Envelope Kaku #2 #72 = Japanese Envelope Kaku #3 @@ -142,7 +142,7 @@ module Axlsx #79 = B4 (JIS) Rotated (364 mm x 257 mm) #80 = B5 (JIS) Rotated (257 mm x 182 mm) #81 = Japanese Postcard Rotated (148 mm x 100 mm) - #82 = Double Japanese Postcard Rotated (148 mm x 200 mm) + #82 = Double Japanese Postcard Rotated (148 mm x 200 mm) #83 = A6 Rotated (148 mm x 105 mm) #84 = Japanese Envelope Kaku #2 Rotated #85 = Japanese Envelope Kaku #3 Rotated @@ -210,20 +210,20 @@ module Axlsx # @see scale def scale=(v); Axlsx::validate_scale_10_400(v); @scale = v; end - # convenience method to achieve sanity when setting fit_to_width and fit_to_height + # convenience method to achieve sanity when setting fit_to_width and fit_to_height # as they both default to 1 if only their counterpart is specified. # @note This method will overwrite any value you explicitly set via the fit_to_height or fit_to_width methods. - # @option options [Integer] width The number of pages to fit this worksheet on horizontally. Default 9999 - # @option options [Integer] height The number of pages to fit this worksheet on vertically. Default 9999 + # @option options [Integer] width The number of pages to fit this worksheet on horizontally. Default 999 + # @option options [Integer] height The number of pages to fit this worksheet on vertically. Default 999 def fit_to(options={}) - self.fit_to_width = options[:width] || 9999 - self.fit_to_height = options[:height] || 9999 + self.fit_to_width = options[:width] || 999 + self.fit_to_height = options[:height] || 999 [@fit_to_width, @fit_to_height] end # helper method for worksheet to determine if the page setup is configured for fit to page printing - # We treat any page set up that has a value set for fit_to_width or fit_to_height value as fit_to_page. + # We treat any page set up that has a value set for fit_to_width or fit_to_height value as fit_to_page. # @return [Boolean] def fit_to_page? # is there some better what to express this? diff --git a/test/drawing/tc_pic.rb b/test/drawing/tc_pic.rb index b8bd2c36..3cea49c0 100644 --- a/test/drawing/tc_pic.rb +++ b/test/drawing/tc_pic.rb @@ -79,6 +79,10 @@ class TestPic < Test::Unit::TestCase def test_image_src_downcase assert_nothing_raised { @image.image_src = @test_img_up } + ct = @p.send(:content_types).detect do |t| + t.respond_to?(:extension) && t.extension.downcase == @image.extname.downcase + end + assert_equal("image/jpeg", ct.content_type) end def test_descr diff --git a/test/tc_helper.rb b/test/tc_helper.rb index af40a1e4..96f545cd 100644 --- a/test/tc_helper.rb +++ b/test/tc_helper.rb @@ -7,4 +7,4 @@ end require 'test/unit' require "timecop" -require "axlsx.rb" +require "axlsx.rb"
\ No newline at end of file diff --git a/test/tc_package.rb b/test/tc_package.rb index 0a33e248..0ad27f7d 100644 --- a/test/tc_package.rb +++ b/test/tc_package.rb @@ -54,7 +54,7 @@ class TestPackage < Test::Unit::TestCase end ws.add_chart(Axlsx::BubbleChart, :title => 'bubble chart') do |chart| - chart.add_series :xData => [1,2,3,4], :yData => [4,3,2,1], :yData => [1,3,2,4] + chart.add_series :xData => [1,2,3,4], :yData => [1,3,2,4] chart.d_lbls.show_val = true end diff --git a/test/workbook/worksheet/tc_page_setup.rb b/test/workbook/worksheet/tc_page_setup.rb index 4c78f4ae..097eb563 100644 --- a/test/workbook/worksheet/tc_page_setup.rb +++ b/test/workbook/worksheet/tc_page_setup.rb @@ -63,7 +63,7 @@ class TestPageSetup < Test::Unit::TestCase assert(@ps.fit_to_width == nil && @ps.fit_to_height == nil) assert(@ps.fit_to_page? == false) end - + def test_with_height_fit_to_page? assert(@ps.fit_to_width == nil && @ps.fit_to_height == nil) @ps.set(:fit_to_height => 1) @@ -131,9 +131,9 @@ class TestPageSetup < Test::Unit::TestCase def test_fit_to fits = @ps.fit_to(:width => 1) - assert_equal([1, 9999], fits) + assert_equal([1, 999], fits) fits = @ps.fit_to :height => 1 - assert_equal(fits, [9999,1]) + assert_equal(fits, [999 ,1]) fits = @ps.fit_to :height => 7, :width => 2 assert_equal(fits, [2, 7]) assert_raise(ArgumentError) { puts @ps.fit_to(:width => true)} |
