axlsx 1.0.17 → 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 (167) hide show
  1. data/CHANGELOG.md +11 -3
  2. data/README.md +159 -51
  3. data/examples/example.csv +1000 -0
  4. data/examples/example.rb +255 -150
  5. data/examples/example.xlsx +0 -0
  6. data/examples/example_streamed.xlsx +0 -0
  7. data/examples/no-use_autowidth.xlsx +0 -0
  8. data/examples/shared_strings_example.xlsx +0 -0
  9. data/lib/axlsx/content_type/content_type.rb +12 -12
  10. data/lib/axlsx/content_type/default.rb +9 -6
  11. data/lib/axlsx/content_type/override.rb +12 -8
  12. data/lib/axlsx/doc_props/app.rb +37 -40
  13. data/lib/axlsx/doc_props/core.rb +12 -17
  14. data/lib/axlsx/drawing/axis.rb +38 -19
  15. data/lib/axlsx/drawing/bar_3D_chart.rb +33 -32
  16. data/lib/axlsx/drawing/bar_series.rb +13 -14
  17. data/lib/axlsx/drawing/cat_axis.rb +15 -14
  18. data/lib/axlsx/drawing/cat_axis_data.rb +16 -18
  19. data/lib/axlsx/drawing/chart.rb +39 -40
  20. data/lib/axlsx/drawing/drawing.rb +15 -12
  21. data/lib/axlsx/drawing/graphic_frame.rb +21 -21
  22. data/lib/axlsx/drawing/hyperlink.rb +12 -11
  23. data/lib/axlsx/drawing/line_3D_chart.rb +30 -28
  24. data/lib/axlsx/drawing/line_series.rb +11 -11
  25. data/lib/axlsx/drawing/marker.rb +10 -8
  26. data/lib/axlsx/drawing/named_axis_data.rb +36 -0
  27. data/lib/axlsx/drawing/one_cell_anchor.rb +17 -16
  28. data/lib/axlsx/drawing/pic.rb +25 -37
  29. data/lib/axlsx/drawing/picture_locking.rb +21 -18
  30. data/lib/axlsx/drawing/pie_3D_chart.rb +10 -8
  31. data/lib/axlsx/drawing/pie_series.rb +15 -12
  32. data/lib/axlsx/drawing/scaling.rb +10 -10
  33. data/lib/axlsx/drawing/scatter_chart.rb +69 -0
  34. data/lib/axlsx/drawing/scatter_series.rb +39 -0
  35. data/lib/axlsx/drawing/ser_axis.rb +10 -10
  36. data/lib/axlsx/drawing/series.rb +15 -15
  37. data/lib/axlsx/drawing/series_title.rb +14 -14
  38. data/lib/axlsx/drawing/title.rb +26 -26
  39. data/lib/axlsx/drawing/two_cell_anchor.rb +18 -20
  40. data/lib/axlsx/drawing/val_axis.rb +8 -7
  41. data/lib/axlsx/drawing/val_axis_data.rb +17 -17
  42. data/lib/axlsx/drawing/view_3D.rb +22 -20
  43. data/lib/axlsx/package.rb +60 -43
  44. data/lib/axlsx/rels/relationship.rb +11 -8
  45. data/lib/axlsx/rels/relationships.rb +7 -1
  46. data/lib/axlsx/stylesheet/#num_fmt.rb# +69 -0
  47. data/lib/axlsx/stylesheet/border.rb +27 -23
  48. data/lib/axlsx/stylesheet/border_pr.rb +16 -15
  49. data/lib/axlsx/stylesheet/cell_alignment.rb +23 -21
  50. data/lib/axlsx/stylesheet/cell_protection.rb +10 -7
  51. data/lib/axlsx/stylesheet/cell_style.rb +8 -5
  52. data/lib/axlsx/stylesheet/color.rb +20 -14
  53. data/lib/axlsx/stylesheet/fill.rb +7 -5
  54. data/lib/axlsx/stylesheet/font.rb +21 -14
  55. data/lib/axlsx/stylesheet/gradient_fill.rb +19 -16
  56. data/lib/axlsx/stylesheet/gradient_stop.rb +9 -5
  57. data/lib/axlsx/stylesheet/num_fmt.rb +12 -6
  58. data/lib/axlsx/stylesheet/pattern_fill.rb +25 -10
  59. data/lib/axlsx/stylesheet/styles.rb +47 -35
  60. data/lib/axlsx/stylesheet/table_style.rb +9 -4
  61. data/lib/axlsx/stylesheet/table_style_element.rb +10 -7
  62. data/lib/axlsx/stylesheet/table_styles.rb +11 -8
  63. data/lib/axlsx/stylesheet/xf.rb +29 -25
  64. data/lib/axlsx/util/constants.rb +20 -14
  65. data/lib/axlsx/util/simple_typed_list.rb +18 -9
  66. data/lib/axlsx/util/validators.rb +13 -6
  67. data/lib/axlsx/version.rb +1 -1
  68. data/lib/axlsx/workbook/shared_strings_table.rb +19 -21
  69. data/lib/axlsx/workbook/workbook.rb +58 -34
  70. data/lib/axlsx/workbook/worksheet/cell.rb +149 -132
  71. data/lib/axlsx/workbook/worksheet/col.rb +114 -0
  72. data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
  73. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +29 -0
  74. data/lib/axlsx/workbook/worksheet/page_margins.rb +97 -0
  75. data/lib/axlsx/workbook/worksheet/row.rb +40 -23
  76. data/lib/axlsx/workbook/worksheet/table.rb +96 -0
  77. data/lib/axlsx/workbook/worksheet/table.rb~ +97 -0
  78. data/lib/axlsx/workbook/worksheet/worksheet.rb +243 -127
  79. data/lib/axlsx.rb +30 -9
  80. data/lib/schema/dc.xsd +5 -5
  81. data/lib/schema/dcmitype.xsd +5 -3
  82. data/lib/schema/dcterms.xsd +15 -15
  83. data/lib/schema/opc-coreProperties.xsd +6 -2
  84. data/lib/schema/xml.xsd +7 -8
  85. data/test/#benchmark.txt# +7 -0
  86. data/test/#tc_helper.rb# +3 -0
  87. data/test/benchmark.rb +81 -0
  88. data/test/benchmark.rb~ +0 -0
  89. data/test/benchmark.txt +6 -0
  90. data/test/benchmark.txt~ +6 -0
  91. data/test/content_type/tc_content_type.rb +30 -32
  92. data/test/content_type/tc_default.rb +8 -23
  93. data/test/content_type/tc_override.rb +7 -21
  94. data/test/doc_props/tc_app.rb +2 -8
  95. data/test/doc_props/tc_core.rb +6 -7
  96. data/test/drawing/tc_axis.rb +7 -3
  97. data/test/drawing/tc_bar_3D_chart.rb +6 -7
  98. data/test/drawing/tc_bar_series.rb +4 -5
  99. data/test/drawing/tc_cat_axis.rb +2 -3
  100. data/test/drawing/tc_cat_axis_data.rb +2 -3
  101. data/test/drawing/tc_chart.rb +13 -14
  102. data/test/drawing/tc_drawing.rb +7 -8
  103. data/test/drawing/tc_graphic_frame.rb +3 -4
  104. data/test/drawing/tc_hyperlink.rb +2 -3
  105. data/test/drawing/tc_line_3d_chart.rb +5 -6
  106. data/test/drawing/tc_line_series.rb +3 -4
  107. data/test/drawing/tc_marker.rb +3 -4
  108. data/test/drawing/tc_one_cell_anchor.rb +6 -7
  109. data/test/drawing/tc_pic.rb +8 -9
  110. data/test/drawing/tc_picture_locking.rb +2 -3
  111. data/test/drawing/tc_pie_3D_chart.rb +5 -6
  112. data/test/drawing/tc_pie_series.rb +4 -5
  113. data/test/drawing/tc_scaling.rb +3 -4
  114. data/test/drawing/tc_scatter_chart.rb +43 -0
  115. data/test/drawing/tc_scatter_series.rb +20 -0
  116. data/test/drawing/tc_ser_axis.rb +2 -3
  117. data/test/drawing/tc_series.rb +4 -5
  118. data/test/drawing/tc_series_title.rb +4 -5
  119. data/test/drawing/tc_title.rb +4 -5
  120. data/test/drawing/tc_two_cell_anchor.rb +4 -5
  121. data/test/drawing/tc_val_axis.rb +2 -3
  122. data/test/drawing/tc_val_axis_data.rb +2 -3
  123. data/test/drawing/tc_view_3D.rb +6 -7
  124. data/test/example.csv +1000 -0
  125. data/test/example.xlsx +0 -0
  126. data/test/example_streamed.xlsx +0 -0
  127. data/test/profile.rb +33 -0
  128. data/test/rels/tc_relationship.rb +5 -6
  129. data/test/rels/tc_relationships.rb +4 -5
  130. data/test/stylesheet/tc_border.rb +3 -4
  131. data/test/stylesheet/tc_border_pr.rb +3 -4
  132. data/test/stylesheet/tc_cell_alignment.rb +10 -6
  133. data/test/stylesheet/tc_cell_protection.rb +2 -3
  134. data/test/stylesheet/tc_cell_style.rb +2 -3
  135. data/test/stylesheet/tc_color.rb +2 -3
  136. data/test/stylesheet/tc_fill.rb +1 -2
  137. data/test/stylesheet/tc_font.rb +12 -5
  138. data/test/stylesheet/tc_gradient_fill.rb +1 -2
  139. data/test/stylesheet/tc_gradient_stop.rb +1 -2
  140. data/test/stylesheet/tc_num_fmt.rb +1 -2
  141. data/test/stylesheet/tc_pattern_fill.rb +3 -4
  142. data/test/stylesheet/tc_styles.rb +16 -6
  143. data/test/stylesheet/tc_table_style.rb +2 -3
  144. data/test/stylesheet/tc_table_style_element.rb +2 -3
  145. data/test/stylesheet/tc_table_styles.rb +3 -4
  146. data/test/stylesheet/tc_xf.rb +16 -17
  147. data/test/tc_axlsx.rb +39 -0
  148. data/test/tc_axlsx.rb~ +0 -0
  149. data/test/tc_helper.rb +3 -0
  150. data/test/tc_helper.rb~ +3 -0
  151. data/test/tc_package.rb +13 -10
  152. data/test/util/tc_simple_typed_list.rb +8 -9
  153. data/test/util/tc_validators.rb +7 -8
  154. data/test/workbook/tc_shared_strings_table.rb +5 -6
  155. data/test/workbook/tc_workbook.rb +24 -6
  156. data/test/workbook/worksheet/table/tc_table.rb +71 -0
  157. data/test/workbook/worksheet/table/tc_table.rb~ +72 -0
  158. data/test/workbook/worksheet/tc_cell.rb +62 -18
  159. data/test/workbook/worksheet/tc_col.rb +59 -0
  160. data/test/workbook/worksheet/tc_col.rb~ +10 -0
  161. data/test/workbook/worksheet/tc_date_time_converter.rb +126 -0
  162. data/test/workbook/worksheet/tc_page_margins.rb +97 -0
  163. data/test/workbook/worksheet/tc_row.rb +54 -4
  164. data/test/workbook/worksheet/tc_worksheet.rb +177 -34
  165. metadata +69 -41
  166. data/test/drawing/tc_hyperlink.rb~ +0 -71
  167. data/test/workbook/tc_shared_strings_table.rb~ +0 -8
data/test/example.xlsx ADDED
Binary file
Binary file
data/test/profile.rb ADDED
@@ -0,0 +1,33 @@
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 = 1000
19
+
20
+ PerfTools::CpuProfiler.start("/tmp/axlsx_noautowidth") do
21
+ p = Axlsx::Package.new
22
+ p.use_autowidth = false
23
+ wb = p.workbook
24
+
25
+ #A Simple Workbook
26
+
27
+ wb.add_worksheet do |sheet|
28
+ times.times do
29
+ sheet << row
30
+ end
31
+ end
32
+ p.serialize("example.xlsx")
33
+ 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
- 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' }
@@ -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,14 @@ 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"} }
21
26
 
27
+ end
22
28
 
23
29
  def test_add_style
24
30
  fill_count = @styles.fills.size
@@ -42,11 +48,15 @@ class TestStyles < Test::Unit::TestCase
42
48
 
43
49
  assert(xf.alignment.is_a?(Axlsx::CellAlignment), "alignment was created")
44
50
  assert_equal(xf.alignment.horizontal, :left, "horizontal alignment applied")
45
- assert_equal(xf.applyProtection, 1, "protection applied")
46
51
  assert_equal(xf.protection.hidden, true, "hidden protection set")
47
52
  assert_equal(xf.protection.locked, true, "cell locking set")
48
53
  assert_raise(ArgumentError, "should reject invalid borderId") { @styles.add_style :border => 2 }
49
54
 
55
+
56
+ assert_equal(xf.applyProtection, 1, "protection applied")
57
+ assert_equal(xf.applyBorder, true, "border applied")
58
+ assert_equal(xf.applyNumberFormat, true, "number format applied")
59
+ assert_equal(xf.applyAlignment, true, "alignment applied")
50
60
  end
51
61
 
52
62
  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_axlsx.rb~ ADDED
File without changes
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"
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
+ require 'test/unit'
3
+ require "tc_helper.rb"
data/test/tc_package.rb CHANGED
@@ -1,8 +1,7 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestPackage < Test::Unit::TestCase
5
- def setup
4
+ def setup
6
5
  @package = Axlsx::Package.new
7
6
  ws = @package.workbook.add_worksheet
8
7
  chart = ws.add_chart Axlsx::Pie3DChart
@@ -39,16 +38,16 @@ class TestPackage < Test::Unit::TestCase
39
38
  fname = 'axlsx_test_serialization.xlsx'
40
39
  assert_nothing_raised do
41
40
  begin
42
- z= @package.serialize(@fname)
41
+ z= @package.serialize(@fname)
43
42
  zf = Zip::ZipFile.open(@fname)
44
43
  @package.send(:parts).each{ |part| zf.get_entry(part[:entry]) }
45
- File.delete(@fname)
44
+ File.delete(@fname)
46
45
  rescue Errno::EACCES
47
46
  puts "WARNING:: test_serialization requires write access."
48
47
  end
49
- end
48
+ end
50
49
  end
51
-
50
+
52
51
  def test_validation
53
52
  assert_equal(@package.validate.size, 0, @package.validate)
54
53
  #how to test for failure? the internal validations on the models are so strict I cant break anthing.....
@@ -58,7 +57,7 @@ class TestPackage < Test::Unit::TestCase
58
57
  p = @package.send(:parts)
59
58
  p.each do |part|
60
59
  #all parts must have :doc, :entry, :schema
61
- assert(part.keys.size == 3 && part.keys.reject{ |k| [:doc, :entry, :schema].include? k}.empty?)
60
+ assert(part.keys.size == 3 && part.keys.reject{ |k| [:doc, :entry, :schema].include? k}.empty?)
62
61
  end
63
62
  #all parts have an entry
64
63
  assert_equal(p.select{ |part| part[:entry] =~ /_rels\/\.rels/ }.size, 1, "rels missing")
@@ -76,7 +75,7 @@ class TestPackage < Test::Unit::TestCase
76
75
 
77
76
  #no mystery parts
78
77
  assert_equal(p.size, 12)
79
-
78
+
80
79
  end
81
80
 
82
81
  def test_shared_strings_requires_part
@@ -84,7 +83,7 @@ class TestPackage < Test::Unit::TestCase
84
83
  p = @package.send(:parts)
85
84
  assert_equal(p.select{ |part| part[:entry] =~/xl\/sharedStrings.xml/}.size, 1, "shared strings table missing")
86
85
  end
87
-
86
+
88
87
  def test_workbook_is_a_workbook
89
88
  assert @package.workbook.is_a? Axlsx::Workbook
90
89
  end
@@ -106,4 +105,8 @@ class TestPackage < Test::Unit::TestCase
106
105
  assert(ct.select { |ct| ct.ContentType == Axlsx::SHARED_STRINGS_CT }.size == 1)
107
106
  end
108
107
 
108
+ def test_name_to_indices
109
+ assert(Axlsx::name_to_indices('A1') == [0,0])
110
+ assert(Axlsx::name_to_indices('A100') == [0,99], 'needs to axcept rows that contain 0')
111
+ end
109
112
  end