diff options
| -rwxr-xr-x | examples/example.rb | 19 | ||||
| -rw-r--r-- | lib/axlsx/drawing/chart.rb | 18 | ||||
| -rw-r--r-- | lib/axlsx/package.rb | 2 | ||||
| -rw-r--r-- | test/drawing/tc_pic.rb | 4 |
4 files changed, 40 insertions, 3 deletions
diff --git a/examples/example.rb b/examples/example.rb index 116ce730..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 @@ -210,6 +211,7 @@ if examples.include? :row_column_style head = s.add_style :bg_color => "00", :fg_color => "FF" percent = s.add_style :num_fmt => 9 wb.add_worksheet(:name => "Columns and Rows") do |sheet| + # Note: you must add rows to the document *BEFORE* applying column styles to them sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4', 'col5'] sheet.add_row [1, 2, 0.3, 4, 5.0] sheet.add_row [1, 2, 0.2, 4, 5.0] @@ -246,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| @@ -825,4 +842,4 @@ if examples.include? :rich_text end p.serialize 'rich_text.xlsx' end -#```
\ No newline at end of file +#``` diff --git a/lib/axlsx/drawing/chart.rb b/lib/axlsx/drawing/chart.rb index 066d49cd..e7fcc9e8 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 @@ -72,6 +74,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 @@ -131,6 +144,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 @@ -178,7 +194,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/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 |
