summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--lib/axlsx/workbook/worksheet/rich_text.rb18
-rw-r--r--lib/axlsx/workbook/worksheet/rich_text_run.rb6
-rw-r--r--test/drawing/tc_drawing.rb4
-rw-r--r--test/workbook/worksheet/tc_pivot_table.rb7
-rw-r--r--test/workbook/worksheet/tc_table.rb5
-rw-r--r--test/workbook/worksheet/tc_worksheet.rb10
6 files changed, 34 insertions, 16 deletions
diff --git a/lib/axlsx/workbook/worksheet/rich_text.rb b/lib/axlsx/workbook/worksheet/rich_text.rb
index e8c58c67..81af32b2 100644
--- a/lib/axlsx/workbook/worksheet/rich_text.rb
+++ b/lib/axlsx/workbook/worksheet/rich_text.rb
@@ -1,34 +1,52 @@
module Axlsx
+ # A simple, self serializing class for storing TextRuns
class RichText < SimpleTypedList
+ # creates a new RichText collection
+ # @param [String] text -optional The text to use in creating the first RichTextRun
+ # @param [Object] options -optional The options to use in creating the first RichTextRun
+ # @yield [RichText] self
def initialize(text = nil, options={})
super(RichTextRun)
add_run(text, options) unless text.nil?
yield self if block_given?
end
+ # The cell that owns this RichText collection
attr_reader :cell
+ # Assign the cell for this RichText collection
+ # @param [Cell] cell The cell which all RichTextRuns in the collection will belong to
def cell=(cell)
@cell = cell
each { |run| run.cell = cell }
end
+ # Calculates the longest autowidth of the RichTextRuns in this collection
+ # @return [Number]
def autowidth
widtharray = [0] # Are arrays the best way of solving this problem?
each { |run| run.autowidth(widtharray) }
widtharray.max
end
+ # Creates and adds a RichTextRun to this collectino
+ # @param [String] text The text to use in creating a new RichTextRun
+ # @param [Object] options The options to use in creating the new RichTextRun
def add_run(text, options={})
self << RichTextRun.new(text, options)
end
+ # The RichTextRuns we own
+ # @return [RichText]
def runs
self
end
+ # renders the RichTextRuns in this collection
+ # @param [String] str
+ # @return [String]
def to_xml_string(str='')
each{ |run| run.to_xml_string(str) }
str
diff --git a/lib/axlsx/workbook/worksheet/rich_text_run.rb b/lib/axlsx/workbook/worksheet/rich_text_run.rb
index e709f265..40d99bb0 100644
--- a/lib/axlsx/workbook/worksheet/rich_text_run.rb
+++ b/lib/axlsx/workbook/worksheet/rich_text_run.rb
@@ -1,10 +1,13 @@
module Axlsx
+
+ # The RichTextRun class creates and self serializing text run.
class RichTextRun
include Axlsx::OptionsParser
attr_reader :value
+ # A list of allowed inline style attributes used for validation
INLINE_STYLES = [:font_name, :charset,
:family, :b, :i, :strike, :outline,
:shadow, :condense, :extend, :u,
@@ -182,6 +185,9 @@ module Axlsx
self.instance_variable_set :"@#{attr.to_s}", value
end
+ # Serializes the RichTextRun
+ # @param [String] str
+ # @return [String]
def to_xml_string(str = '')
valid = RichTextRun::INLINE_STYLES
data = Hash[self.instance_values.map{ |k, v| [k.to_sym, v] }]
diff --git a/test/drawing/tc_drawing.rb b/test/drawing/tc_drawing.rb
index 7014f1b2..c9095fe7 100644
--- a/test/drawing/tc_drawing.rb
+++ b/test/drawing/tc_drawing.rb
@@ -59,9 +59,9 @@ class TestDrawing < Test::Unit::TestCase
end
def test_relationships
- chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"bob", :start_at=>[0,0], :end_at=>[1,1])
+ @ws.add_chart(Axlsx::Pie3DChart, :title=>"bob", :start_at=>[0,0], :end_at=>[1,1])
assert_equal(@ws.drawing.relationships.size, 1, "adding a chart adds a relationship")
- chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"nancy", :start_at=>[1,5], :end_at=>[5,10])
+ @ws.add_chart(Axlsx::Pie3DChart, :title=>"nancy", :start_at=>[1,5], :end_at=>[5,10])
assert_equal(@ws.drawing.relationships.size, 2, "adding a chart adds a relationship")
end
diff --git a/test/workbook/worksheet/tc_pivot_table.rb b/test/workbook/worksheet/tc_pivot_table.rb
index ff7f8b92..6d7f4d1c 100644
--- a/test/workbook/worksheet/tc_pivot_table.rb
+++ b/test/workbook/worksheet/tc_pivot_table.rb
@@ -117,12 +117,7 @@ class TestPivotTable < Test::Unit::TestCase
end
def test_to_xml_string
- pivot_table = @ws.add_pivot_table('G5:G6', 'A1:D5')
- shared_test_pivot_table_xml_validity(pivot_table)
- end
-
- def test_to_xml_string_with_configuration
- pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5') do |pt|
+ pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5', {:no_subtotals_on_headers=>['Year']}) do |pt|
pt.rows = ['Year', 'Month']
pt.columns = ['Type']
pt.data = ['Sales']
diff --git a/test/workbook/worksheet/tc_table.rb b/test/workbook/worksheet/tc_table.rb
index 6f39bb13..8edfc099 100644
--- a/test/workbook/worksheet/tc_table.rb
+++ b/test/workbook/worksheet/tc_table.rb
@@ -47,9 +47,9 @@ class TestTable < Test::Unit::TestCase
def test_relationships
assert(@ws.relationships.empty?)
- table = @ws.add_table("A1:D5")
+ @ws.add_table("A1:D5")
assert_equal(@ws.relationships.size, 1, "adding a table adds a relationship")
- table = @ws.add_table("F1:J5")
+ @ws.add_table("F1:J5")
assert_equal(@ws.relationships.size, 2, "adding a table adds a relationship")
end
@@ -64,5 +64,4 @@ class TestTable < Test::Unit::TestCase
end
assert(errors.empty?, "error free validation")
end
-
end
diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb
index c7e963f5..fa8832d8 100644
--- a/test/workbook/worksheet/tc_worksheet.rb
+++ b/test/workbook/worksheet/tc_worksheet.rb
@@ -437,15 +437,15 @@ class TestWorksheet < Test::Unit::TestCase
def test_relationships
@ws.add_row [1,2,3]
assert(@ws.relationships.empty?, "No Drawing relationship until you add a chart")
- c = @ws.add_chart Axlsx::Pie3DChart
+ @ws.add_chart Axlsx::Pie3DChart
assert_equal(@ws.relationships.size, 1, "adding a chart creates the relationship")
- c = @ws.add_chart Axlsx::Pie3DChart
+ @ws.add_chart Axlsx::Pie3DChart
assert_equal(@ws.relationships.size, 1, "multiple charts still only result in one relationship")
- c = @ws.add_comment :text => 'builder', :author => 'bob', :ref => @ws.rows.last.cells.last
+ @ws.add_comment :text => 'builder', :author => 'bob', :ref => @ws.rows.last.cells.last
assert_equal(@ws.relationships.size, 3, "adding a comment adds 2 relationships")
- c = @ws.add_comment :text => 'not that is a comment!', :author => 'travis', :ref => "A1"
+ @ws.add_comment :text => 'not that is a comment!', :author => 'travis', :ref => "A1"
assert_equal(@ws.relationships.size, 3, "adding multiple comments in the same worksheet should not add any additional comment relationships")
- c = @ws.add_pivot_table 'G5:G6', 'A1:D10'
+ @ws.add_pivot_table 'G5:G6', 'A1:D10'
assert_equal(@ws.relationships.size, 4, "adding a pivot table adds 1 relationship")
end