summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--README.md9
-rw-r--r--examples/basic_charts.rb46
-rwxr-xr-xexamples/example.rb2
-rw-r--r--examples/pie_chart.rb31
-rw-r--r--lib/axlsx/drawing/chart.rb6
-rw-r--r--lib/axlsx/drawing/graphic_frame.rb2
-rw-r--r--lib/axlsx/drawing/title.rb30
7 files changed, 78 insertions, 48 deletions
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 << '<?xml version="1.0" encoding="UTF-8"?>'
- str << '<c:chartSpace xmlns:c="' << XML_NS_C << '" xmlns:a="' << XML_NS_A << '">'
+ str << '<c:chartSpace xmlns:c="' << XML_NS_C << '" xmlns:a="' << XML_NS_A << '" xmlns:r="' << XML_NS_R << '">'
str << '<c:date1904 val="' << Axlsx::Workbook.date1904.to_s << '"/>'
str << '<c:style val="' << style.to_s << '"/>'
str << '<c:chart>'
@title.to_xml_string str
# do these need the c: namespace as well???
- str << '<c:autoTitleDeleted val="0"/>'
+ str << '<c:autoTitleDeleted val="' << (@title == nil).to_s << '"/>'
@view3D.to_xml_string(str) if @view3D
str << '<c:floor><c:thickness val="0"/></c:floor>'
str << '<c:sideWall><c:thickness val="0"/></c:sideWall>'
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 << '<xdr:graphicFrame>'
str << '<xdr:nvGraphicFramePr>'
- str << '<xdr:cNvPr id="' << @anchor.drawing.worksheet.workbook.drawings.index(@anchor.drawing).to_s << '" name="' << chart.title.text << '"/>'
+ str << '<xdr:cNvPr id="' << @anchor.drawing.index.to_s << '" name="' << 'item_' << @anchor.drawing.index.to_s << '"/>'
str << '<xdr:cNvGraphicFramePr/>'
str << '</xdr:nvGraphicFramePr>'
str << '<xdr:xfrm>'
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 << '<c:title>'
unless @text.empty?
str << '<c:tx>'
- str << '<c:strRef>'
- str << '<c:f>' << Axlsx::cell_range([@cell]) << '</c:f>'
- str << '<c:strCache>'
- str << '<c:ptCount val="1"/>'
- str << '<c:pt idx="0">'
- str << '<c:v>' << @text << '</c:v>'
- str << '</c:pt>'
- str << '</c:strCache>'
- str << '</c:strRef>'
+ if @cell.is_a?(Cell)
+ str << '<c:strRef>'
+ str << '<c:f>' << Axlsx::cell_range([@cell]) << '</c:f>'
+ str << '<c:strCache>'
+ str << '<c:ptCount val="1"/>'
+ str << '<c:pt idx="0">'
+ str << '<c:v>' << @text << '</c:v>'
+ str << '</c:pt>'
+ str << '</c:strCache>'
+ str << '</c:strRef>'
+ else
+ str << '<c:rich>'
+ str << '<a:bodyPr/>'
+ str << '<a:lstStyle/>'
+ str << '<a:p>'
+ str << '<a:r>'
+ str << '<a:t>' << @text.to_s << '</a:t>'
+ str << '</a:r>'
+ str << '</a:p>'
+ str << '</c:rich>'
+ end
str << '</c:tx>'
end
str << '<c:layout/>'