axlsx 1.0.15 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. data/.yardopts +1 -0
  2. data/CHANGELOG.md +40 -2
  3. data/README.md +223 -92
  4. data/examples/example.csv +1000 -0
  5. data/examples/example.rb +266 -132
  6. data/examples/example.xlsx +0 -0
  7. data/examples/example_streamed.xlsx +0 -0
  8. data/examples/no-use_autowidth.xlsx +0 -0
  9. data/examples/shared_strings_example.xlsx +0 -0
  10. data/lib/axlsx/content_type/content_type.rb +13 -12
  11. data/lib/axlsx/content_type/default.rb +10 -6
  12. data/lib/axlsx/content_type/override.rb +13 -8
  13. data/lib/axlsx/doc_props/app.rb +38 -41
  14. data/lib/axlsx/doc_props/core.rb +13 -17
  15. data/lib/axlsx/drawing/axis.rb +39 -19
  16. data/lib/axlsx/drawing/bar_3D_chart.rb +34 -32
  17. data/lib/axlsx/drawing/bar_series.rb +14 -14
  18. data/lib/axlsx/drawing/cat_axis.rb +16 -14
  19. data/lib/axlsx/drawing/cat_axis_data.rb +17 -18
  20. data/lib/axlsx/drawing/chart.rb +40 -41
  21. data/lib/axlsx/drawing/drawing.rb +27 -12
  22. data/lib/axlsx/drawing/graphic_frame.rb +22 -21
  23. data/lib/axlsx/drawing/hlink_click.rb~ +0 -0
  24. data/lib/axlsx/drawing/hyperlink.rb +96 -0
  25. data/lib/axlsx/drawing/hyperlink.rb~ +64 -0
  26. data/lib/axlsx/drawing/line_3D_chart.rb +31 -28
  27. data/lib/axlsx/drawing/line_series.rb +12 -11
  28. data/lib/axlsx/drawing/marker.rb +11 -8
  29. data/lib/axlsx/drawing/named_axis_data.rb +36 -0
  30. data/lib/axlsx/drawing/one_cell_anchor.rb +18 -16
  31. data/lib/axlsx/drawing/pic.rb +47 -33
  32. data/lib/axlsx/drawing/picture_locking.rb +22 -18
  33. data/lib/axlsx/drawing/pie_3D_chart.rb +11 -8
  34. data/lib/axlsx/drawing/pie_series.rb +16 -12
  35. data/lib/axlsx/drawing/scaling.rb +11 -10
  36. data/lib/axlsx/drawing/scatter_chart.rb +69 -0
  37. data/lib/axlsx/drawing/scatter_series.rb +39 -0
  38. data/lib/axlsx/drawing/ser_axis.rb +11 -10
  39. data/lib/axlsx/drawing/series.rb +16 -15
  40. data/lib/axlsx/drawing/series_title.rb +15 -14
  41. data/lib/axlsx/drawing/title.rb +27 -26
  42. data/lib/axlsx/drawing/two_cell_anchor.rb +19 -20
  43. data/lib/axlsx/drawing/val_axis.rb +9 -7
  44. data/lib/axlsx/drawing/val_axis_data.rb +18 -17
  45. data/lib/axlsx/drawing/view_3D.rb +23 -20
  46. data/lib/axlsx/package.rb +117 -52
  47. data/lib/axlsx/rels/relationship.rb +27 -8
  48. data/lib/axlsx/rels/relationships.rb +9 -2
  49. data/lib/axlsx/stylesheet/#num_fmt.rb# +69 -0
  50. data/lib/axlsx/stylesheet/border.rb +28 -23
  51. data/lib/axlsx/stylesheet/border_pr.rb +17 -15
  52. data/lib/axlsx/stylesheet/cell_alignment.rb +24 -21
  53. data/lib/axlsx/stylesheet/cell_protection.rb +11 -7
  54. data/lib/axlsx/stylesheet/cell_style.rb +9 -5
  55. data/lib/axlsx/stylesheet/color.rb +21 -14
  56. data/lib/axlsx/stylesheet/fill.rb +8 -5
  57. data/lib/axlsx/stylesheet/font.rb +22 -14
  58. data/lib/axlsx/stylesheet/gradient_fill.rb +20 -17
  59. data/lib/axlsx/stylesheet/gradient_stop.rb +10 -6
  60. data/lib/axlsx/stylesheet/num_fmt.rb +13 -6
  61. data/lib/axlsx/stylesheet/pattern_fill.rb +26 -10
  62. data/lib/axlsx/stylesheet/styles.rb +53 -41
  63. data/lib/axlsx/stylesheet/table_style.rb +10 -4
  64. data/lib/axlsx/stylesheet/table_style_element.rb +11 -7
  65. data/lib/axlsx/stylesheet/table_styles.rb +12 -8
  66. data/lib/axlsx/stylesheet/xf.rb +30 -25
  67. data/lib/axlsx/util/cbf.rb +69 -33
  68. data/lib/axlsx/util/constants.rb +39 -20
  69. data/lib/axlsx/util/ms_off_crypto.rb +10 -10
  70. data/lib/axlsx/util/parser.rb +1 -0
  71. data/lib/axlsx/util/simple_typed_list.rb +20 -10
  72. data/lib/axlsx/util/storage.rb +1 -1
  73. data/lib/axlsx/util/validators.rb +23 -7
  74. data/lib/axlsx/version.rb +5 -2
  75. data/lib/axlsx/workbook/shared_strings_table.rb +69 -0
  76. data/lib/axlsx/workbook/shared_strings_table.rb~ +69 -0
  77. data/lib/axlsx/workbook/workbook.rb +82 -26
  78. data/lib/axlsx/workbook/worksheet/cell.rb +172 -117
  79. data/lib/axlsx/workbook/worksheet/col.rb +114 -0
  80. data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
  81. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +29 -0
  82. data/lib/axlsx/workbook/worksheet/page_margins.rb +97 -0
  83. data/lib/axlsx/workbook/worksheet/row.rb +53 -21
  84. data/lib/axlsx/workbook/worksheet/shared_strings_table.rb~ +0 -0
  85. data/lib/axlsx/workbook/worksheet/table.rb +96 -0
  86. data/lib/axlsx/workbook/worksheet/table.rb~ +97 -0
  87. data/lib/axlsx/workbook/worksheet/worksheet.rb +270 -121
  88. data/lib/axlsx.rb +41 -14
  89. data/lib/schema/dc.xsd +5 -5
  90. data/lib/schema/dcmitype.xsd +5 -3
  91. data/lib/schema/dcterms.xsd +15 -15
  92. data/lib/schema/opc-coreProperties.xsd +6 -2
  93. data/lib/schema/xml.xsd +7 -8
  94. data/test/#benchmark.txt# +7 -0
  95. data/test/#tc_helper.rb# +3 -0
  96. data/test/benchmark.rb +81 -0
  97. data/test/benchmark.rb~ +0 -0
  98. data/test/benchmark.txt +6 -0
  99. data/test/benchmark.txt~ +6 -0
  100. data/test/content_type/tc_content_type.rb +31 -31
  101. data/test/content_type/tc_default.rb +9 -22
  102. data/test/content_type/tc_override.rb +8 -21
  103. data/test/doc_props/tc_app.rb +2 -8
  104. data/test/doc_props/tc_core.rb +6 -7
  105. data/test/drawing/tc_axis.rb +7 -3
  106. data/test/drawing/tc_bar_3D_chart.rb +6 -7
  107. data/test/drawing/tc_bar_series.rb +4 -5
  108. data/test/drawing/tc_cat_axis.rb +2 -3
  109. data/test/drawing/tc_cat_axis_data.rb +2 -3
  110. data/test/drawing/tc_chart.rb +13 -14
  111. data/test/drawing/tc_drawing.rb +7 -8
  112. data/test/drawing/tc_graphic_frame.rb +3 -4
  113. data/test/drawing/tc_hyperlink.rb +69 -0
  114. data/test/drawing/tc_line_3d_chart.rb +5 -6
  115. data/test/drawing/tc_line_series.rb +3 -4
  116. data/test/drawing/tc_marker.rb +3 -4
  117. data/test/drawing/tc_one_cell_anchor.rb +6 -7
  118. data/test/drawing/tc_pic.rb +13 -8
  119. data/test/drawing/tc_picture_locking.rb +2 -3
  120. data/test/drawing/tc_pie_3D_chart.rb +5 -6
  121. data/test/drawing/tc_pie_series.rb +4 -5
  122. data/test/drawing/tc_scaling.rb +3 -4
  123. data/test/drawing/tc_scatter_chart.rb +43 -0
  124. data/test/drawing/tc_scatter_series.rb +20 -0
  125. data/test/drawing/tc_ser_axis.rb +2 -3
  126. data/test/drawing/tc_series.rb +4 -5
  127. data/test/drawing/tc_series_title.rb +4 -5
  128. data/test/drawing/tc_title.rb +4 -5
  129. data/test/drawing/tc_two_cell_anchor.rb +4 -5
  130. data/test/drawing/tc_val_axis.rb +2 -3
  131. data/test/drawing/tc_val_axis_data.rb +2 -3
  132. data/test/drawing/tc_view_3D.rb +6 -7
  133. data/test/example.csv +1000 -0
  134. data/test/example.xlsx +0 -0
  135. data/test/example_streamed.xlsx +0 -0
  136. data/test/profile.rb +33 -0
  137. data/test/rels/tc_relationship.rb +10 -6
  138. data/test/rels/tc_relationships.rb +4 -5
  139. data/test/stylesheet/tc_border.rb +3 -4
  140. data/test/stylesheet/tc_border_pr.rb +3 -4
  141. data/test/stylesheet/tc_cell_alignment.rb +10 -6
  142. data/test/stylesheet/tc_cell_protection.rb +2 -3
  143. data/test/stylesheet/tc_cell_style.rb +2 -3
  144. data/test/stylesheet/tc_color.rb +2 -3
  145. data/test/stylesheet/tc_fill.rb +1 -2
  146. data/test/stylesheet/tc_font.rb +12 -5
  147. data/test/stylesheet/tc_gradient_fill.rb +1 -2
  148. data/test/stylesheet/tc_gradient_stop.rb +1 -2
  149. data/test/stylesheet/tc_num_fmt.rb +1 -2
  150. data/test/stylesheet/tc_pattern_fill.rb +3 -4
  151. data/test/stylesheet/tc_styles.rb +16 -6
  152. data/test/stylesheet/tc_table_style.rb +2 -3
  153. data/test/stylesheet/tc_table_style_element.rb +2 -3
  154. data/test/stylesheet/tc_table_styles.rb +3 -4
  155. data/test/stylesheet/tc_xf.rb +16 -17
  156. data/test/tc_axlsx.rb +39 -0
  157. data/test/tc_axlsx.rb~ +0 -0
  158. data/test/tc_helper.rb +3 -0
  159. data/test/tc_helper.rb~ +3 -0
  160. data/test/tc_package.rb +43 -9
  161. data/test/util/tc_simple_typed_list.rb +8 -9
  162. data/test/util/tc_validators.rb +7 -8
  163. data/test/workbook/tc_shared_strings_table.rb +38 -0
  164. data/test/workbook/tc_workbook.rb +32 -6
  165. data/test/workbook/worksheet/table/tc_table.rb +71 -0
  166. data/test/workbook/worksheet/table/tc_table.rb~ +72 -0
  167. data/test/workbook/worksheet/tc_cell.rb +70 -13
  168. data/test/workbook/worksheet/tc_col.rb +59 -0
  169. data/test/workbook/worksheet/tc_col.rb~ +10 -0
  170. data/test/workbook/worksheet/tc_date_time_converter.rb +126 -0
  171. data/test/workbook/worksheet/tc_page_margins.rb +97 -0
  172. data/test/workbook/worksheet/tc_row.rb +54 -4
  173. data/test/workbook/worksheet/tc_worksheet.rb +198 -31
  174. metadata +167 -111
  175. data/test/drawing/tc_line_series.tc~ +0 -34
  176. data/test/drawing/tc_picture_locking.rb~ +0 -77
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestChart < Test::Unit::TestCase
5
4
 
@@ -16,7 +15,7 @@ class TestChart < Test::Unit::TestCase
16
15
  def test_initialization
17
16
  assert_equal(@p.workbook.charts.last,@chart, "the chart is in the workbook")
18
17
  assert_equal(@chart.title.text, "fishery", "the title option has been applied")
19
- assert((@chart.series.is_a?(Axlsx::SimpleTypedList) && @chart.series.empty?), "The series is initialized and empty")
18
+ assert((@chart.series.is_a?(Axlsx::SimpleTypedList) && @chart.series.empty?), "The series is initialized and empty")
20
19
  end
21
20
 
22
21
  def test_title
@@ -41,33 +40,33 @@ class TestChart < Test::Unit::TestCase
41
40
 
42
41
  end
43
42
 
44
- def end_at
43
+ def test_end_at
45
44
  @chart.end_at 25, 90
46
- assert_equal(@chart.graphic_frame.anchor.from.col, 25)
45
+ assert_equal(@chart.graphic_frame.anchor.to.col, 25)
47
46
  assert_equal(@chart.graphic_frame.anchor.to.row, 90)
48
47
  end
49
48
 
50
- def test_add_series
49
+ def test_add_series
51
50
  s = @chart.add_series :data=>[0,1,2,3], :labels => ["one", 1, "anything"], :title=>"bob"
52
51
  assert_equal(@chart.series.last, s, "series has been added to chart series collection")
53
52
  assert_equal(s.title.text, "bob", "series title has been applied")
54
53
  assert_equal(s.data, [0,1,2,3], "data option applied")
55
- assert_equal(s.labels, ["one",1,"anything"], "labels option applied")
56
- end
57
-
54
+ assert_equal(s.labels, ["one",1,"anything"], "labels option applied")
55
+ end
56
+
58
57
  def test_pn
59
58
  assert_equal(@chart.pn, "charts/chart1.xml")
60
59
  end
61
-
62
- def test_to_xml
60
+
61
+ def test_to_xml_string
63
62
  schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
64
- doc = Nokogiri::XML(@chart.to_xml)
63
+ doc = Nokogiri::XML(@chart.to_xml_string)
65
64
  errors = []
66
65
  schema.validate(doc).each do |error|
67
66
  errors.push error
68
67
  puts error.message
69
68
  end
70
69
  assert(errors.empty?, "error free validation")
71
- end
72
-
70
+ end
71
+
73
72
  end
@@ -1,8 +1,7 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestDrawing < Test::Unit::TestCase
5
- def setup
4
+ def setup
6
5
  p = Axlsx::Package.new
7
6
  @ws = p.workbook.add_worksheet
8
7
 
@@ -24,14 +23,14 @@ class TestDrawing < Test::Unit::TestCase
24
23
  assert_equal([anchor.to.row, anchor.to.col], [1,1], "options for start at are applied")
25
24
  assert_equal(chart.title.text, "bob", "option for title is applied")
26
25
  end
27
-
26
+
28
27
  def test_add_image
29
28
  src = File.dirname(__FILE__) + "/../../examples/image1.jpeg"
30
29
  image = @ws.add_image(:image_src => src, :start_at=>[0,0], :width=>600, :height=>400)
31
30
  assert(@ws.drawing.anchors.last.is_a?(Axlsx::OneCellAnchor))
32
31
  assert(image.is_a?(Axlsx::Pic))
33
32
  assert_equal(600, image.width)
34
- assert_equal(400, image.height)
33
+ assert_equal(400, image.height)
35
34
  end
36
35
 
37
36
  def test_charts
@@ -39,7 +38,7 @@ class TestDrawing < Test::Unit::TestCase
39
38
  chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"bob", :start_at=>[0,0], :end_at=>[1,1])
40
39
  assert_equal(@ws.drawing.charts.last, chart, "add chart is returned")
41
40
  chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"nancy", :start_at=>[1,5], :end_at=>[5,10])
42
- assert_equal(@ws.drawing.charts.last, chart, "add chart is returned")
41
+ assert_equal(@ws.drawing.charts.last, chart, "add chart is returned")
43
42
  end
44
43
 
45
44
  def test_pn
@@ -53,7 +52,7 @@ class TestDrawing < Test::Unit::TestCase
53
52
  def test_rId
54
53
  assert_equal(@ws.drawing.rId, "rId1")
55
54
  end
56
-
55
+
57
56
  def test_index
58
57
  assert_equal(@ws.drawing.index, @ws.workbook.drawings.index(@ws.drawing))
59
58
  end
@@ -68,7 +67,7 @@ class TestDrawing < Test::Unit::TestCase
68
67
 
69
68
  def test_to_xml
70
69
  schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
71
- doc = Nokogiri::XML(@ws.drawing.to_xml)
70
+ doc = Nokogiri::XML(@ws.drawing.to_xml_string)
72
71
  errors = []
73
72
  schema.validate(doc).each do |error|
74
73
  errors.push error
@@ -1,8 +1,7 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestGraphicFrame < Test::Unit::TestCase
5
- def setup
4
+ def setup
6
5
  p = Axlsx::Package.new
7
6
  @ws = p.workbook.add_worksheet
8
7
  @chart = @ws.add_chart Axlsx::Chart
@@ -20,7 +19,7 @@ class TestGraphicFrame < Test::Unit::TestCase
20
19
  def test_rId
21
20
  assert_equal(@frame.rId, "rId1")
22
21
  chart = @ws.add_chart Axlsx::Chart
23
- assert_equal(chart.graphic_frame.rId, "rId2")
22
+ assert_equal(chart.graphic_frame.rId, "rId2")
24
23
  end
25
24
 
26
25
  end
@@ -0,0 +1,69 @@
1
+ require 'tc_helper.rb'
2
+
3
+ class TestHyperlink < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @p = Axlsx::Package.new
7
+ ws = @p.workbook.add_worksheet
8
+ @test_img = File.dirname(__FILE__) + "/../../examples/image1.jpeg"
9
+ @image = ws.add_image :image_src => @test_img, :hyperlink => "http://axlsx.blogspot.com"
10
+ @hyperlink = @image.hyperlink
11
+ end
12
+
13
+ def teardown
14
+ end
15
+
16
+
17
+ def test_href
18
+ assert_nothing_raised { @hyperlink.href = "http://axlsx.blogspot.com" }
19
+ assert_equal(@hyperlink.href, "http://axlsx.blogspot.com")
20
+ end
21
+
22
+ def test_invalidUrl
23
+ assert_nothing_raised { @hyperlink.invalidUrl = "http://axlsx.blogspot.com" }
24
+ assert_equal(@hyperlink.invalidUrl, "http://axlsx.blogspot.com")
25
+ end
26
+
27
+ def test_tgtFrame
28
+ assert_nothing_raised { @hyperlink.tgtFrame = "http://axlsx.blogspot.com" }
29
+ assert_equal(@hyperlink.tgtFrame, "http://axlsx.blogspot.com")
30
+ end
31
+
32
+ def test_tooltip
33
+ assert_nothing_raised { @hyperlink.tooltip = "http://axlsx.blogspot.com" }
34
+ assert_equal(@hyperlink.tooltip, "http://axlsx.blogspot.com")
35
+ end
36
+
37
+ def test_invalidUrl
38
+ assert_nothing_raised { @hyperlink.invalidUrl = "http://axlsx.blogspot.com" }
39
+ assert_equal(@hyperlink.invalidUrl, "http://axlsx.blogspot.com")
40
+ end
41
+
42
+ def test_action
43
+ assert_nothing_raised { @hyperlink.action = "flee" }
44
+ assert_equal(@hyperlink.action, "flee")
45
+ end
46
+
47
+ def test_endSnd
48
+ assert_nothing_raised { @hyperlink.endSnd = "true" }
49
+ assert_raise(ArgumentError) {@hyperlink.endSnd = "bob"}
50
+ assert_equal(@hyperlink.endSnd, "true")
51
+ end
52
+
53
+ def test_highlightClick
54
+ assert_nothing_raised { @hyperlink.highlightClick = false }
55
+ assert_raise(ArgumentError) {@hyperlink.highlightClick = "bob"}
56
+ assert_equal(@hyperlink.highlightClick, false )
57
+ end
58
+
59
+ def test_id
60
+ assert_equal(@hyperlink.send(:id), 2)
61
+ end
62
+
63
+ def test_history
64
+ assert_nothing_raised { @hyperlink.history = false }
65
+ assert_raise(ArgumentError) {@hyperlink.history = "bob"}
66
+ assert_equal(@hyperlink.history, false )
67
+ end
68
+
69
+ end
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestLine3DChart < Test::Unit::TestCase
5
4
 
@@ -13,7 +12,7 @@ class TestLine3DChart < Test::Unit::TestCase
13
12
  def teardown
14
13
  end
15
14
 
16
- def test_initialization
15
+ def test_initialization
17
16
  assert_equal(@chart.grouping, :standard, "grouping defualt incorrect")
18
17
  assert_equal(@chart.series_type, Axlsx::LineSeries, "series type incorrect")
19
18
  assert(@chart.catAxis.is_a?(Axlsx::CatAxis), "category axis not created")
@@ -36,13 +35,13 @@ class TestLine3DChart < Test::Unit::TestCase
36
35
 
37
36
  def test_to_xml
38
37
  schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
39
- doc = Nokogiri::XML(@chart.to_xml)
38
+ doc = Nokogiri::XML(@chart.to_xml_string)
40
39
  errors = []
41
40
  schema.validate(doc).each do |error|
42
41
  errors.push error
43
42
  puts error.message
44
43
  end
45
44
  assert(errors.empty?, "error free validation")
46
- end
47
-
45
+ end
46
+
48
47
  end
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestLineSeries < Test::Unit::TestCase
5
4
 
@@ -9,11 +8,11 @@ class TestLineSeries < Test::Unit::TestCase
9
8
  chart = @ws.drawing.add_chart Axlsx::Line3DChart, :title => "fishery"
10
9
  @series = chart.add_series :data=>[0,1,2], :labels=>["zero", "one", "two"], :title=>"bob"
11
10
  end
12
-
11
+
13
12
  def test_initialize
14
13
  assert_equal(@series.title.text, "bob", "series title has been applied")
15
14
  assert_equal(@series.data, [0,1,2], "data option applied")
16
- assert_equal(@series.labels, ["zero", "one","two"], "labels option applied")
15
+ assert_equal(@series.labels, ["zero", "one","two"], "labels option applied")
17
16
  end
18
17
 
19
18
  def test_data
@@ -1,8 +1,7 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestMarker < Test::Unit::TestCase
5
- def setup
4
+ def setup
6
5
  @marker = Axlsx::Marker.new
7
6
  end
8
7
 
@@ -41,5 +40,5 @@ class TestMarker < Test::Unit::TestCase
41
40
  assert_equal(@marker.col, 5)
42
41
  assert_equal(@marker.row, 10)
43
42
  end
44
-
43
+
45
44
  end
@@ -1,9 +1,8 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestOneCellAnchor < Test::Unit::TestCase
5
4
 
6
- def setup
5
+ def setup
7
6
  @p = Axlsx::Package.new
8
7
  @ws = @p.workbook.add_worksheet
9
8
  @test_img = File.dirname(__FILE__) + "/../../examples/image1.jpeg"
@@ -22,7 +21,7 @@ class TestOneCellAnchor < Test::Unit::TestCase
22
21
  end
23
22
 
24
23
  def test_from
25
- assert(@anchor.from.is_a?(Axlsx::Marker))
24
+ assert(@anchor.from.is_a?(Axlsx::Marker))
26
25
  end
27
26
 
28
27
  def test_object
@@ -36,13 +35,13 @@ class TestOneCellAnchor < Test::Unit::TestCase
36
35
  def test_width
37
36
  assert_raise(ArgumentError) { @anchor.width = "a" }
38
37
  assert_nothing_raised { @anchor.width = 600 }
39
- assert_equal(@anchor.width, 600)
38
+ assert_equal(@anchor.width, 600)
40
39
  end
41
40
 
42
41
  def test_height
43
42
  assert_raise(ArgumentError) { @anchor.height = "a" }
44
43
  assert_nothing_raised { @anchor.height = 400 }
45
- assert_equal(400, @anchor.height)
44
+ assert_equal(400, @anchor.height)
46
45
  end
47
46
 
48
47
  def test_ext
@@ -63,5 +62,5 @@ class TestOneCellAnchor < Test::Unit::TestCase
63
62
  assert_equal(2, i.anchor.from.row)
64
63
  assert_equal(@test_img, i.image_src)
65
64
  end
66
-
65
+
67
66
  end
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestPic < Test::Unit::TestCase
5
4
 
@@ -18,6 +17,12 @@ class TestPic < Test::Unit::TestCase
18
17
  assert_equal(@image.image_src, @test_img)
19
18
  end
20
19
 
20
+ def test_hyperlink
21
+ assert_equal(@image.hyperlink, nil)
22
+ @image.hyperlink = "http://axlsx.blogspot.com"
23
+ assert_equal(@image.hyperlink.href, "http://axlsx.blogspot.com")
24
+ end
25
+
21
26
  def test_name
22
27
  assert_raise(ArgumentError) { @image.name = 49 }
23
28
  assert_nothing_raised { @image.name = "unknown" }
@@ -34,13 +39,13 @@ class TestPic < Test::Unit::TestCase
34
39
  def test_width
35
40
  assert_raise(ArgumentError) { @image.width = "a" }
36
41
  assert_nothing_raised { @image.width = 600 }
37
- assert_equal(@image.width, 600)
42
+ assert_equal(@image.width, 600)
38
43
  end
39
44
 
40
45
  def test_height
41
46
  assert_raise(ArgumentError) { @image.height = "a" }
42
47
  assert_nothing_raised { @image.height = 600 }
43
- assert_equal(600, @image.height)
48
+ assert_equal(600, @image.height)
44
49
  end
45
50
 
46
51
  def test_image_src
@@ -56,16 +61,16 @@ class TestPic < Test::Unit::TestCase
56
61
  assert_nothing_raised { @image.descr = "test" }
57
62
  assert_equal(@image.descr, "test")
58
63
  end
59
-
64
+
60
65
  def test_to_xml
61
66
  schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
62
- doc = Nokogiri::XML(@image.anchor.drawing.to_xml)
67
+ doc = Nokogiri::XML(@image.anchor.drawing.to_xml_string)
63
68
  errors = []
64
69
  schema.validate(doc).each do |error|
65
70
  errors.push error
66
71
  puts error.message
67
72
  end
68
73
  assert(errors.empty?, "error free validation")
69
- end
70
-
74
+ end
75
+
71
76
  end
@@ -1,8 +1,7 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestPictureLocking < Test::Unit::TestCase
5
- def setup
4
+ def setup
6
5
  @item = Axlsx::PictureLocking.new
7
6
  end
8
7
  def teardown
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestPie3DChart < Test::Unit::TestCase
5
4
 
@@ -18,16 +17,16 @@ class TestPie3DChart < Test::Unit::TestCase
18
17
  assert_equal(@chart.view3D.perspective, 30, "view 3d default perspective incorrect")
19
18
  assert_equal(@chart.series_type, Axlsx::PieSeries, "series type incorrect")
20
19
  end
21
-
20
+
22
21
  def test_to_xml
23
22
  schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
24
- doc = Nokogiri::XML(@chart.to_xml)
23
+ doc = Nokogiri::XML(@chart.to_xml_string)
25
24
  errors = []
26
25
  schema.validate(doc).each do |error|
27
26
  errors.push error
28
27
  puts error.message
29
28
  end
30
29
  assert(errors.empty?, "error free validation")
31
- end
32
-
30
+ end
31
+
33
32
  end
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestPieSeries < Test::Unit::TestCase
5
4
 
@@ -9,12 +8,12 @@ class TestPieSeries < Test::Unit::TestCase
9
8
  chart = @ws.drawing.add_chart Axlsx::Pie3DChart, :title => "fishery"
10
9
  @series = chart.add_series :data=>[0,1,2], :labels=>["zero", "one", "two"], :title=>"bob"
11
10
  end
12
-
11
+
13
12
  def test_initialize
14
13
  assert_equal(@series.title.text, "bob", "series title has been applied")
15
14
  assert_equal(@series.data, [0,1,2], "data option applied")
16
- assert_equal(@series.labels, ["zero", "one","two"], "labels option applied")
17
- assert_equal(@series.explosion, nil, "series shape has been applied")
15
+ assert_equal(@series.labels, ["zero", "one","two"], "labels option applied")
16
+ assert_equal(@series.explosion, nil, "series shape has been applied")
18
17
  end
19
18
 
20
19
  def test_data
@@ -1,8 +1,7 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestScaling < Test::Unit::TestCase
5
- def setup
4
+ def setup
6
5
  @scaling = Axlsx::Scaling.new
7
6
  end
8
7
 
@@ -33,5 +32,5 @@ class TestScaling < Test::Unit::TestCase
33
32
  assert_raise(ArgumentError) { @scaling.min = 1}
34
33
  assert_nothing_raised {@scaling.min = 10.5}
35
34
  end
36
-
35
+
37
36
  end
@@ -0,0 +1,43 @@
1
+ require 'tc_helper.rb'
2
+
3
+ class TestScatterChart < Test::Unit::TestCase
4
+ def setup
5
+ @p = Axlsx::Package.new
6
+ @chart = nil
7
+ ws = @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 ["Second", 5, 2, 14, 9]
11
+ sheet.add_row ["", 5, 10, 15, 20]
12
+ sheet.add_chart(Axlsx::ScatterChart, :title => "example 7: Scatter Chart") do |chart|
13
+ chart.start_at 0, 4
14
+ chart.end_at 10, 19
15
+ chart.add_series :xData => sheet["B1:E1"], :yData => sheet["B2:E2"], :title => sheet["A1"]
16
+ chart.add_series :xData => sheet["B3:E3"], :yData => sheet["B4:E4"], :title => sheet["A3"]
17
+ @chart = chart
18
+ end
19
+ end
20
+ end
21
+
22
+ def teardown
23
+ end
24
+
25
+ def test_initialization
26
+ assert_equal(@chart.scatterStyle, :lineMarker, "scatterStyle defualt incorrect")
27
+ assert_equal(@chart.series_type, Axlsx::ScatterSeries, "series type incorrect")
28
+ assert(@chart.xValAxis.is_a?(Axlsx::ValAxis), "independant value axis not created")
29
+ assert(@chart.yValAxis.is_a?(Axlsx::ValAxis), "dependant value axis not created")
30
+ end
31
+
32
+ def test_to_xml_string
33
+ schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
34
+ doc = Nokogiri::XML(@chart.to_xml_string)
35
+ errors = []
36
+ schema.validate(doc).each do |error|
37
+ errors.push error
38
+ puts error.message
39
+ end
40
+ assert(errors.empty?, "error free validation")
41
+ end
42
+
43
+ end
@@ -0,0 +1,20 @@
1
+ require 'tc_helper.rb'
2
+
3
+ class TestScatterSeries < Test::Unit::TestCase
4
+
5
+ def setup
6
+ p = Axlsx::Package.new
7
+ @ws = p.workbook.add_worksheet :name=>"hmmm"
8
+ chart = @ws.drawing.add_chart Axlsx::ScatterChart, :title => "Scatter Chart"
9
+ @series = chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"exponents"
10
+ end
11
+
12
+ def test_initialize
13
+ assert_equal(@series.title.text, "exponents", "series title has been applied")
14
+ end
15
+
16
+ def test_data
17
+ assert_equal(@series.xData, [1,2,4])
18
+ assert_equal(@series.yData, [1,3,9])
19
+ end
20
+ end
@@ -1,8 +1,7 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestSerAxis < Test::Unit::TestCase
5
- def setup
4
+ def setup
6
5
  @axis = Axlsx::SerAxis.new 12345, 54321
7
6
  end
8
7
  def teardown
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestSeries < Test::Unit::TestCase
5
4
 
@@ -9,16 +8,16 @@ class TestSeries < Test::Unit::TestCase
9
8
  chart = @ws.drawing.add_chart Axlsx::Chart, :title => "fishery"
10
9
  @series = chart.add_series :title=>"bob"
11
10
  end
12
-
11
+
13
12
  def test_initialize
14
13
  assert_equal(@series.title.text, "bob", "series title has been applied")
15
14
  assert_equal(@series.order, @series.index, "order is index by default")
16
- assert_equal(@series.index, @series.chart.series.index(@series), "index is applied")
15
+ assert_equal(@series.index, @series.chart.series.index(@series), "index is applied")
17
16
  end
18
17
 
19
18
  def test_order
20
19
  @series.order = 2
21
20
  assert_equal(@series.order, 2)
22
21
  end
23
-
22
+
24
23
  end
@@ -1,8 +1,7 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestSeriesTitle < Test::Unit::TestCase
5
- def setup
4
+ def setup
6
5
  @p = Axlsx::Package.new
7
6
  ws = @p.workbook.add_worksheet
8
7
  @row = ws.add_row ["one", 1, Time.now]
@@ -21,7 +20,7 @@ class TestSeriesTitle < Test::Unit::TestCase
21
20
  def test_text
22
21
  assert_raise(ArgumentError, "text must be a string") { @title.text = 123 }
23
22
  @title.cell = @row.cells.first
24
- @title.text = "bob"
23
+ @title.text = "bob"
25
24
  assert(@title.cell == nil, "setting title with text clears the cell")
26
25
  end
27
26
 
@@ -30,5 +29,5 @@ class TestSeriesTitle < Test::Unit::TestCase
30
29
  @title.cell = @row.cells.first
31
30
  assert(@title.text == "one")
32
31
  end
33
-
32
+
34
33
  end
@@ -1,8 +1,7 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestTitle < Test::Unit::TestCase
5
- def setup
4
+ def setup
6
5
  @p = Axlsx::Package.new
7
6
  ws = @p.workbook.add_worksheet
8
7
  @row = ws.add_row ["one", 1, Time.now]
@@ -21,7 +20,7 @@ class TestTitle < Test::Unit::TestCase
21
20
  def test_text
22
21
  assert_raise(ArgumentError, "text must be a string") { @title.text = 123 }
23
22
  @title.cell = @row.cells.first
24
- @title.text = "bob"
23
+ @title.text = "bob"
25
24
  assert(@title.cell == nil, "setting title with text clears the cell")
26
25
  end
27
26
 
@@ -30,5 +29,5 @@ class TestTitle < Test::Unit::TestCase
30
29
  @title.cell = @row.cells.first
31
30
  assert(@title.text == "one")
32
31
  end
33
-
32
+
34
33
  end
@@ -1,9 +1,8 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestTwoCellAnchor < Test::Unit::TestCase
5
4
 
6
- def setup
5
+ def setup
7
6
  p = Axlsx::Package.new
8
7
  @ws = p.workbook.add_worksheet
9
8
  row = @ws.add_row ["one", 1, Time.now]
@@ -22,7 +21,7 @@ class TestTwoCellAnchor < Test::Unit::TestCase
22
21
  assert(@anchor.to.row == 10)
23
22
  end
24
23
 
25
-
24
+
26
25
  def test_options
27
26
  assert_raise(ArgumentError, 'invalid start_at') { @ws.add_chart Axlsx::Chart, :start_at=>[1] }
28
27
  assert_raise(ArgumentError, 'invalid end_at') { @ws.add_chart Axlsx::Chart, :start_at=>[1,2], :end_at => ["a", 4] }
@@ -34,5 +33,5 @@ class TestTwoCellAnchor < Test::Unit::TestCase
34
33
  assert_equal(a.graphic_frame.anchor.to.col, 90)
35
34
  assert_equal(a.graphic_frame.anchor.to.row, 45)
36
35
  end
37
-
36
+
38
37
  end
@@ -1,8 +1,7 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestValAxis < Test::Unit::TestCase
5
- def setup
4
+ def setup
6
5
  @axis = Axlsx::ValAxis.new 12345, 54321
7
6
  end
8
7
  def teardown
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestValAxisData < Test::Unit::TestCase
5
4
 
@@ -9,7 +8,7 @@ class TestValAxisData < Test::Unit::TestCase
9
8
  chart = @ws.drawing.add_chart Axlsx::Line3DChart
10
9
  @series = chart.add_series :data=>[0,1,2]
11
10
  end
12
-
11
+
13
12
  def test_initialize
14
13
  assert(@series.data.is_a?Axlsx::SimpleTypedList)
15
14
  assert_equal(@series.data, [0,1,2])