From 2d6d18c2e0b8e1b68adae27500c002cfb4cd01b4 Mon Sep 17 00:00:00 2001 From: Randy Morgan Date: Tue, 5 Jun 2012 13:03:32 +0900 Subject: fix chart title parsing to properly handle non-cell based text runs --- README.md | 9 +++++--- examples/basic_charts.rb | 46 ++++++++++++++++++++++++++++++++++++++ examples/example.rb | 2 +- examples/pie_chart.rb | 31 ------------------------- lib/axlsx/drawing/chart.rb | 6 ++--- lib/axlsx/drawing/graphic_frame.rb | 2 +- lib/axlsx/drawing/title.rb | 30 +++++++++++++++++-------- 7 files changed, 78 insertions(+), 48 deletions(-) create mode 100644 examples/basic_charts.rb delete mode 100644 examples/pie_chart.rb diff --git a/README.md b/README.md index ab592fe7..2beac5b2 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Axlsx: Office Open XML Spreadsheet Generation **Rubinius Version**: rubinius 2.0.0dev * lower versions may run, this gem always tests against head. -**Release Date**: June 4th 2012 +**Release Date**: June 5th 2012 If you are working in rails, or with active record see: http://github.com/randym/acts_as_xlsx @@ -115,9 +115,12 @@ This gem has 100% test coverage using test/unit. To execute tests for this gem, #Change log --------- -- **June.4.12**: 1.1.7 release +- **June.5.12**: 1.1.7 release - fix chart rendering issue when label offset is specified as a - percentage in serialization. + percentage in serialization and ensure that formula are not stored +in value caches + - fix bug that causes repair warnings when using a text only title reference. + - **May.30.12**: 1.1.6 release - data protection with passwords for sheets - cell level input validators diff --git a/examples/basic_charts.rb b/examples/basic_charts.rb new file mode 100644 index 00000000..63cb715b --- /dev/null +++ b/examples/basic_charts.rb @@ -0,0 +1,46 @@ +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" +require 'axlsx' +p = Axlsx::Package.new +wb = p.workbook + +# Pie Chart +wb.add_worksheet(:name => "Pie Chart") do |sheet| + sheet.add_row ["First", "Second", "Third", "Fourth"] + sheet.add_row [1, 2, 3, 4] + sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,2], :end_at => [5, 15], :title=> 'dark corner here') do |chart| + chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"] + end +end + +# line chart + wb.add_worksheet(:name => "Line Chart") do |sheet| + sheet.add_row ['1', '2', '3', '4'] + sheet.add_row [1, 2, 3, '=sum(A2:C2)'] + sheet.add_chart(Axlsx::Line3DChart, :start_at => [0,2], :end_at => [5, 15], :title => "Chart") do |chart| + chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"], :title => 'bob' + end + end + +# bar chart + wb.add_worksheet(:name => "Bar Chart") do |sheet| + sheet.add_row ["A Simple Bar Chart"] + sheet.add_row ["First", "Second", "Third"] + sheet.add_row [1, 2, 3] + sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A4", :end_at => "F17") do |chart| + chart.add_series :data => sheet["A3:C3"], :labels => sheet["A2:C2"], :title => sheet["A1"] + chart.valAxis.label_rotation = -45 + chart.catAxis.label_rotation = 45 + end + end + +# specifying colors and title +wb.add_worksheet(:name => "Colored Pie Chart") do |sheet| + sheet.add_row ["First", "Second", "Third", "Fourth"] + sheet.add_row [1, 2, 3, "=PRODUCT(A2:C2)"] + sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,2], :end_at => [5, 15], :title => "example 3: Pie Chart") do |chart| + chart.add_series :data => sheet["A2:D2"], :labels => ["A1:D1"], :colors => ['FF0000', '00FF00', '0000FF'] + end +end + +p.serialize('basic_charts.xlsx') + diff --git a/examples/example.rb b/examples/example.rb index 315c7146..446dd79c 100755 --- a/examples/example.rb +++ b/examples/example.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -w -s # -*- coding: utf-8 -*- -# $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" #```ruby require 'axlsx' diff --git a/examples/pie_chart.rb b/examples/pie_chart.rb deleted file mode 100644 index 8c261b31..00000000 --- a/examples/pie_chart.rb +++ /dev/null @@ -1,31 +0,0 @@ -$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" -require 'axlsx' -p = Axlsx::Package.new -wb = p.workbook -##Generating A Pie Chart -#```ruby -wb.add_worksheet(:name => "Pie Chart") do |sheet| - sheet.add_row ["First", "Second", "Third", "Fourth"] - sheet.add_row [1, 2, 3, '=sum(A2:C2)'] - sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,2], :end_at => [5, 15], :title => "Chart") do |chart| - chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"] - end -end - -p.serialize('pie_chart.xlsx') - - -# -# Line Chart - -p = Axlsx::Package.new -wb = p.workbook -wb.add_worksheet(:name => "Line Chart") do |sheet| - sheet.add_row ['first', 'second', 'third', 'fourth'] - sheet.add_row [1, 2, 3, '=sum(A2:C2)'] - sheet.add_chart(Axlsx::Line3DChart, :start_at => [0,2], :end_at => [5, 15], :title => "Chart") do |chart| - chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"], :title => 'bob' - end -end -p.serialize('line_chart.xlsx') -## diff --git a/lib/axlsx/drawing/chart.rb b/lib/axlsx/drawing/chart.rb index 0f26c551..f0f0185b 100644 --- a/lib/axlsx/drawing/chart.rb +++ b/lib/axlsx/drawing/chart.rb @@ -44,7 +44,7 @@ module Axlsx # @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={}) - @style = 2 + @style = 18 @view3D = nil @graphic_frame=frame @graphic_frame.anchor.drawing.worksheet.workbook.charts << self @@ -120,13 +120,13 @@ module Axlsx # @return [String] def to_xml_string(str = '') str << '' - str << '' + str << '' str << '' str << '' str << '' @title.to_xml_string str # do these need the c: namespace as well??? - str << '' + str << '' @view3D.to_xml_string(str) if @view3D str << '' str << '' diff --git a/lib/axlsx/drawing/graphic_frame.rb b/lib/axlsx/drawing/graphic_frame.rb index e36ae3f2..a829e5ea 100644 --- a/lib/axlsx/drawing/graphic_frame.rb +++ b/lib/axlsx/drawing/graphic_frame.rb @@ -35,7 +35,7 @@ module Axlsx # macro attribute should be optional! str << '' str << '' - str << '' + str << '' str << '' str << '' str << '' diff --git a/lib/axlsx/drawing/title.rb b/lib/axlsx/drawing/title.rb index a85d8e11..5292a177 100644 --- a/lib/axlsx/drawing/title.rb +++ b/lib/axlsx/drawing/title.rb @@ -46,15 +46,27 @@ module Axlsx str << '' unless @text.empty? str << '' - str << '' - str << '' << Axlsx::cell_range([@cell]) << '' - str << '' - str << '' - str << '' - str << '' << @text << '' - str << '' - str << '' - str << '' + if @cell.is_a?(Cell) + str << '' + str << '' << Axlsx::cell_range([@cell]) << '' + str << '' + str << '' + str << '' + str << '' << @text << '' + str << '' + str << '' + str << '' + else + str << '' + str << '' + str << '' + str << '' + str << '' + str << '' << @text.to_s << '' + str << '' + str << '' + str << '' + end str << '' end str << '' -- cgit v1.2.3