axlsx 1.0.15 → 1.1.1

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 (184) hide show
  1. data/.yardopts +1 -0
  2. data/CHANGELOG.md +58 -2
  3. data/README.md +425 -207
  4. data/Rakefile +6 -2
  5. data/examples/axlsx.xlsx +0 -0
  6. data/examples/example.csv +1000 -0
  7. data/examples/example.rb +266 -132
  8. data/examples/example.xlsx +0 -0
  9. data/examples/example_streamed.xlsx +0 -0
  10. data/examples/no-use_autowidth.xlsx +0 -0
  11. data/examples/real_example.rb +63 -0
  12. data/examples/sample.png +0 -0
  13. data/examples/shared_strings_example.xlsx +0 -0
  14. data/lib/axlsx/content_type/content_type.rb +13 -12
  15. data/lib/axlsx/content_type/default.rb +10 -6
  16. data/lib/axlsx/content_type/override.rb +13 -8
  17. data/lib/axlsx/doc_props/app.rb +38 -41
  18. data/lib/axlsx/doc_props/core.rb +13 -17
  19. data/lib/axlsx/drawing/axis.rb +39 -19
  20. data/lib/axlsx/drawing/bar_3D_chart.rb +34 -32
  21. data/lib/axlsx/drawing/bar_series.rb +14 -14
  22. data/lib/axlsx/drawing/cat_axis.rb +16 -14
  23. data/lib/axlsx/drawing/cat_axis_data.rb +17 -18
  24. data/lib/axlsx/drawing/chart.rb +40 -41
  25. data/lib/axlsx/drawing/drawing.rb +27 -12
  26. data/lib/axlsx/drawing/graphic_frame.rb +22 -21
  27. data/lib/axlsx/drawing/hlink_click.rb~ +0 -0
  28. data/lib/axlsx/drawing/hyperlink.rb +96 -0
  29. data/lib/axlsx/drawing/hyperlink.rb~ +64 -0
  30. data/lib/axlsx/drawing/line_3D_chart.rb +31 -28
  31. data/lib/axlsx/drawing/line_series.rb +12 -11
  32. data/lib/axlsx/drawing/marker.rb +11 -8
  33. data/lib/axlsx/drawing/named_axis_data.rb +36 -0
  34. data/lib/axlsx/drawing/one_cell_anchor.rb +18 -16
  35. data/lib/axlsx/drawing/pic.rb +47 -33
  36. data/lib/axlsx/drawing/picture_locking.rb +22 -18
  37. data/lib/axlsx/drawing/pie_3D_chart.rb +11 -8
  38. data/lib/axlsx/drawing/pie_series.rb +16 -12
  39. data/lib/axlsx/drawing/scaling.rb +11 -10
  40. data/lib/axlsx/drawing/scatter_chart.rb +69 -0
  41. data/lib/axlsx/drawing/scatter_series.rb +39 -0
  42. data/lib/axlsx/drawing/ser_axis.rb +11 -10
  43. data/lib/axlsx/drawing/series.rb +16 -15
  44. data/lib/axlsx/drawing/series_title.rb +15 -14
  45. data/lib/axlsx/drawing/title.rb +27 -26
  46. data/lib/axlsx/drawing/two_cell_anchor.rb +19 -20
  47. data/lib/axlsx/drawing/val_axis.rb +9 -7
  48. data/lib/axlsx/drawing/val_axis_data.rb +18 -17
  49. data/lib/axlsx/drawing/view_3D.rb +23 -20
  50. data/lib/axlsx/package.rb +117 -52
  51. data/lib/axlsx/rels/relationship.rb +27 -8
  52. data/lib/axlsx/rels/relationships.rb +9 -2
  53. data/lib/axlsx/stylesheet/border.rb +28 -23
  54. data/lib/axlsx/stylesheet/border_pr.rb +17 -15
  55. data/lib/axlsx/stylesheet/cell_alignment.rb +24 -21
  56. data/lib/axlsx/stylesheet/cell_protection.rb +11 -7
  57. data/lib/axlsx/stylesheet/cell_style.rb +9 -5
  58. data/lib/axlsx/stylesheet/color.rb +20 -14
  59. data/lib/axlsx/stylesheet/fill.rb +8 -5
  60. data/lib/axlsx/stylesheet/font.rb +22 -14
  61. data/lib/axlsx/stylesheet/gradient_fill.rb +20 -17
  62. data/lib/axlsx/stylesheet/gradient_stop.rb +10 -6
  63. data/lib/axlsx/stylesheet/num_fmt.rb +13 -6
  64. data/lib/axlsx/stylesheet/pattern_fill.rb +26 -10
  65. data/lib/axlsx/stylesheet/styles.rb +55 -41
  66. data/lib/axlsx/stylesheet/table_style.rb +10 -4
  67. data/lib/axlsx/stylesheet/table_style_element.rb +11 -7
  68. data/lib/axlsx/stylesheet/table_styles.rb +12 -8
  69. data/lib/axlsx/stylesheet/xf.rb +30 -25
  70. data/lib/axlsx/util/cbf.rb +69 -33
  71. data/lib/axlsx/util/constants.rb +39 -20
  72. data/lib/axlsx/util/doc/_index.html +84 -0
  73. data/lib/axlsx/util/doc/class_list.html +47 -0
  74. data/lib/axlsx/util/doc/css/common.css +1 -0
  75. data/lib/axlsx/util/doc/css/full_list.css +55 -0
  76. data/lib/axlsx/util/doc/css/style.css +322 -0
  77. data/lib/axlsx/util/doc/file_list.html +46 -0
  78. data/lib/axlsx/util/doc/frames.html +13 -0
  79. data/lib/axlsx/util/doc/index.html +84 -0
  80. data/lib/axlsx/util/doc/js/app.js +205 -0
  81. data/lib/axlsx/util/doc/js/full_list.js +173 -0
  82. data/lib/axlsx/util/doc/js/jquery.js +16 -0
  83. data/lib/axlsx/util/doc/method_list.html +46 -0
  84. data/lib/axlsx/util/doc/top-level-namespace.html +95 -0
  85. data/lib/axlsx/util/font_tables.rb~ +0 -0
  86. data/lib/axlsx/util/ms_off_crypto.rb +10 -10
  87. data/lib/axlsx/util/parser.rb +1 -0
  88. data/lib/axlsx/util/simple_typed_list.rb +20 -10
  89. data/lib/axlsx/util/storage.rb +1 -1
  90. data/lib/axlsx/util/validators.rb +23 -7
  91. data/lib/axlsx/version.rb +5 -2
  92. data/lib/axlsx/workbook/shared_strings_table.rb +68 -0
  93. data/lib/axlsx/workbook/shared_strings_table.rb~ +69 -0
  94. data/lib/axlsx/workbook/workbook.rb +82 -26
  95. data/lib/axlsx/workbook/worksheet/cell.rb +166 -130
  96. data/lib/axlsx/workbook/worksheet/col.rb +114 -0
  97. data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
  98. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +29 -0
  99. data/lib/axlsx/workbook/worksheet/page_margins.rb +97 -0
  100. data/lib/axlsx/workbook/worksheet/row.rb +53 -21
  101. data/lib/axlsx/workbook/worksheet/shared_strings_table.rb~ +0 -0
  102. data/lib/axlsx/workbook/worksheet/table.rb +96 -0
  103. data/lib/axlsx/workbook/worksheet/table.rb~ +97 -0
  104. data/lib/axlsx/workbook/worksheet/worksheet.rb +275 -124
  105. data/lib/axlsx.rb +41 -14
  106. data/lib/schema/dc.xsd +5 -5
  107. data/lib/schema/dcmitype.xsd +5 -3
  108. data/lib/schema/dcterms.xsd +15 -15
  109. data/lib/schema/opc-coreProperties.xsd +6 -2
  110. data/lib/schema/xml.xsd +7 -8
  111. data/test/benchmark.rb +73 -0
  112. data/test/content_type/tc_content_type.rb +31 -31
  113. data/test/content_type/tc_default.rb +9 -22
  114. data/test/content_type/tc_override.rb +8 -21
  115. data/test/doc_props/tc_app.rb +2 -8
  116. data/test/doc_props/tc_core.rb +6 -7
  117. data/test/drawing/tc_axis.rb +7 -3
  118. data/test/drawing/tc_bar_3D_chart.rb +6 -7
  119. data/test/drawing/tc_bar_series.rb +4 -5
  120. data/test/drawing/tc_cat_axis.rb +2 -3
  121. data/test/drawing/tc_cat_axis_data.rb +2 -3
  122. data/test/drawing/tc_chart.rb +13 -14
  123. data/test/drawing/tc_drawing.rb +7 -8
  124. data/test/drawing/tc_graphic_frame.rb +3 -4
  125. data/test/drawing/tc_hyperlink.rb +69 -0
  126. data/test/drawing/tc_line_3d_chart.rb +5 -6
  127. data/test/drawing/tc_line_series.rb +3 -4
  128. data/test/drawing/tc_marker.rb +3 -4
  129. data/test/drawing/tc_one_cell_anchor.rb +6 -7
  130. data/test/drawing/tc_pic.rb +13 -8
  131. data/test/drawing/tc_picture_locking.rb +2 -3
  132. data/test/drawing/tc_pie_3D_chart.rb +5 -6
  133. data/test/drawing/tc_pie_series.rb +4 -5
  134. data/test/drawing/tc_scaling.rb +3 -4
  135. data/test/drawing/tc_scatter_chart.rb +43 -0
  136. data/test/drawing/tc_scatter_series.rb +20 -0
  137. data/test/drawing/tc_ser_axis.rb +2 -3
  138. data/test/drawing/tc_series.rb +4 -5
  139. data/test/drawing/tc_series_title.rb +4 -5
  140. data/test/drawing/tc_title.rb +4 -5
  141. data/test/drawing/tc_two_cell_anchor.rb +4 -5
  142. data/test/drawing/tc_val_axis.rb +2 -3
  143. data/test/drawing/tc_val_axis_data.rb +2 -3
  144. data/test/drawing/tc_view_3D.rb +6 -7
  145. data/test/profile.rb +34 -0
  146. data/test/rels/tc_relationship.rb +10 -6
  147. data/test/rels/tc_relationships.rb +4 -5
  148. data/test/stylesheet/tc_border.rb +3 -4
  149. data/test/stylesheet/tc_border_pr.rb +3 -4
  150. data/test/stylesheet/tc_cell_alignment.rb +10 -6
  151. data/test/stylesheet/tc_cell_protection.rb +2 -3
  152. data/test/stylesheet/tc_cell_style.rb +2 -3
  153. data/test/stylesheet/tc_color.rb +2 -3
  154. data/test/stylesheet/tc_fill.rb +1 -2
  155. data/test/stylesheet/tc_font.rb +12 -5
  156. data/test/stylesheet/tc_gradient_fill.rb +1 -2
  157. data/test/stylesheet/tc_gradient_stop.rb +1 -2
  158. data/test/stylesheet/tc_num_fmt.rb +1 -2
  159. data/test/stylesheet/tc_pattern_fill.rb +3 -4
  160. data/test/stylesheet/tc_styles.rb +31 -6
  161. data/test/stylesheet/tc_table_style.rb +2 -3
  162. data/test/stylesheet/tc_table_style_element.rb +2 -3
  163. data/test/stylesheet/tc_table_styles.rb +3 -4
  164. data/test/stylesheet/tc_xf.rb +16 -17
  165. data/test/tc_axlsx.rb +39 -0
  166. data/test/tc_helper.rb +3 -0
  167. data/test/tc_package.rb +43 -9
  168. data/test/util/tc_simple_typed_list.rb +8 -9
  169. data/test/util/tc_validators.rb +7 -8
  170. data/test/workbook/tc_shared_strings_table.rb +38 -0
  171. data/test/workbook/tc_workbook.rb +32 -6
  172. data/test/workbook/worksheet/table/tc_table.rb +71 -0
  173. data/test/workbook/worksheet/table/tc_table.rb~ +72 -0
  174. data/test/workbook/worksheet/tc_cell.rb +80 -13
  175. data/test/workbook/worksheet/tc_col.rb +59 -0
  176. data/test/workbook/worksheet/tc_col.rb~ +10 -0
  177. data/test/workbook/worksheet/tc_date_time_converter.rb +132 -0
  178. data/test/workbook/worksheet/tc_page_margins.rb +97 -0
  179. data/test/workbook/worksheet/tc_row.rb +54 -4
  180. data/test/workbook/worksheet/tc_worksheet.rb +205 -31
  181. metadata +78 -84
  182. data/examples/example.rb~ +0 -112
  183. data/test/drawing/tc_line_series.tc~ +0 -34
  184. data/test/drawing/tc_picture_locking.rb~ +0 -77
@@ -1,14 +1,13 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestView3D < Test::Unit::TestCase
5
- def setup
4
+ def setup
6
5
  @view = Axlsx::View3D.new
7
6
  end
8
7
 
9
8
  def teardown
10
9
  end
11
-
10
+
12
11
  def test_options
13
12
  v = Axlsx::View3D.new :rotX => 10, :rotY => 5, :hPercent => "30%", :depthPercent => "45%", :rAngAx => false, :perspective => 10
14
13
  assert_equal(v.rotX, 10)
@@ -18,7 +17,7 @@ class TestView3D < Test::Unit::TestCase
18
17
  assert_equal(v.rAngAx, false)
19
18
  assert_equal(v.perspective, 10)
20
19
  end
21
-
20
+
22
21
  def test_rotX
23
22
  assert_raise(ArgumentError) {@view.rotX = "bob"}
24
23
  assert_nothing_raised {@view.rotX = -90}
@@ -44,12 +43,12 @@ class TestView3D < Test::Unit::TestCase
44
43
  assert_raise(ArgumentError) {@view.rAngAx = "bob"}
45
44
  assert_nothing_raised {@view.rAngAx = true}
46
45
  end
47
-
46
+
48
47
  def test_perspective
49
48
  assert_raise(ArgumentError) {@view.perspective = "bob"}
50
49
  assert_nothing_raised {@view.perspective = 30}
51
50
  end
52
51
 
53
52
 
54
-
53
+
55
54
  end
data/test/profile.rb ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby -s
2
+ # -*- coding: utf-8 -*-
3
+
4
+ # Usage:
5
+ # > ruby test/profile.rb
6
+ # > pprof.rb --gif /tmp/axlsx_noautowidth > /tmp/axlsx_noautowidth.gif
7
+ # > open /tmp/axlsx_noautowidth.gif
8
+
9
+ $:.unshift "#{File.dirname(__FILE__)}/../lib"
10
+ require 'axlsx'
11
+ require 'csv'
12
+
13
+ # require 'benchmark'
14
+ require 'perftools'
15
+ row = []
16
+ input = (32..126).to_a.pack('U*').chars.to_a
17
+ 20.times { row << input.shuffle.join}
18
+ times = 3000
19
+
20
+ PerfTools::CpuProfiler.start("/tmp/axlsx_noautowidth") do
21
+ p = Axlsx::Package.new
22
+ p.use_autowidth = false
23
+ p.use_shared_strings = true
24
+ wb = p.workbook
25
+
26
+ #A Simple Workbook
27
+
28
+ wb.add_worksheet do |sheet|
29
+ times.times do
30
+ sheet << row
31
+ end
32
+ end
33
+ p.serialize("example.xlsx")
34
+ end
@@ -1,16 +1,20 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestRelationships < Test::Unit::TestCase
5
- def setup
4
+ def setup
5
+ end
6
+
7
+ def teardown
6
8
  end
7
-
8
- def teardown
9
- end
10
9
 
11
10
  def test_type
12
11
  assert_raise(ArgumentError) { Axlsx::Relationship.new 'type', 'target' }
13
12
  assert_nothing_raised { Axlsx::Relationship.new Axlsx::WORKSHEET_R, 'target' }
14
13
  end
15
14
 
15
+ def test_target_mode
16
+ assert_raise(ArgumentError) { Axlsx::Relationship.new 'type', 'target', :target_mode => "FISH" }
17
+ assert_nothing_raised { Axlsx::Relationship.new( Axlsx::WORKSHEET_R, 'target', :target_mode => :External) }
18
+ end
19
+
16
20
  end
@@ -1,12 +1,11 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestRelationships < Test::Unit::TestCase
5
4
 
6
5
  def test_valid_document
7
6
  @rels = Axlsx::Relationships.new
8
7
  schema = Nokogiri::XML::Schema(File.open(Axlsx::RELS_XSD))
9
- doc = Nokogiri::XML(@rels.to_xml)
8
+ doc = Nokogiri::XML(@rels.to_xml_string)
10
9
  errors = []
11
10
  schema.validate(doc).each do |error|
12
11
  puts error.message
@@ -14,14 +13,14 @@ class TestRelationships < Test::Unit::TestCase
14
13
  end
15
14
 
16
15
  @rels << Axlsx::Relationship.new(Axlsx::WORKSHEET_R, "bar")
17
- doc = Nokogiri::XML(@rels.to_xml)
16
+ doc = Nokogiri::XML(@rels.to_xml_string)
18
17
  errors = []
19
18
  schema.validate(doc).each do |error|
20
19
  puts error.message
21
20
  errors << error
22
21
  end
23
22
 
24
- assert(errors.size == 0)
23
+ assert(errors.size == 0)
25
24
  end
26
25
 
27
26
  end
@@ -1,8 +1,7 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestBorder < Test::Unit::TestCase
5
- def setup
4
+ def setup
6
5
  @b = Axlsx::Border.new
7
6
  end
8
7
  def teardown
@@ -10,7 +9,7 @@ class TestBorder < Test::Unit::TestCase
10
9
  def test_initialiation
11
10
  assert_equal(@b.diagonalUp, nil)
12
11
  assert_equal(@b.diagonalDown, nil)
13
- assert_equal(@b.outline, nil)
12
+ assert_equal(@b.outline, nil)
14
13
  assert(@b.prs.is_a?(Axlsx::SimpleTypedList))
15
14
  end
16
15
 
@@ -1,8 +1,7 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestBorderPr < Test::Unit::TestCase
5
- def setup
4
+ def setup
6
5
  @bpr = Axlsx::BorderPr.new
7
6
  end
8
7
  def teardown
@@ -10,7 +9,7 @@ class TestBorderPr < Test::Unit::TestCase
10
9
  def test_initialiation
11
10
  assert_equal(@bpr.color, nil)
12
11
  assert_equal(@bpr.style, nil)
13
- assert_equal(@bpr.name, nil)
12
+ assert_equal(@bpr.name, nil)
14
13
  end
15
14
 
16
15
  def test_color
@@ -1,12 +1,10 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestCellAlignment < Test::Unit::TestCase
5
- def setup
4
+ def setup
6
5
  @item = Axlsx::CellAlignment.new
7
6
  end
8
- def teardown
9
- end
7
+
10
8
  def test_initialiation
11
9
  assert_equal(@item.horizontal, nil)
12
10
  assert_equal(@item.vertical, nil)
@@ -17,7 +15,13 @@ class TestCellAlignment < Test::Unit::TestCase
17
15
  assert_equal(@item.justifyLastLine, nil)
18
16
  assert_equal(@item.shrinkToFit, nil)
19
17
  assert_equal(@item.readingOrder, nil)
20
-
18
+ options = { :horizontal => :left, :vertical => :top, :textRotation => 3,
19
+ :wrapText => true, :indent => 2, :relativeIndent => 5,
20
+ :justifyLastLine => true, :shrinkToFit => true, :readingOrder => 2 }
21
+ ca = Axlsx::CellAlignment.new options
22
+ options.each do |key, value|
23
+ assert_equal(ca.send(key.to_sym),value)
24
+ end
21
25
  end
22
26
 
23
27
  def test_horizontal
@@ -1,9 +1,8 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestCellProtection < Test::Unit::TestCase
5
4
 
6
- def setup
5
+ def setup
7
6
  @item = Axlsx::CellProtection.new
8
7
  end
9
8
 
@@ -1,9 +1,8 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestCellStyle < Test::Unit::TestCase
5
4
 
6
- def setup
5
+ def setup
7
6
  @item = Axlsx::CellStyle.new
8
7
  end
9
8
 
@@ -1,9 +1,8 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestColor < Test::Unit::TestCase
5
4
 
6
- def setup
5
+ def setup
7
6
  @item = Axlsx::Color.new
8
7
  end
9
8
 
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestFill < Test::Unit::TestCase
5
4
 
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestFont < Test::Unit::TestCase
5
4
 
@@ -17,6 +16,7 @@ class TestFont < Test::Unit::TestCase
17
16
  assert_equal(@item.family, nil)
18
17
  assert_equal(@item.b, nil)
19
18
  assert_equal(@item.i, nil)
19
+ assert_equal(@item.u, nil)
20
20
  assert_equal(@item.strike, nil)
21
21
  assert_equal(@item.outline, nil)
22
22
  assert_equal(@item.shadow, nil)
@@ -28,7 +28,7 @@ class TestFont < Test::Unit::TestCase
28
28
 
29
29
 
30
30
 
31
- # def name=(v) Axlsx::validate_string v; @name = v end
31
+ # def name=(v) Axlsx::validate_string v; @name = v end
32
32
  def test_name
33
33
  assert_raise(ArgumentError) { @item.name = 7 }
34
34
  assert_nothing_raised { @item.name = "bob" }
@@ -48,7 +48,7 @@ class TestFont < Test::Unit::TestCase
48
48
  assert_equal(@item.family, 5)
49
49
  end
50
50
 
51
- # def b=(v) Axlsx::validate_boolean v; @b = v end
51
+ # def b=(v) Axlsx::validate_boolean v; @b = v end
52
52
  def test_b
53
53
  assert_raise(ArgumentError) { @item.b = -7 }
54
54
  assert_nothing_raised { @item.b = true }
@@ -62,6 +62,13 @@ class TestFont < Test::Unit::TestCase
62
62
  assert_equal(@item.i, true)
63
63
  end
64
64
 
65
+ # def u=(v) Axlsx::validate_boolean v; @u = v end
66
+ def test_u
67
+ assert_raise(ArgumentError) { @item.u = -7 }
68
+ assert_nothing_raised { @item.u = true }
69
+ assert_equal(@item.u, true)
70
+ end
71
+
65
72
  # def strike=(v) Axlsx::validate_boolean v; @strike = v end
66
73
  def test_strike
67
74
  assert_raise(ArgumentError) { @item.strike = -7 }
@@ -76,7 +83,7 @@ class TestFont < Test::Unit::TestCase
76
83
  assert_equal(@item.outline, true)
77
84
  end
78
85
 
79
- # def shadow=(v) Axlsx::validate_boolean v; @shadow = v end
86
+ # def shadow=(v) Axlsx::validate_boolean v; @shadow = v end
80
87
  def test_shadow
81
88
  assert_raise(ArgumentError) { @item.shadow = -7 }
82
89
  assert_nothing_raised { @item.shadow = true }
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestGradientFill < Test::Unit::TestCase
5
4
 
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestGradientStop < Test::Unit::TestCase
5
4
 
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestNumFmt < Test::Unit::TestCase
5
4
 
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestPatternFill < Test::Unit::TestCase
5
4
 
@@ -17,13 +16,13 @@ class TestPatternFill < Test::Unit::TestCase
17
16
  assert_equal(@item.fgColor, nil)
18
17
  end
19
18
 
20
- def test_bgColor
19
+ def test_bgColor
21
20
  assert_raise(ArgumentError) { @item.bgColor = -1.1 }
22
21
  assert_nothing_raised { @item.bgColor = Axlsx::Color.new }
23
22
  assert_equal(@item.bgColor.rgb, "FF000000")
24
23
  end
25
24
 
26
- def test_fgColor
25
+ def test_fgColor
27
26
  assert_raise(ArgumentError) { @item.fgColor = -1.1 }
28
27
  assert_nothing_raised { @item.fgColor = Axlsx::Color.new }
29
28
  assert_equal(@item.fgColor.rgb, "FF000000")
@@ -1,16 +1,15 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestStyles < Test::Unit::TestCase
5
- def setup
4
+ def setup
6
5
  @styles = Axlsx::Styles.new
7
6
  end
8
7
  def teardown
9
8
  end
10
-
9
+
11
10
  def test_valid_document
12
11
  schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
13
- doc = Nokogiri::XML(@styles.to_xml)
12
+ doc = Nokogiri::XML(@styles.to_xml_string)
14
13
  errors = []
15
14
  schema.validate(doc).each do |error|
16
15
  errors.push error
@@ -18,7 +17,29 @@ class TestStyles < Test::Unit::TestCase
18
17
  end
19
18
  assert(errors.size == 0)
20
19
  end
20
+ def test_add_style_border_hash
21
+ border_count = @styles.borders.size
22
+ s = @styles.add_style :border => {:style => :thin, :color => "FFFF0000"}
23
+ assert_equal(@styles.borders.size, border_count + 1)
24
+ assert_equal(@styles.borders.last.prs.last.color.rgb, "FFFF0000")
25
+ assert_raise(ArgumentError) { @styles.add_style :border => {:color => "FFFF0000"} }
26
+ assert_equal @styles.borders.last.prs.size, 4
27
+ end
28
+
29
+ def test_add_style_border_edges
30
+ s = @styles.add_style :border => { :style => :thin, :color => "0000FFFF", :edges => [:top, :bottom] }
31
+ parts = @styles.borders.last.prs
32
+ parts.each { |pr| assert_equal(pr.color.rgb, "0000FFFF", "Style is applied to #{pr.name} properly") }
33
+ assert((parts.map { |pr| pr.name.to_s }.sort && ['bottom', 'top']).size == 2, "specify two edges, and you get two border prs")
34
+ end
21
35
 
36
+ def test_do_not_alter_options_in_add_style
37
+ #This should test all options, but for now - just the bits that we know caused some pain
38
+ options = { :border => { :style => :thin, :color =>"FF000000" } }
39
+ @styles.add_style options
40
+ assert_equal options[:border][:style], :thin, 'thin style is stil in option'
41
+ assert_equal options[:border][:color], "FF000000", 'color is stil in option'
42
+ end
22
43
 
23
44
  def test_add_style
24
45
  fill_count = @styles.fills.size
@@ -42,11 +63,15 @@ class TestStyles < Test::Unit::TestCase
42
63
 
43
64
  assert(xf.alignment.is_a?(Axlsx::CellAlignment), "alignment was created")
44
65
  assert_equal(xf.alignment.horizontal, :left, "horizontal alignment applied")
45
- assert_equal(xf.applyProtection, 1, "protection applied")
46
66
  assert_equal(xf.protection.hidden, true, "hidden protection set")
47
67
  assert_equal(xf.protection.locked, true, "cell locking set")
48
68
  assert_raise(ArgumentError, "should reject invalid borderId") { @styles.add_style :border => 2 }
49
69
 
70
+
71
+ assert_equal(xf.applyProtection, 1, "protection applied")
72
+ assert_equal(xf.applyBorder, true, "border applied")
73
+ assert_equal(xf.applyNumberFormat, true, "number format applied")
74
+ assert_equal(xf.applyAlignment, true, "alignment applied")
50
75
  end
51
76
 
52
77
  end
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestTableStyle < Test::Unit::TestCase
5
4
 
@@ -16,7 +15,7 @@ class TestTableStyle < Test::Unit::TestCase
16
15
  assert_equal(@item.table, nil)
17
16
  end
18
17
 
19
- def test_name
18
+ def test_name
20
19
  assert_raise(ArgumentError) { @item.name = -1.1 }
21
20
  assert_nothing_raised { @item.name = "lovely table style" }
22
21
  assert_equal(@item.name, "lovely table style")
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestTableStyleElement < Test::Unit::TestCase
5
4
 
@@ -16,7 +15,7 @@ class TestTableStyleElement < Test::Unit::TestCase
16
15
  assert_equal(@item.dxfId, nil)
17
16
  end
18
17
 
19
- def test_type
18
+ def test_type
20
19
  assert_raise(ArgumentError) { @item.type = -1.1 }
21
20
  assert_nothing_raised { @item.type = :blankRow }
22
21
  assert_equal(@item.type, :blankRow)
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestTableStyles < Test::Unit::TestCase
5
4
 
@@ -15,13 +14,13 @@ class TestTableStyles < Test::Unit::TestCase
15
14
  assert_equal(@item.defaultPivotStyle, "PivotStyleLight16")
16
15
  end
17
16
 
18
- def test_defaultTableStyle
17
+ def test_defaultTableStyle
19
18
  assert_raise(ArgumentError) { @item.defaultTableStyle = -1.1 }
20
19
  assert_nothing_raised { @item.defaultTableStyle = "anyones guess" }
21
20
  assert_equal(@item.defaultTableStyle, "anyones guess")
22
21
  end
23
22
 
24
- def test_defaultPivotStyle
23
+ def test_defaultPivotStyle
25
24
  assert_raise(ArgumentError) { @item.defaultPivotStyle = -1.1 }
26
25
  assert_nothing_raised { @item.defaultPivotStyle = "anyones guess" }
27
26
  assert_equal(@item.defaultPivotStyle, "anyones guess")
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestXf < Test::Unit::TestCase
5
4
 
@@ -28,91 +27,91 @@ class TestXf < Test::Unit::TestCase
28
27
  assert_equal(@item.applyProtection, nil)
29
28
  end
30
29
 
31
- def test_alignment
30
+ def test_alignment
32
31
  assert_raise(ArgumentError) { @item.alignment = -1.1 }
33
32
  assert_nothing_raised { @item.alignment = Axlsx::CellAlignment.new }
34
33
  assert(@item.alignment.is_a?(Axlsx::CellAlignment))
35
34
  end
36
35
 
37
- def test_protection
36
+ def test_protection
38
37
  assert_raise(ArgumentError) { @item.protection = -1.1 }
39
38
  assert_nothing_raised { @item.protection = Axlsx::CellProtection.new }
40
39
  assert(@item.protection.is_a?(Axlsx::CellProtection))
41
40
  end
42
41
 
43
- def test_numFmtId
42
+ def test_numFmtId
44
43
  assert_raise(ArgumentError) { @item.numFmtId = -1.1 }
45
44
  assert_nothing_raised { @item.numFmtId = 0 }
46
45
  assert_equal(@item.numFmtId, 0)
47
46
  end
48
47
 
49
- def test_fillId
48
+ def test_fillId
50
49
  assert_raise(ArgumentError) { @item.fillId = -1.1 }
51
50
  assert_nothing_raised { @item.fillId = 0 }
52
51
  assert_equal(@item.fillId, 0)
53
52
  end
54
53
 
55
- def test_fontId
54
+ def test_fontId
56
55
  assert_raise(ArgumentError) { @item.fontId = -1.1 }
57
56
  assert_nothing_raised { @item.fontId = 0 }
58
57
  assert_equal(@item.fontId, 0)
59
58
  end
60
59
 
61
- def test_borderId
60
+ def test_borderId
62
61
  assert_raise(ArgumentError) { @item.borderId = -1.1 }
63
62
  assert_nothing_raised { @item.borderId = 0 }
64
63
  assert_equal(@item.borderId, 0)
65
64
  end
66
65
 
67
- def test_xfId
66
+ def test_xfId
68
67
  assert_raise(ArgumentError) { @item.xfId = -1.1 }
69
68
  assert_nothing_raised { @item.xfId = 0 }
70
69
  assert_equal(@item.xfId, 0)
71
70
  end
72
71
 
73
- def test_quotePrefix
72
+ def test_quotePrefix
74
73
  assert_raise(ArgumentError) { @item.quotePrefix = -1.1 }
75
74
  assert_nothing_raised { @item.quotePrefix = false }
76
75
  assert_equal(@item.quotePrefix, false)
77
76
  end
78
77
 
79
- def test_pivotButton
78
+ def test_pivotButton
80
79
  assert_raise(ArgumentError) { @item.pivotButton = -1.1 }
81
80
  assert_nothing_raised { @item.pivotButton = false }
82
81
  assert_equal(@item.pivotButton, false)
83
82
  end
84
83
 
85
- def test_applyNumberFormat
84
+ def test_applyNumberFormat
86
85
  assert_raise(ArgumentError) { @item.applyNumberFormat = -1.1 }
87
86
  assert_nothing_raised { @item.applyNumberFormat = false }
88
87
  assert_equal(@item.applyNumberFormat, false)
89
88
  end
90
89
 
91
- def test_applyFont
90
+ def test_applyFont
92
91
  assert_raise(ArgumentError) { @item.applyFont = -1.1 }
93
92
  assert_nothing_raised { @item.applyFont = false }
94
93
  assert_equal(@item.applyFont, false)
95
94
  end
96
95
 
97
- def test_applyFill
96
+ def test_applyFill
98
97
  assert_raise(ArgumentError) { @item.applyFill = -1.1 }
99
98
  assert_nothing_raised { @item.applyFill = false }
100
99
  assert_equal(@item.applyFill, false)
101
100
  end
102
101
 
103
- def test_applyBorder
102
+ def test_applyBorder
104
103
  assert_raise(ArgumentError) { @item.applyBorder = -1.1 }
105
104
  assert_nothing_raised { @item.applyBorder = false }
106
105
  assert_equal(@item.applyBorder, false)
107
106
  end
108
107
 
109
- def test_applyAlignment
108
+ def test_applyAlignment
110
109
  assert_raise(ArgumentError) { @item.applyAlignment = -1.1 }
111
110
  assert_nothing_raised { @item.applyAlignment = false }
112
111
  assert_equal(@item.applyAlignment, false)
113
112
  end
114
113
 
115
- def test_applyProtection
114
+ def test_applyProtection
116
115
  assert_raise(ArgumentError) { @item.applyProtection = -1.1 }
117
116
  assert_nothing_raised { @item.applyProtection = false }
118
117
  assert_equal(@item.applyProtection, false)
data/test/tc_axlsx.rb ADDED
@@ -0,0 +1,39 @@
1
+ require 'tc_helper.rb'
2
+
3
+ class TestAxlsx < Test::Unit::TestCase
4
+
5
+ def setup_wide
6
+ @wide_test_points = { "A3" => 0,
7
+ "Z3" => 25,
8
+ "B3" => 1,
9
+ "AA3" => 1 * 26 + 0,
10
+ "AAA3" => 1 * 26**2 + 1 * 26 + 0,
11
+ "AAZ3" => 1 * 26**2 + 1 * 26 + 25,
12
+ "ABA3" => 1 * 26**2 + 2 * 26 + 0,
13
+ "BZU3" => 2 * 26**2 + 26 * 26 + 20
14
+ }
15
+ end
16
+
17
+ def test_cell_range
18
+ #To do
19
+ end
20
+
21
+ def test_name_to_indices
22
+ setup_wide
23
+ @wide_test_points.each do |key, value|
24
+ assert_equal(Axlsx.name_to_indices(key), [value,2])
25
+ end
26
+ end
27
+
28
+ def test_col_ref
29
+ setup_wide
30
+ @wide_test_points.each do |key, value|
31
+ assert_equal(Axlsx.col_ref(value), key.gsub(/\d+/, ''))
32
+ end
33
+ end
34
+
35
+ def test_cell_r
36
+ # todo
37
+ end
38
+
39
+ end
data/test/tc_helper.rb ADDED
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
+ require 'test/unit'
3
+ require "axlsx.rb"