axlsx 2.0.1 → 2.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -3
  3. data/Rakefile +9 -10
  4. data/examples/IMAGE1UP.JPEG +0 -0
  5. data/examples/auto_filter.rb +10 -1
  6. data/examples/conditional_formatting/example_conditional_formatting.rb +3 -3
  7. data/examples/example.rb +72 -4
  8. data/examples/merge_cells.rb +17 -0
  9. data/examples/no_grid_with_borders.rb +18 -0
  10. data/examples/pivot_test.rb +63 -0
  11. data/examples/split.rb +16 -0
  12. data/lib/axlsx.rb +30 -16
  13. data/lib/axlsx/content_type/abstract_content_type.rb +1 -1
  14. data/lib/axlsx/content_type/content_type.rb +1 -1
  15. data/lib/axlsx/doc_props/app.rb +1 -1
  16. data/lib/axlsx/doc_props/core.rb +5 -5
  17. data/lib/axlsx/drawing/axes.rb +1 -1
  18. data/lib/axlsx/drawing/axis.rb +12 -9
  19. data/lib/axlsx/drawing/bar_3D_chart.rb +13 -13
  20. data/lib/axlsx/drawing/bar_series.rb +9 -9
  21. data/lib/axlsx/drawing/bubble_chart.rb +59 -0
  22. data/lib/axlsx/drawing/bubble_series.rb +63 -0
  23. data/lib/axlsx/drawing/cat_axis.rb +5 -5
  24. data/lib/axlsx/drawing/chart.rb +44 -7
  25. data/lib/axlsx/drawing/drawing.rb +3 -1
  26. data/lib/axlsx/drawing/graphic_frame.rb +3 -3
  27. data/lib/axlsx/drawing/hyperlink.rb +1 -3
  28. data/lib/axlsx/drawing/line_3D_chart.rb +2 -2
  29. data/lib/axlsx/drawing/line_chart.rb +10 -10
  30. data/lib/axlsx/drawing/line_series.rb +14 -2
  31. data/lib/axlsx/drawing/marker.rb +1 -1
  32. data/lib/axlsx/drawing/num_data.rb +4 -4
  33. data/lib/axlsx/drawing/num_data_source.rb +6 -6
  34. data/lib/axlsx/drawing/num_val.rb +1 -1
  35. data/lib/axlsx/drawing/one_cell_anchor.rb +1 -1
  36. data/lib/axlsx/drawing/pic.rb +2 -3
  37. data/lib/axlsx/drawing/picture_locking.rb +1 -3
  38. data/lib/axlsx/drawing/pie_3D_chart.rb +5 -6
  39. data/lib/axlsx/drawing/pie_series.rb +6 -6
  40. data/lib/axlsx/drawing/scaling.rb +4 -4
  41. data/lib/axlsx/drawing/scatter_chart.rb +10 -10
  42. data/lib/axlsx/drawing/scatter_series.rb +26 -7
  43. data/lib/axlsx/drawing/ser_axis.rb +2 -2
  44. data/lib/axlsx/drawing/series.rb +3 -3
  45. data/lib/axlsx/drawing/series_title.rb +2 -2
  46. data/lib/axlsx/drawing/str_data.rb +3 -3
  47. data/lib/axlsx/drawing/str_val.rb +1 -1
  48. data/lib/axlsx/drawing/title.rb +3 -3
  49. data/lib/axlsx/drawing/val_axis.rb +1 -1
  50. data/lib/axlsx/drawing/vml_drawing.rb +1 -1
  51. data/lib/axlsx/package.rb +39 -28
  52. data/lib/axlsx/rels/relationship.rb +1 -1
  53. data/lib/axlsx/rels/relationships.rb +2 -2
  54. data/lib/axlsx/stylesheet/border_pr.rb +2 -2
  55. data/lib/axlsx/stylesheet/cell_alignment.rb +1 -3
  56. data/lib/axlsx/stylesheet/cell_protection.rb +1 -3
  57. data/lib/axlsx/stylesheet/cell_style.rb +1 -3
  58. data/lib/axlsx/stylesheet/color.rb +1 -3
  59. data/lib/axlsx/stylesheet/font.rb +1 -1
  60. data/lib/axlsx/stylesheet/gradient_stop.rb +1 -1
  61. data/lib/axlsx/stylesheet/num_fmt.rb +1 -3
  62. data/lib/axlsx/stylesheet/pattern_fill.rb +1 -1
  63. data/lib/axlsx/stylesheet/styles.rb +6 -6
  64. data/lib/axlsx/stylesheet/table_style_element.rb +1 -3
  65. data/lib/axlsx/util/accessors.rb +6 -6
  66. data/lib/axlsx/util/constants.rb +106 -101
  67. data/lib/axlsx/util/options_parser.rb +2 -1
  68. data/lib/axlsx/util/parser.rb +4 -4
  69. data/lib/axlsx/util/serialized_attributes.rb +16 -6
  70. data/lib/axlsx/util/simple_typed_list.rb +28 -52
  71. data/lib/axlsx/util/storage.rb +4 -4
  72. data/lib/axlsx/util/string.rb +7 -0
  73. data/lib/axlsx/util/validators.rb +20 -13
  74. data/lib/axlsx/version.rb +1 -1
  75. data/lib/axlsx/workbook/defined_name.rb +11 -12
  76. data/lib/axlsx/workbook/defined_names.rb +2 -2
  77. data/lib/axlsx/workbook/shared_strings_table.rb +5 -5
  78. data/lib/axlsx/workbook/workbook.rb +19 -12
  79. data/lib/axlsx/workbook/workbook_view.rb +78 -0
  80. data/lib/axlsx/workbook/workbook_views.rb +22 -0
  81. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +2 -2
  82. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +1 -3
  83. data/lib/axlsx/workbook/worksheet/break.rb +1 -3
  84. data/lib/axlsx/workbook/worksheet/cell.rb +128 -73
  85. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +50 -40
  86. data/lib/axlsx/workbook/worksheet/cfvo.rb +1 -3
  87. data/lib/axlsx/workbook/worksheet/cfvos.rb +1 -1
  88. data/lib/axlsx/workbook/worksheet/col.rb +7 -10
  89. data/lib/axlsx/workbook/worksheet/col_breaks.rb +2 -2
  90. data/lib/axlsx/workbook/worksheet/comment.rb +5 -6
  91. data/lib/axlsx/workbook/worksheet/comments.rb +9 -12
  92. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +1 -1
  93. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +1 -1
  94. data/lib/axlsx/workbook/worksheet/data_bar.rb +4 -6
  95. data/lib/axlsx/workbook/worksheet/data_validation.rb +6 -4
  96. data/lib/axlsx/workbook/worksheet/dimension.rb +2 -2
  97. data/lib/axlsx/workbook/worksheet/header_footer.rb +6 -8
  98. data/lib/axlsx/workbook/worksheet/icon_set.rb +3 -5
  99. data/lib/axlsx/workbook/worksheet/merged_cells.rb +2 -2
  100. data/lib/axlsx/workbook/worksheet/page_margins.rb +1 -3
  101. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +1 -1
  102. data/lib/axlsx/workbook/worksheet/page_setup.rb +21 -23
  103. data/lib/axlsx/workbook/worksheet/pane.rb +1 -3
  104. data/lib/axlsx/workbook/worksheet/pivot_table.rb +17 -24
  105. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +4 -4
  106. data/lib/axlsx/workbook/worksheet/print_options.rb +1 -3
  107. data/lib/axlsx/workbook/worksheet/protected_range.rb +1 -3
  108. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +1 -1
  109. data/lib/axlsx/workbook/worksheet/rich_text.rb +35 -0
  110. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +254 -0
  111. data/lib/axlsx/workbook/worksheet/row.rb +33 -51
  112. data/lib/axlsx/workbook/worksheet/row_breaks.rb +2 -2
  113. data/lib/axlsx/workbook/worksheet/selection.rb +1 -3
  114. data/lib/axlsx/workbook/worksheet/sheet_data.rb +3 -1
  115. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +1 -3
  116. data/lib/axlsx/workbook/worksheet/table.rb +6 -6
  117. data/lib/axlsx/workbook/worksheet/table_style_info.rb +1 -3
  118. data/lib/axlsx/workbook/worksheet/tables.rb +1 -1
  119. data/lib/axlsx/workbook/worksheet/worksheet.rb +59 -30
  120. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +3 -3
  121. data/test/drawing/tc_axis.rb +27 -0
  122. data/test/drawing/tc_bubble_chart.rb +44 -0
  123. data/test/drawing/tc_bubble_series.rb +21 -0
  124. data/test/drawing/tc_data_source.rb +6 -0
  125. data/test/drawing/tc_line_chart.rb +5 -5
  126. data/test/drawing/tc_line_series.rb +10 -2
  127. data/test/drawing/tc_pic.rb +4 -0
  128. data/test/drawing/tc_scatter_series.rb +25 -1
  129. data/test/tc_helper.rb +1 -1
  130. data/test/tc_package.rb +7 -1
  131. data/test/util/tc_simple_typed_list.rb +1 -2
  132. data/test/workbook/tc_defined_name.rb +12 -4
  133. data/test/workbook/tc_workbook.rb +16 -2
  134. data/test/workbook/tc_workbook_view.rb +50 -0
  135. data/test/workbook/worksheet/auto_filter/tc_filters.rb +1 -1
  136. data/test/workbook/worksheet/tc_break.rb +1 -1
  137. data/test/workbook/worksheet/tc_cell.rb +30 -4
  138. data/test/workbook/worksheet/tc_col.rb +2 -2
  139. data/test/workbook/worksheet/tc_conditional_formatting.rb +2 -2
  140. data/test/workbook/worksheet/tc_data_bar.rb +1 -1
  141. data/test/workbook/worksheet/tc_data_validation.rb +11 -11
  142. data/test/workbook/worksheet/tc_header_footer.rb +2 -2
  143. data/test/workbook/worksheet/tc_icon_set.rb +1 -1
  144. data/test/workbook/worksheet/tc_page_setup.rb +3 -3
  145. data/test/workbook/worksheet/tc_print_options.rb +1 -1
  146. data/test/workbook/worksheet/tc_rich_text.rb +44 -0
  147. data/test/workbook/worksheet/tc_rich_text_run.rb +172 -0
  148. data/test/workbook/worksheet/tc_row.rb +2 -2
  149. data/test/workbook/worksheet/tc_sheet_calc_pr.rb +1 -1
  150. data/test/workbook/worksheet/tc_sheet_format_pr.rb +4 -4
  151. data/test/workbook/worksheet/tc_sheet_protection.rb +5 -5
  152. data/test/workbook/worksheet/tc_sheet_view.rb +4 -4
  153. data/test/workbook/worksheet/tc_worksheet.rb +49 -10
  154. metadata +81 -55
  155. data/test/axlsx.qcachegrind +0 -2226
@@ -15,8 +15,8 @@ module Axlsx
15
15
  # @see WorksheetHyperlink#initialize
16
16
  # @return [WorksheetHyperlink]
17
17
  def add(options)
18
- @list << WorksheetHyperlink.new(@worksheet, options)
19
- @list.last
18
+ self << WorksheetHyperlink.new(@worksheet, options)
19
+ last
20
20
  end
21
21
 
22
22
  # The relationships required by this collection's hyperlinks
@@ -31,7 +31,7 @@ module Axlsx
31
31
  def to_xml_string(str='')
32
32
  return if empty?
33
33
  str << '<hyperlinks>'
34
- @list.each { |hyperlink| hyperlink.to_xml_string(str) }
34
+ each { |hyperlink| hyperlink.to_xml_string(str) }
35
35
  str << '</hyperlinks>'
36
36
  end
37
37
  end
@@ -61,6 +61,33 @@ class TestAxis < Test::Unit::TestCase
61
61
  assert_nothing_raised("accepts valid format code") { @axis.format_code = "00.##" }
62
62
  end
63
63
 
64
+ def create_chart_with_formatting(format_string=nil)
65
+ p = Axlsx::Package.new
66
+ p.workbook.add_worksheet(:name => "Formatting Test") do |sheet|
67
+ sheet.add_row(['test', 20])
68
+ sheet.add_chart(Axlsx::Bar3DChart, :start_at => [0,5], :end_at => [10, 20], :title => "Test Formatting") do |chart|
69
+ chart.add_series :data => sheet["B1:B1"], :labels => sheet["A1:A1"]
70
+ chart.val_axis.format_code = format_string if format_string
71
+ doc = Nokogiri::XML(chart.to_xml_string)
72
+ yield doc
73
+ end
74
+ end
75
+ end
76
+
77
+ def test_format_code_resets_source_linked
78
+ create_chart_with_formatting("#,##0.00") do |doc|
79
+ assert_equal(doc.xpath("//c:valAx/c:numFmt[@formatCode='#,##0.00']").size, 1)
80
+ assert_equal(doc.xpath("//c:valAx/c:numFmt[@sourceLinked='0']").size, 1)
81
+ end
82
+ end
83
+
84
+ def test_no_format_code_keeps_source_linked
85
+ create_chart_with_formatting do |doc|
86
+ assert_equal(doc.xpath("//c:valAx/c:numFmt[@formatCode='General']").size, 1)
87
+ assert_equal(doc.xpath("//c:valAx/c:numFmt[@sourceLinked='1']").size, 1)
88
+ end
89
+ end
90
+
64
91
  def test_crosses
65
92
  assert_raise(ArgumentError, "requires valid crosses") { @axis.crosses = 1 }
66
93
  assert_nothing_raised("accepts valid crosses") { @axis.crosses = :min }
@@ -0,0 +1,44 @@
1
+ require 'tc_helper.rb'
2
+
3
+ class TestBubbleChart < Test::Unit::TestCase
4
+ def setup
5
+ @p = Axlsx::Package.new
6
+ @chart = nil
7
+ @p.workbook.add_worksheet do |sheet|
8
+ sheet.add_row ["First", 1, 5, 7, 9]
9
+ sheet.add_row ["", 1, 25, 49, 81]
10
+ sheet.add_row ["", 1, 42, 60, 75]
11
+ sheet.add_row ["Second", 5, 2, 14, 9]
12
+ sheet.add_row ["", 5, 10, 15, 20]
13
+ sheet.add_row ["", 5, 28, 92, 13]
14
+ sheet.add_chart(Axlsx::BubbleChart, :title => "example: Bubble Chart") do |chart|
15
+ chart.start_at 0, 4
16
+ chart.end_at 10, 19
17
+ chart.add_series :xData => sheet["B1:E1"], :yData => sheet["B2:E2"], :bubbleSize => sheet["B3:E3"], :title => sheet["A1"]
18
+ chart.add_series :xData => sheet["B4:E4"], :yData => sheet["B5:E5"], :bubbleSize => sheet["B6:E6"], :title => sheet["A3"]
19
+ @chart = chart
20
+ end
21
+ end
22
+ end
23
+
24
+ def teardown
25
+ end
26
+
27
+ def test_initialization
28
+ assert_equal(@chart.series_type, Axlsx::BubbleSeries, "series type incorrect")
29
+ assert(@chart.xValAxis.is_a?(Axlsx::ValAxis), "independant value axis not created")
30
+ assert(@chart.yValAxis.is_a?(Axlsx::ValAxis), "dependant value axis not created")
31
+ end
32
+
33
+ def test_to_xml_string
34
+ schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
35
+ doc = Nokogiri::XML(@chart.to_xml_string)
36
+ errors = []
37
+ schema.validate(doc).each do |error|
38
+ errors.push error
39
+ puts error.message
40
+ end
41
+ assert(errors.empty?, "error free validation")
42
+ end
43
+
44
+ end
@@ -0,0 +1,21 @@
1
+ require 'tc_helper.rb'
2
+
3
+ class TestBubbleSeries < Test::Unit::TestCase
4
+
5
+ def setup
6
+ p = Axlsx::Package.new
7
+ @ws = p.workbook.add_worksheet :name=>"hmmm"
8
+ @chart = @ws.add_chart Axlsx::BubbleChart, :title => "Bubble Chart"
9
+ @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :bubbleSize=>[1,5,7], :title=>"GDP", :color => 'FF0000'
10
+ end
11
+
12
+ def test_initialize
13
+ assert_equal(@series.title.text, "GDP", "series title has been applied")
14
+ end
15
+
16
+ def test_to_xml_string
17
+ doc = Nokogiri::XML(@chart.to_xml_string)
18
+ assert_equal(doc.xpath("//a:srgbClr[@val='#{@series.color}']").size,2)
19
+ end
20
+
21
+ end
@@ -6,6 +6,12 @@
6
6
  @data_source = Axlsx::NumDataSource.new :data => ["1", "2", "3"]
7
7
  end
8
8
 
9
+ def test_tag_name
10
+ assert_raise(ArgumentError) { @data_source.tag_name = :zVal }
11
+ assert_nothing_raised { @data_source.tag_name = :yVal }
12
+ assert_nothing_raised { @data_source.tag_name = :bubbleSize }
13
+ end
14
+
9
15
  def test_to_xml_string_strLit
10
16
  str = '<?xml version="1.0" encoding="UTF-8"?>'
11
17
  str << '<c:chartSpace xmlns:c="' << Axlsx::XML_NS_C << '">'
@@ -19,11 +19,11 @@ class TestLineChart < Test::Unit::TestCase
19
19
  assert(@chart.val_axis.is_a?(Axlsx::ValAxis), "value access not created")
20
20
  end
21
21
 
22
- def test_grouping
23
- assert_raise(ArgumentError, "require valid grouping") { @chart.grouping = :inverted }
24
- assert_nothing_raised("allow valid grouping") { @chart.grouping = :stacked }
25
- assert(@chart.grouping == :stacked)
26
- end
22
+ def test_grouping
23
+ assert_raise(ArgumentError, "require valid grouping") { @chart.grouping = :inverted }
24
+ assert_nothing_raised("allow valid grouping") { @chart.grouping = :stacked }
25
+ assert(@chart.grouping == :stacked)
26
+ end
27
27
 
28
28
  def test_to_xml
29
29
  schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
@@ -6,7 +6,7 @@ class TestLineSeries < Test::Unit::TestCase
6
6
  p = Axlsx::Package.new
7
7
  @ws = p.workbook.add_worksheet :name=>"hmmm"
8
8
  chart = @ws.add_chart Axlsx::Line3DChart, :title => "fishery"
9
- @series = chart.add_series :data=>[0,1,2], :labels=>["zero", "one", "two"], :title=>"bob", :color => "#FF0000", :show_marker => true
9
+ @series = chart.add_series :data=>[0,1,2], :labels=>["zero", "one", "two"], :title=>"bob", :color => "#FF0000", :show_marker => true, :smooth => true
10
10
  end
11
11
 
12
12
  def test_initialize
@@ -20,11 +20,19 @@ class TestLineSeries < Test::Unit::TestCase
20
20
  assert_equal(true, @series.show_marker)
21
21
  @series.show_marker = false
22
22
  assert_equal(false, @series.show_marker)
23
- end
23
+ end
24
+
25
+ def test_smooth
26
+ assert_equal(true, @series.smooth)
27
+ @series.smooth = false
28
+ assert_equal(false, @series.smooth)
29
+ end
30
+
24
31
  def test_to_xml_string
25
32
  doc = Nokogiri::XML(@series.to_xml_string)
26
33
  assert(doc.xpath("//srgbClr[@val='#{@series.color}']"))
27
34
  assert(doc.xpath("//marker"))
35
+ assert(doc.xpath("//smooth"))
28
36
  end
29
37
  #TODO serialization testing
30
38
  end
@@ -79,6 +79,10 @@ class TestPic < Test::Unit::TestCase
79
79
 
80
80
  def test_image_src_downcase
81
81
  assert_nothing_raised { @image.image_src = @test_img_up }
82
+ ct = @p.send(:content_types).detect do |t|
83
+ t.respond_to?(:extension) && t.extension.downcase == @image.extname.downcase
84
+ end
85
+ assert_equal("image/jpeg", ct.content_type)
82
86
  end
83
87
 
84
88
  def test_descr
@@ -6,13 +6,37 @@ class TestScatterSeries < Test::Unit::TestCase
6
6
  p = Axlsx::Package.new
7
7
  @ws = p.workbook.add_worksheet :name=>"hmmm"
8
8
  @chart = @ws.add_chart Axlsx::ScatterChart, :title => "Scatter Chart"
9
- @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"exponents", :color => 'FF0000'
9
+ @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"exponents", :color => 'FF0000', :smooth => true
10
10
  end
11
11
 
12
12
  def test_initialize
13
13
  assert_equal(@series.title.text, "exponents", "series title has been applied")
14
14
  end
15
15
 
16
+ def test_smoothed_chart_default_smoothing
17
+ @chart = @ws.add_chart Axlsx::ScatterChart, :title => "Smooth Chart", :scatter_style => :smoothMarker
18
+ @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"smoothed exponents"
19
+ assert(@series.smooth, "series is smooth by default on smooth charts")
20
+ end
21
+
22
+ def test_unsmoothed_chart_default_smoothing
23
+ @chart = @ws.add_chart Axlsx::ScatterChart, :title => "Unsmooth Chart", :scatter_style => :line
24
+ @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"unsmoothed exponents"
25
+ assert(!@series.smooth, "series is not smooth by default on non-smooth charts")
26
+ end
27
+
28
+ def test_explicit_smoothing
29
+ @chart = @ws.add_chart Axlsx::ScatterChart, :title => "Unsmooth Chart, Smooth Series", :scatter_style => :line
30
+ @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"smoothed exponents", :smooth => true
31
+ assert(@series.smooth, "series is smooth when overriding chart default")
32
+ end
33
+
34
+ def test_explicit_unsmoothing
35
+ @chart = @ws.add_chart Axlsx::ScatterChart, :title => "Smooth Chart, Unsmooth Series", :scatter_style => :smoothMarker
36
+ @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"unsmoothed exponents", :smooth => false
37
+ assert(!@series.smooth, "series is not smooth when overriding chart default")
38
+ end
39
+
16
40
  def test_to_xml_string
17
41
  doc = Nokogiri::XML(@chart.to_xml_string)
18
42
  assert_equal(doc.xpath("//a:srgbClr[@val='#{@series.color}']").size,4)
@@ -7,4 +7,4 @@ end
7
7
 
8
8
  require 'test/unit'
9
9
  require "timecop"
10
- require "axlsx.rb"
10
+ require "axlsx.rb"
@@ -11,6 +11,7 @@ class TestPackage < Test::Unit::TestCase
11
11
  ws.outline_level_columns 0, 1
12
12
  ws.add_hyperlink :ref => ws.rows.first.cells.last, :location => 'https://github.com/randym'
13
13
  ws.workbook.add_defined_name("#{ws.name}!A1:C2", :name => '_xlnm.Print_Titles', :hidden => true)
14
+ ws.workbook.add_view active_tab: 1, first_sheet: 0
14
15
  ws.protect_range('A1:C1')
15
16
  ws.protect_range(ws.rows.last.cells)
16
17
  ws.add_comment :author => 'alice', :text => 'Hi Bob', :ref => 'A12'
@@ -52,6 +53,11 @@ class TestPackage < Test::Unit::TestCase
52
53
  chart.d_lbls.show_val = true
53
54
  end
54
55
 
56
+ ws.add_chart(Axlsx::BubbleChart, :title => 'bubble chart') do |chart|
57
+ chart.add_series :xData => [1,2,3,4], :yData => [1,3,2,4]
58
+ chart.d_lbls.show_val = true
59
+ end
60
+
55
61
  @fname = 'axlsx_test_serialization.xlsx'
56
62
  img = File.expand_path('../../examples/image1.jpeg', __FILE__)
57
63
  ws.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image|
@@ -176,7 +182,7 @@ class TestPackage < Test::Unit::TestCase
176
182
 
177
183
 
178
184
  #no mystery parts
179
- assert_equal(24, p.size)
185
+ assert_equal(25, p.size)
180
186
 
181
187
  end
182
188
 
@@ -72,7 +72,6 @@ class TestSimpleTypedList < Test::Unit::TestCase
72
72
  def test_equality
73
73
  @list.push 1
74
74
  @list.push 2
75
- assert_equal(@list, [1,2])
76
-
75
+ assert_equal(@list.to_ary, [1,2])
77
76
  end
78
77
  end
@@ -1,14 +1,14 @@
1
1
  require 'tc_helper'
2
2
 
3
3
  class TestDefinedNames < Test::Unit::TestCase
4
- def setup
4
+ def setup
5
5
  @dn = Axlsx::DefinedName.new('Sheet1!A1:A1')
6
6
  end
7
7
 
8
8
  def test_initialize
9
9
  assert_equal('Sheet1!A1:A1', @dn.formula)
10
10
  end
11
-
11
+
12
12
  def test_string_attributes
13
13
  %w(short_cut_key status_bar help description custom_menu comment).each do |attr|
14
14
  assert_raise(ArgumentError, 'only strings allowed in string attributes') { @dn.send("#{attr}=", 1) }
@@ -29,13 +29,21 @@ class TestDefinedNames < Test::Unit::TestCase
29
29
  assert_nothing_raised { @dn.local_sheet_id = 1 }
30
30
  end
31
31
 
32
+ def test_do_not_camelcase_value_for_name
33
+ @dn.name = '_xlnm._FilterDatabase'
34
+ doc = Nokogiri::XML(@dn.to_xml_string)
35
+ assert_equal(doc.xpath("//definedName[@name='_xlnm._FilterDatabase']").size, 1)
36
+ assert_equal('Sheet1!A1:A1', doc.xpath('//definedName').text)
37
+ end
38
+
32
39
  def test_to_xml_string
33
40
  assert_raise(ArgumentError, 'name is required for serialization') { @dn.to_xml_string }
34
41
  @dn.name = '_xlnm.Print_Titles'
35
42
  @dn.hidden = true
36
43
  doc = Nokogiri::XML(@dn.to_xml_string)
37
- assert(doc.xpath("//definedName[@name='_xlnm.Print_Titles']"))
38
- assert(doc.xpath("//definedName[@hidden='true']"))
44
+ assert_equal(doc.xpath("//definedName[@name='_xlnm.Print_Titles']").size, 1)
45
+ assert_equal(doc.xpath("//definedName[@hidden='1']").size, 1)
39
46
  assert_equal('Sheet1!A1:A1', doc.xpath('//definedName').text)
40
47
  end
48
+
41
49
  end
@@ -38,7 +38,7 @@ class TestWorkbook < Test::Unit::TestCase
38
38
  @wb.add_worksheet(:name=>'foo')
39
39
  @wb.add_worksheet(:name=>'bar')
40
40
  assert_equal('foo', @wb.sheet_by_name('foo').name)
41
-
41
+
42
42
  end
43
43
  def test_date1904
44
44
  assert_equal(Axlsx::Workbook.date1904, @wb.date1904)
@@ -53,6 +53,11 @@ class TestWorkbook < Test::Unit::TestCase
53
53
  assert_equal(1, @wb.defined_names.size)
54
54
  end
55
55
 
56
+ def test_add_view
57
+ @wb.add_view visibility: :hidden, window_width: 800
58
+ assert_equal(1, @wb.views.size)
59
+ end
60
+
56
61
  def test_shared_strings
57
62
  assert_equal(@wb.use_shared_strings, nil)
58
63
  assert_raise(ArgumentError) {@wb.use_shared_strings = 'bpb'}
@@ -66,7 +71,7 @@ class TestWorkbook < Test::Unit::TestCase
66
71
  assert_equal(@wb.worksheets.first, ws, "the worksheet returned is the worksheet added")
67
72
  assert_equal(ws.name, "bob", "name option gets passed to worksheet")
68
73
  end
69
-
74
+
70
75
  def test_insert_worksheet
71
76
  @wb.add_worksheet(:name => 'A')
72
77
  @wb.add_worksheet(:name => 'B')
@@ -116,6 +121,15 @@ class TestWorkbook < Test::Unit::TestCase
116
121
  assert_equal(doc.xpath('//xmlns:workbook/xmlns:definedNames/xmlns:definedName').inner_text, @wb.worksheets[0].auto_filter.defined_name)
117
122
  end
118
123
 
124
+ def test_to_xml_string_book_views
125
+ @wb.add_worksheet do |sheet|
126
+ sheet.add_row [1, "two"]
127
+ end
128
+ @wb.add_view active_tab: 0, first_sheet: 0
129
+ doc = Nokogiri::XML(@wb.to_xml_string)
130
+ assert_equal(1, doc.xpath('//xmlns:workbook/xmlns:bookViews/xmlns:workbookView[@activeTab=0]').size)
131
+ end
132
+
119
133
  def test_to_xml_uses_correct_rIds_for_pivotCache
120
134
  ws = @wb.add_worksheet
121
135
  pivot_table = ws.add_pivot_table('G5:G6', 'A1:D5')
@@ -0,0 +1,50 @@
1
+ require 'tc_helper'
2
+
3
+ class TestWorkbookView < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @options = { visibility: :hidden, minimized: true, show_horizontal_scroll: true, show_vertical_scroll: true,
7
+ show_sheet_tabs: true, tab_ratio: 750, first_sheet: 0, active_tab: 1, x_window: 500, y_window: 400,
8
+ window_width: 800, window_height: 600, auto_filter_date_grouping: true }
9
+ @book_view = Axlsx::WorkbookView.new @options
10
+ end
11
+
12
+ def test_options_assignation
13
+ @options.each do |key, value|
14
+ assert_equal(value, @book_view.send(key))
15
+ end
16
+ end
17
+
18
+ def test_boolean_attribute_validation
19
+ %w(minimized show_horizontal_scroll show_vertical_scroll show_sheet_tabs auto_filter_date_grouping).each do |attr|
20
+ assert_raise(ArgumentError, 'only booleanish allowed in boolean attributes') { @book_view.send("#{attr}=", "banana") }
21
+ assert_nothing_raised { @book_view.send("#{attr}=", false )}
22
+ end
23
+ end
24
+
25
+ def test_integer_attribute_validation
26
+ %w(tab_ratio first_sheet active_tab x_window y_window window_width window_height).each do |attr|
27
+ assert_raise(ArgumentError, 'only integer allowed in integer attributes') { @book_view.send("#{attr}=", "b") }
28
+ assert_nothing_raised { @book_view.send("#{attr}=", 7 )}
29
+ end
30
+ end
31
+
32
+ def test_visibility_attribute_validation
33
+ assert_raise(ArgumentError) { @book_view.visibility = :foobar }
34
+ assert_nothing_raised { @book_view.visibility = :hidden }
35
+ assert_nothing_raised { @book_view.visibility = :very_hidden }
36
+ assert_nothing_raised { @book_view.visibility = :visible }
37
+ end
38
+
39
+ def test_to_xml_string
40
+ xml = @book_view.to_xml_string
41
+ doc = Nokogiri::XML(xml)
42
+ @options.each do |key, value|
43
+ if value == true || value == false
44
+ value = value ? 1 : 0
45
+ end
46
+ path = "workbookView[@#{Axlsx.camel(key, false)}='#{value}']"
47
+ assert_equal(1, doc.xpath(path).size)
48
+ end
49
+ end
50
+ end
@@ -44,7 +44,7 @@ class TestFilters < Test::Unit::TestCase
44
44
 
45
45
  def test_to_xml_string
46
46
  doc = Nokogiri::XML(@filters.to_xml_string)
47
- assert_equal(1, doc.xpath('//filters[@blank="true"]').size)
47
+ assert_equal(1, doc.xpath('//filters[@blank=1]').size)
48
48
  end
49
49
  end
50
50
 
@@ -44,6 +44,6 @@ class TestBreak < Test::Unit::TestCase
44
44
 
45
45
  def test_to_xml_string
46
46
  doc = Nokogiri::XML(@break.to_xml_string)
47
- assert_equal(doc.xpath('//brk[@id="1"][@min="1"][@max="10"][@pt="false"][@man="true"]').size, 1)
47
+ assert_equal(doc.xpath('//brk[@id="1"][@min="1"][@max="10"][@pt=0][@man=1]').size, 1)
48
48
  end
49
49
  end
@@ -34,7 +34,7 @@ class TestCell < Test::Unit::TestCase
34
34
  end
35
35
 
36
36
  def test_pos
37
- assert_equal(@c.pos, [@c.index, @c.row.index])
37
+ assert_equal(@c.pos, [@c.index, @c.row.index(@c)])
38
38
  end
39
39
 
40
40
  def test_r
@@ -50,6 +50,12 @@ class TestCell < Test::Unit::TestCase
50
50
  assert_equal(@cAA.r_abs,"$AA$2", "needs to accept multi-digit columns")
51
51
  end
52
52
 
53
+ def test_name
54
+ @c.name = 'foo'
55
+ assert_equal(1, @ws.workbook.defined_names.size)
56
+ assert_equal('foo', @ws.workbook.defined_names.last.name)
57
+ end
58
+
53
59
  def test_style
54
60
  assert_raise(ArgumentError, "must reject invalid style indexes") { @c.style=@c.row.worksheet.workbook.styles.cellXfs.size }
55
61
  assert_nothing_raised("must allow valid style index changes") {@c.style=1}
@@ -89,6 +95,7 @@ class TestCell < Test::Unit::TestCase
89
95
  assert_equal(@c.send(:cell_type_from_value, true), :boolean)
90
96
  assert_equal(@c.send(:cell_type_from_value, false), :boolean)
91
97
  assert_equal(@c.send(:cell_type_from_value, 1.0/10**6), :float)
98
+ assert_equal(@c.send(:cell_type_from_value, Axlsx::RichText.new), :richtext)
92
99
  assert_equal(:iso_8601, @c.send(:cell_type_from_value, '2008-08-30T01:45:36.123+09:00'))
93
100
  end
94
101
 
@@ -101,6 +108,8 @@ class TestCell < Test::Unit::TestCase
101
108
  assert_equal(@c.send(:cast_value, "1.0"), 1.0)
102
109
  @c.type = :string
103
110
  assert_equal(@c.send(:cast_value, nil), nil)
111
+ @c.type = :richtext
112
+ assert_equal(@c.send(:cast_value, nil), nil)
104
113
  @c.type = :float
105
114
  assert_equal(@c.send(:cast_value, nil), nil)
106
115
  @c.type = :boolean
@@ -216,6 +225,13 @@ class TestCell < Test::Unit::TestCase
216
225
  @c.merge @row.cells.last
217
226
  assert_equal(@c.row.worksheet.send(:merged_cells).last, "A1:C1")
218
227
  end
228
+
229
+ def test_reverse_merge_with_cell
230
+ @c.row.add_cell 2
231
+ @c.row.add_cell 3
232
+ @row.cells.last.merge @c
233
+ assert_equal(@c.row.worksheet.send(:merged_cells).last, "A1:C1")
234
+ end
219
235
 
220
236
  def test_ssti
221
237
  assert_raise(ArgumentError, "ssti must be an unsigned integer!") { @c.send(:ssti=, -1) }
@@ -278,6 +294,18 @@ class TestCell < Test::Unit::TestCase
278
294
 
279
295
  end
280
296
 
297
+ def test_to_xml_string_array_formula
298
+ p = Axlsx::Package.new
299
+ ws = p.workbook.add_worksheet do |sheet|
300
+ sheet.add_row ["{=SUM(C2:C11*D2:D11)}"]
301
+ end
302
+ doc = Nokogiri::XML(ws.to_xml_string)
303
+ doc.remove_namespaces!
304
+ assert(doc.xpath("//f[text()='SUM(C2:C11*D2:D11)']"))
305
+ assert(doc.xpath("//f[@t='array']"))
306
+ assert(doc.xpath("//f[@ref='A1']"))
307
+ end
308
+
281
309
  def test_font_size_with_custom_style_and_no_sz
282
310
  @c.style = @c.row.worksheet.workbook.styles.add_style :bg_color => 'FF00FF'
283
311
  sz = @c.send(:font_size)
@@ -295,11 +323,11 @@ class TestCell < Test::Unit::TestCase
295
323
  assert_equal(sz, 52)
296
324
  end
297
325
 
298
-
299
326
  def test_cell_with_sz
300
327
  @c.sz = 25
301
328
  assert_equal(25, @c.send(:font_size))
302
329
  end
330
+
303
331
  def test_to_xml
304
332
  # TODO This could use some much more stringent testing related to the xml content generated!
305
333
  @ws.add_row [Time.now, Date.today, true, 1, 1.0, "text", "=sum(A1:A2)", "2013-01-13T13:31:25.123"]
@@ -313,7 +341,5 @@ class TestCell < Test::Unit::TestCase
313
341
  puts error.message
314
342
  end
315
343
  assert(errors.empty?, "error free validation")
316
-
317
344
  end
318
-
319
345
  end