axlsx 1.0.12 → 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/README.md +7 -3
  2. data/lib/axlsx.rb +57 -0
  3. data/lib/axlsx/content_type/content_type.rb +23 -0
  4. data/lib/axlsx/content_type/default.rb +37 -0
  5. data/lib/axlsx/content_type/override.rb +37 -0
  6. data/lib/axlsx/doc_props/app.rb +178 -0
  7. data/lib/axlsx/doc_props/core.rb +34 -0
  8. data/lib/axlsx/drawing/axis.rb +90 -0
  9. data/lib/axlsx/drawing/bar_3D_chart.rb +128 -0
  10. data/lib/axlsx/drawing/bar_series.rb +64 -0
  11. data/lib/axlsx/drawing/cat_axis.rb +63 -0
  12. data/lib/axlsx/drawing/cat_axis_data.rb +35 -0
  13. data/lib/axlsx/drawing/chart.rb +179 -0
  14. data/lib/axlsx/drawing/drawing.rb +137 -0
  15. data/lib/axlsx/drawing/graphic_frame.rb +52 -0
  16. data/lib/axlsx/drawing/line_3D_chart.rb +106 -0
  17. data/lib/axlsx/drawing/line_series.rb +46 -0
  18. data/lib/axlsx/drawing/marker.rb +61 -0
  19. data/lib/axlsx/drawing/one_cell_anchor.rb +89 -0
  20. data/lib/axlsx/drawing/pic.rb +153 -0
  21. data/lib/axlsx/drawing/picture_locking.rb +72 -0
  22. data/lib/axlsx/drawing/picture_locking.rb~ +36 -0
  23. data/lib/axlsx/drawing/pie_3D_chart.rb +41 -0
  24. data/lib/axlsx/drawing/pie_series.rb +56 -0
  25. data/lib/axlsx/drawing/scaling.rb +59 -0
  26. data/lib/axlsx/drawing/ser_axis.rb +45 -0
  27. data/lib/axlsx/drawing/series.rb +71 -0
  28. data/lib/axlsx/drawing/series_title.rb +22 -0
  29. data/lib/axlsx/drawing/title.rb +61 -0
  30. data/lib/axlsx/drawing/two_cell_anchor.rb +76 -0
  31. data/lib/axlsx/drawing/val_axis.rb +34 -0
  32. data/lib/axlsx/drawing/val_axis_data.rb +28 -0
  33. data/lib/axlsx/drawing/view_3D.rb +85 -0
  34. data/lib/axlsx/package.rb +215 -0
  35. data/lib/axlsx/rels/relationship.rb +44 -0
  36. data/lib/axlsx/rels/relationships.rb +25 -0
  37. data/lib/axlsx/stylesheet/border.rb +57 -0
  38. data/lib/axlsx/stylesheet/border_pr.rb +68 -0
  39. data/lib/axlsx/stylesheet/cell_alignment.rb +105 -0
  40. data/lib/axlsx/stylesheet/cell_protection.rb +36 -0
  41. data/lib/axlsx/stylesheet/cell_style.rb +65 -0
  42. data/lib/axlsx/stylesheet/color.rb +69 -0
  43. data/lib/axlsx/stylesheet/fill.rb +32 -0
  44. data/lib/axlsx/stylesheet/font.rb +139 -0
  45. data/lib/axlsx/stylesheet/gradient_fill.rb +76 -0
  46. data/lib/axlsx/stylesheet/gradient_stop.rb +33 -0
  47. data/lib/axlsx/stylesheet/num_fmt.rb +63 -0
  48. data/lib/axlsx/stylesheet/pattern_fill.rb +66 -0
  49. data/lib/axlsx/stylesheet/styles.rb +298 -0
  50. data/lib/axlsx/stylesheet/table_style.rb +47 -0
  51. data/lib/axlsx/stylesheet/table_style_element.rb +71 -0
  52. data/lib/axlsx/stylesheet/table_styles.rb +39 -0
  53. data/lib/axlsx/stylesheet/xf.rb +138 -0
  54. data/lib/axlsx/util/constants.rb +220 -0
  55. data/lib/axlsx/util/parser.rb +43 -0
  56. data/lib/axlsx/util/parser.rb~ +6 -0
  57. data/lib/axlsx/util/simple_typed_list.rb +160 -0
  58. data/lib/axlsx/util/validators.rb +132 -0
  59. data/lib/axlsx/version.rb +4 -0
  60. data/lib/axlsx/workbook/#workbook.rb# +165 -0
  61. data/lib/axlsx/workbook/workbook.rb +160 -0
  62. data/lib/axlsx/workbook/worksheet/cell.rb +337 -0
  63. data/lib/axlsx/workbook/worksheet/row.rb +107 -0
  64. data/lib/axlsx/workbook/worksheet/worksheet.rb +279 -0
  65. metadata +93 -141
  66. data/examples/follow_20111202.xlsx +0 -0
  67. data/test/content_type/tc_content_type.rb +0 -81
  68. data/test/content_type/tc_default.rb +0 -40
  69. data/test/content_type/tc_override.rb +0 -40
  70. data/test/doc_props/tc_app.rb +0 -19
  71. data/test/doc_props/tc_core.rb +0 -34
  72. data/test/drawing/tc_axis.rb +0 -40
  73. data/test/drawing/tc_bar_3D_chart.rb +0 -66
  74. data/test/drawing/tc_bar_series.rb +0 -34
  75. data/test/drawing/tc_cat_axis.rb +0 -32
  76. data/test/drawing/tc_cat_axis_data.rb +0 -18
  77. data/test/drawing/tc_chart.rb +0 -73
  78. data/test/drawing/tc_drawing.rb +0 -80
  79. data/test/drawing/tc_graphic_frame.rb +0 -26
  80. data/test/drawing/tc_line_3d_chart.rb +0 -48
  81. data/test/drawing/tc_line_series.rb +0 -27
  82. data/test/drawing/tc_marker.rb +0 -45
  83. data/test/drawing/tc_one_cell_anchor.rb +0 -67
  84. data/test/drawing/tc_pic.rb +0 -71
  85. data/test/drawing/tc_picture_locking.rb +0 -73
  86. data/test/drawing/tc_pie_3D_chart.rb +0 -33
  87. data/test/drawing/tc_pie_series.rb +0 -35
  88. data/test/drawing/tc_scaling.rb +0 -37
  89. data/test/drawing/tc_ser_axis.rb +0 -31
  90. data/test/drawing/tc_series.rb +0 -24
  91. data/test/drawing/tc_series_title.rb +0 -34
  92. data/test/drawing/tc_title.rb +0 -34
  93. data/test/drawing/tc_two_cell_anchor.rb +0 -38
  94. data/test/drawing/tc_val_axis.rb +0 -25
  95. data/test/drawing/tc_val_axis_data.rb +0 -18
  96. data/test/drawing/tc_view_3D.rb +0 -55
  97. data/test/rels/tc_relationship.rb +0 -16
  98. data/test/rels/tc_relationships.rb +0 -27
  99. data/test/stylesheet/tc_border.rb +0 -38
  100. data/test/stylesheet/tc_border_pr.rb +0 -33
  101. data/test/stylesheet/tc_cell_alignment.rb +0 -77
  102. data/test/stylesheet/tc_cell_protection.rb +0 -30
  103. data/test/stylesheet/tc_cell_style.rb +0 -58
  104. data/test/stylesheet/tc_color.rb +0 -38
  105. data/test/stylesheet/tc_fill.rb +0 -19
  106. data/test/stylesheet/tc_font.rb +0 -114
  107. data/test/stylesheet/tc_gradient_fill.rb +0 -65
  108. data/test/stylesheet/tc_gradient_stop.rb +0 -32
  109. data/test/stylesheet/tc_num_fmt.rb +0 -31
  110. data/test/stylesheet/tc_pattern_fill.rb +0 -38
  111. data/test/stylesheet/tc_styles.rb +0 -52
  112. data/test/stylesheet/tc_table_style.rb +0 -37
  113. data/test/stylesheet/tc_table_style_element.rb +0 -37
  114. data/test/stylesheet/tc_table_styles.rb +0 -30
  115. data/test/stylesheet/tc_xf.rb +0 -121
  116. data/test/tc_package.rb +0 -68
  117. data/test/util/tc_simple_typed_list.rb +0 -66
  118. data/test/util/tc_validators.rb +0 -76
  119. data/test/workbook/tc_workbook.rb +0 -60
  120. data/test/workbook/worksheet/tc_cell.rb +0 -179
  121. data/test/workbook/worksheet/tc_row.rb +0 -36
  122. data/test/workbook/worksheet/tc_worksheet.rb +0 -138
@@ -1,76 +0,0 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
3
- class TestValidators < Test::Unit::TestCase
4
- def setup
5
- end
6
- def teardown
7
- end
8
-
9
- def test_validators
10
- #unsigned_int
11
- assert_nothing_raised { Axlsx.validate_unsigned_int 1 }
12
- assert_nothing_raised { Axlsx.validate_unsigned_int +1 }
13
- assert_raise(ArgumentError) { Axlsx.validate_unsigned_int -1 }
14
- assert_raise(ArgumentError) { Axlsx.validate_unsigned_int '1' }
15
-
16
- #int
17
- assert_nothing_raised { Axlsx.validate_int 1 }
18
- assert_nothing_raised { Axlsx.validate_int -1 }
19
- assert_raise(ArgumentError) { Axlsx.validate_int 'a' }
20
- assert_raise(ArgumentError) { Axlsx.validate_int Array }
21
-
22
- #boolean (as 0 or 1, :true, :false, true, false, or "true," "false")
23
- [0,1,:true, :false, true, false, "true", "false"].each do |v|
24
- assert_nothing_raised { Axlsx.validate_boolean 0 }
25
- end
26
- assert_raise(ArgumentError) { Axlsx.validate_boolean 2 }
27
-
28
- #string
29
- assert_nothing_raised { Axlsx.validate_string "1" }
30
- assert_raise(ArgumentError) { Axlsx.validate_string 2 }
31
- assert_raise(ArgumentError) { Axlsx.validate_string false }
32
-
33
- #float
34
- assert_nothing_raised { Axlsx.validate_float 1.0 }
35
- assert_raise(ArgumentError) { Axlsx.validate_float 2 }
36
- assert_raise(ArgumentError) { Axlsx.validate_float false }
37
-
38
- #pattern_type
39
- assert_nothing_raised { Axlsx.validate_pattern_type :none }
40
- assert_raise(ArgumentError) { Axlsx.validate_pattern_type "none" }
41
- assert_raise(ArgumentError) { Axlsx.validate_pattern_type "crazy_pattern" }
42
- assert_raise(ArgumentError) { Axlsx.validate_pattern_type false }
43
-
44
- #gradient_type
45
- assert_nothing_raised { Axlsx.validate_gradient_type :path }
46
- assert_raise(ArgumentError) { Axlsx.validate_gradient_type nil }
47
- assert_raise(ArgumentError) { Axlsx.validate_gradient_type "fractal" }
48
- assert_raise(ArgumentError) { Axlsx.validate_gradient_type false }
49
-
50
- #horizontal alignment
51
- assert_nothing_raised { Axlsx.validate_horizontal_alignment :general }
52
- assert_raise(ArgumentError) { Axlsx.validate_horizontal_alignment nil }
53
- assert_raise(ArgumentError) { Axlsx.validate_horizontal_alignment "wavy" }
54
- assert_raise(ArgumentError) { Axlsx.validate_horizontal_alignment false }
55
-
56
- #vertical alignment
57
- assert_nothing_raised { Axlsx.validate_vertical_alignment :top }
58
- assert_raise(ArgumentError) { Axlsx.validate_vertical_alignment nil }
59
- assert_raise(ArgumentError) { Axlsx.validate_vertical_alignment "dynamic" }
60
- assert_raise(ArgumentError) { Axlsx.validate_vertical_alignment false }
61
-
62
- #contentType
63
- assert_nothing_raised { Axlsx.validate_content_type Axlsx::WORKBOOK_CT }
64
- assert_raise(ArgumentError) { Axlsx.validate_content_type nil }
65
- assert_raise(ArgumentError) { Axlsx.validate_content_type "http://some.url" }
66
- assert_raise(ArgumentError) { Axlsx.validate_content_type false }
67
-
68
- #relationshipType
69
- assert_nothing_raised { Axlsx.validate_relationship_type Axlsx::WORKBOOK_R }
70
- assert_raise(ArgumentError) { Axlsx.validate_relationship_type nil }
71
- assert_raise(ArgumentError) { Axlsx.validate_relationship_type "http://some.url" }
72
- assert_raise(ArgumentError) { Axlsx.validate_relationship_type false }
73
-
74
- end
75
- end
76
-
@@ -1,60 +0,0 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
3
-
4
- class TestWorkbook < Test::Unit::TestCase
5
- def setup
6
- p = Axlsx::Package.new
7
- @wb = p.workbook
8
- end
9
-
10
- def teardown
11
- end
12
-
13
- def test_date1904
14
- assert_equal(Axlsx::Workbook.date1904, @wb.date1904)
15
- @wb.date1904 = :false
16
- assert_equal(Axlsx::Workbook.date1904, @wb.date1904)
17
- Axlsx::Workbook.date1904 = :true
18
- assert_equal(Axlsx::Workbook.date1904, @wb.date1904)
19
- end
20
-
21
- def test_add_worksheet
22
- assert(@wb.worksheets.empty?, "worbook has no worksheets by default")
23
- ws = @wb.add_worksheet(:name=>"bob")
24
- assert_equal(@wb.worksheets.size, 1, "add_worksheet adds a worksheet!")
25
- assert_equal(@wb.worksheets.first, ws, "the worksheet returned is the worksheet added")
26
- assert_equal(ws.name, "bob", "name option gets passed to worksheet")
27
- end
28
- def test_relationships
29
- #current relationship size is 1 due to style relation
30
- assert(@wb.relationships.size == 1)
31
- @wb.add_worksheet
32
- assert(@wb.relationships.size == 2)
33
- end
34
-
35
- def test_to_xml
36
- schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
37
- doc = Nokogiri::XML(@wb.to_xml)
38
- errors = []
39
- schema.validate(doc).each do |error|
40
- errors.push error
41
- puts error.message
42
- end
43
- assert(errors.empty?, "error free validation")
44
- end
45
- def test_range_requires__valid_sheet
46
- ws = @wb.add_worksheet :name=>'fish'
47
- ws.add_row [1,2,3]
48
- ws.add_row [4,5,6]
49
- assert_raise(ArgumentError, "no sheet name part") { @wb["A1:C2"]}
50
- assert_equal @wb['fish!A1:C2'].size, 6
51
- end
52
-
53
- def test_to_xml_adds_worksheet_when_worksheets_is_empty
54
- assert(@wb.worksheets.empty?)
55
- @wb.to_xml
56
- assert(@wb.worksheets.size == 1)
57
- end
58
-
59
-
60
- end
@@ -1,179 +0,0 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
3
-
4
- class TestCell < Test::Unit::TestCase
5
-
6
- def setup
7
- p = Axlsx::Package.new
8
- @ws = p.workbook.add_worksheet :name=>"hmmm"
9
- p.workbook.styles.add_style :sz=>20
10
- @row = @ws.add_row
11
- @c = @row.add_cell 1, :type=>:float, :style=>1
12
- end
13
-
14
- def test_initialize
15
- assert_equal(@row.cells.last, @c, "the cell was added to the row")
16
- assert_equal(@c.type, :float, "type option is applied")
17
- assert_equal(@c.style, 1, "style option is applied")
18
- assert_equal(@c.value, 1.0, "type option is applied and value is casted")
19
- end
20
-
21
- def test_style_date_data
22
- c = Axlsx::Cell.new(@c.row, Time.now)
23
- assert_equal(Axlsx::STYLE_DATE, c.style)
24
- end
25
-
26
- def test_index
27
- assert_equal(@c.index, @row.cells.index(@c))
28
- end
29
-
30
- def test_index
31
- assert_equal(@c.pos, [@c.index, @c.row.index])
32
- end
33
-
34
- def test_r
35
- assert_equal(@c.r, "A1", "calculate cell reference")
36
- end
37
-
38
- def test_r_abs
39
- assert_equal(@c.r_abs,"$A$1", "calculate absolute cell reference")
40
- end
41
-
42
- def test_style
43
- assert_raise(ArgumentError, "must reject invalid style indexes") { @c.style=@c.row.worksheet.workbook.styles.cellXfs.size }
44
- assert_nothing_raised("must allow valid style index changes") {@c.style=1}
45
- assert_equal(@c.style, 1)
46
- end
47
-
48
- def test_type
49
- assert_raise(ArgumentError, "type must be :string, :integer, :float, :time") { @c.type = :array }
50
- assert_nothing_raised("type can be changed") { @c.type = :string }
51
- assert_equal(@c.value, "1.0", "changing type casts the value")
52
-
53
- assert_equal(@row.add_cell(Time.now).type, :time, 'time should be time')
54
- end
55
-
56
- def test_value
57
- assert_raise(ArgumentError, "type must be :string, :integer, :float, :time") { @c.type = :array }
58
- assert_nothing_raised("type can be changed") { @c.type = :string }
59
- assert_equal(@c.value, "1.0", "changing type casts the value")
60
- end
61
-
62
- def test_col_ref
63
- assert_equal(@c.send(:col_ref), "A")
64
- end
65
-
66
- def test_cell_type_from_value
67
- assert_equal(@c.send(:cell_type_from_value, 1.0), :float)
68
- assert_equal(@c.send(:cell_type_from_value, 1), :integer)
69
- assert_equal(@c.send(:cell_type_from_value, Time.now), :time)
70
- assert_equal(@c.send(:cell_type_from_value, []), :string)
71
- assert_equal(@c.send(:cell_type_from_value, "d"), :string)
72
- assert_equal(@c.send(:cell_type_from_value, nil), :string)
73
- assert_equal(@c.send(:cell_type_from_value, -1), :integer)
74
- end
75
-
76
- def test_cast_value
77
- @c.type = :string
78
- assert_equal(@c.send(:cast_value, 1.0), "1.0")
79
- @c.type = :integer
80
- assert_equal(@c.send(:cast_value, 1.0), 1)
81
- @c.type = :float
82
- assert_equal(@c.send(:cast_value, "1.0"), 1.0)
83
- @c.type = :string
84
- assert_equal(@c.send(:cast_value, nil), "")
85
-
86
- end
87
-
88
- def test_color
89
- assert_raise(ArgumentError) { @c.color = -1.1 }
90
- assert_nothing_raised { @c.color = "FF00FF00" }
91
- assert_equal(@c.color.rgb, "FF00FF00")
92
- end
93
-
94
- def test_scheme
95
- assert_raise(ArgumentError) { @c.scheme = -1.1 }
96
- assert_nothing_raised { @c.scheme = :major }
97
- assert_equal(@c.scheme, :major)
98
- end
99
-
100
- def test_vertAlign
101
- assert_raise(ArgumentError) { @c.vertAlign = -1.1 }
102
- assert_nothing_raised { @c.vertAlign = :baseline }
103
- assert_equal(@c.vertAlign, :baseline)
104
- end
105
-
106
- def test_sz
107
- assert_raise(ArgumentError) { @c.sz = -1.1 }
108
- assert_nothing_raised { @c.sz = 12 }
109
- assert_equal(@c.sz, 12)
110
- end
111
-
112
- def test_extend
113
- assert_raise(ArgumentError) { @c.extend = -1.1 }
114
- assert_nothing_raised { @c.extend = false }
115
- assert_equal(@c.extend, false)
116
- end
117
-
118
- def test_condense
119
- assert_raise(ArgumentError) { @c.condense = -1.1 }
120
- assert_nothing_raised { @c.condense = false }
121
- assert_equal(@c.condense, false)
122
- end
123
-
124
- def test_shadow
125
- assert_raise(ArgumentError) { @c.shadow = -1.1 }
126
- assert_nothing_raised { @c.shadow = false }
127
- assert_equal(@c.shadow, false)
128
- end
129
-
130
- def test_outline
131
- assert_raise(ArgumentError) { @c.outline = -1.1 }
132
- assert_nothing_raised { @c.outline = false }
133
- assert_equal(@c.outline, false)
134
- end
135
-
136
- def test_strike
137
- assert_raise(ArgumentError) { @c.strike = -1.1 }
138
- assert_nothing_raised { @c.strike = false }
139
- assert_equal(@c.strike, false)
140
- end
141
-
142
- def test_u
143
- assert_raise(ArgumentError) { @c.u = -1.1 }
144
- assert_nothing_raised { @c.u = false }
145
- assert_equal(@c.u, false)
146
- end
147
-
148
- def test_i
149
- assert_raise(ArgumentError) { @c.i = -1.1 }
150
- assert_nothing_raised { @c.i = false }
151
- assert_equal(@c.i, false)
152
- end
153
-
154
- def test_rFont
155
- assert_raise(ArgumentError) { @c.font_name = -1.1 }
156
- assert_nothing_raised { @c.font_name = "Arial" }
157
- assert_equal(@c.font_name, "Arial")
158
- end
159
-
160
- def test_charset
161
- assert_raise(ArgumentError) { @c.charset = -1.1 }
162
- assert_nothing_raised { @c.charset = 1 }
163
- assert_equal(@c.charset, 1)
164
- end
165
-
166
- def test_family
167
- assert_raise(ArgumentError) { @c.family = -1.1 }
168
- assert_nothing_raised { @c.family = "Who knows!" }
169
- assert_equal(@c.family, "Who knows!")
170
- end
171
-
172
- def test_b
173
- assert_raise(ArgumentError) { @c.b = -1.1 }
174
- assert_nothing_raised { @c.b = false }
175
- assert_equal(@c.b, false)
176
- end
177
-
178
-
179
- end
@@ -1,36 +0,0 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
3
-
4
- class TestRow < Test::Unit::TestCase
5
-
6
- def setup
7
- p = Axlsx::Package.new
8
- @ws = p.workbook.add_worksheet :name=>"hmmm"
9
- @row = @ws.add_row
10
- end
11
-
12
- def test_initialize
13
- assert(@row.cells.empty?, "no cells by default")
14
- assert_equal(@row.worksheet, @ws, "has a reference to the worksheet")
15
- end
16
-
17
- def test_style
18
- r = @ws.add_row([1,2,3,4,5])
19
- r.style=1
20
- r.cells.each { |c| assert_equal(c.style,1) }
21
- end
22
-
23
- def test_index
24
- assert_equal(@row.index, @row.worksheet.rows.index(@row))
25
- end
26
-
27
- def test_add_cell
28
- c = @row.add_cell(1)
29
- assert_equal(@row.cells.last, c)
30
- end
31
-
32
- def test_array_to_cells
33
- r = @ws.add_row [1,2,3], :style=>0, :types=>:integer
34
- assert_equal(r.cells.size, 3)
35
- end
36
- end
@@ -1,138 +0,0 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
3
-
4
- class TestWorksheet < Test::Unit::TestCase
5
- def setup
6
- p = Axlsx::Package.new
7
- @ws = p.workbook.add_worksheet
8
- end
9
-
10
- def test_pn
11
- assert_equal(@ws.pn, "worksheets/sheet1.xml")
12
- ws = @ws.workbook.add_worksheet
13
- assert_equal(ws.pn, "worksheets/sheet2.xml")
14
- end
15
-
16
- def test_rels_pn
17
- assert_equal(@ws.rels_pn, "worksheets/_rels/sheet1.xml.rels")
18
- ws = @ws.workbook.add_worksheet
19
- assert_equal(ws.rels_pn, "worksheets/_rels/sheet2.xml.rels")
20
- end
21
-
22
- def test_rId
23
- assert_equal(@ws.rId, "rId1")
24
- ws = @ws.workbook.add_worksheet
25
- assert_equal(ws.rId, "rId2")
26
- end
27
-
28
- def test_index
29
- assert_equal(@ws.index, @ws.workbook.worksheets.index(@ws))
30
- end
31
-
32
- def test_referencing
33
- @ws.add_row [1, 2, 3]
34
- @ws.add_row [4, 5, 6]
35
- range = @ws["A1:C2"]
36
- assert_equal(range.size, 6)
37
- assert_equal(range.first, @ws.rows.first.cells.first)
38
- assert_equal(range.last, @ws.rows.last.cells.last)
39
- end
40
-
41
- def test_add_row
42
- assert(@ws.rows.empty?, "sheet has no rows by default")
43
- r = @ws.add_row([1,2,3])
44
- assert_equal(@ws.rows.size, 1, "add_row adds a row")
45
- assert_equal(@ws.rows.first, r, "the row returned is the row added")
46
- end
47
-
48
- def test_add_chart
49
- assert(@ws.workbook.charts.empty?, "the sheet's workbook should not have any charts by default")
50
- @ws.add_chart Axlsx::Pie3DChart
51
- assert_equal(@ws.workbook.charts.size, 1, "add_chart adds a chart to the workbook")
52
- end
53
-
54
- def test_drawing
55
- assert @ws.drawing.is_a? Axlsx::Drawing
56
- end
57
-
58
- def test_col_style
59
- @ws.add_row [1,2,3,4]
60
- @ws.add_row [1,2,3,4]
61
- @ws.add_row [1,2,3,4]
62
- @ws.add_row [1,2,3,4]
63
- @ws.col_style( (1..2), 1, :row_offset=>1)
64
- @ws.rows[(1..-1)].each do | r |
65
- assert_equal(r.cells[1].style, 1)
66
- assert_equal(r.cells[2].style, 1)
67
- end
68
- assert_equal(@ws.rows.first.cells[1].style, 0)
69
- assert_equal(@ws.rows.first.cells[0].style, 0)
70
- end
71
-
72
- def test_cols
73
- @ws.add_row [1,2,3,4]
74
- @ws.add_row [1,2,3,4]
75
- @ws.add_row [1,2,3,4]
76
- @ws.add_row [1,2,3,4]
77
- c = @ws.cols[1]
78
- assert_equal(c.size, 4)
79
- assert_equal(c[0].value, 2)
80
- end
81
-
82
- def test_row_style
83
- @ws.add_row [1,2,3,4]
84
- @ws.add_row [1,2,3,4]
85
- @ws.add_row [1,2,3,4]
86
- @ws.add_row [1,2,3,4]
87
- @ws.row_style 1, 1, :col_offset=>1
88
- @ws.rows[1].cells[(1..-1)].each do | c |
89
- assert_equal(c.style, 1)
90
- end
91
- assert_equal(@ws.rows[1].cells[0].style, 0)
92
- assert_equal(@ws.rows[2].cells[1].style, 0)
93
- end
94
-
95
- def test_to_xml
96
- schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
97
- doc = Nokogiri::XML(@ws.to_xml)
98
- errors = []
99
- schema.validate(doc).each do |error|
100
- errors.push error
101
- puts error.message
102
- end
103
- assert(errors.empty?, "error free validation")
104
- end
105
-
106
- def test_relationships
107
- assert(@ws.relationships.empty?, "No Drawing relationship until you add a chart")
108
- c = @ws.add_chart Axlsx::Pie3DChart
109
- assert_equal(@ws.relationships.size, 1, "adding a chart creates the relationship")
110
- c = @ws.add_chart Axlsx::Pie3DChart
111
- assert_equal(@ws.relationships.size, 1, "multiple charts still only result in one relationship")
112
- end
113
-
114
-
115
- def test_name_unique
116
- assert_raise(ArgumentError, "worksheet name must be unique") { n = @ws.name; @ws.workbook.add_worksheet(:name=> @ws) }
117
- end
118
-
119
- def test_update_auto_with_data
120
- small = @ws.workbook.styles.add_style(:sz=>2)
121
- big = @ws.workbook.styles.add_style(:sz=>10)
122
-
123
- @ws.add_row ["chasing windmills", "penut"], :style=>small
124
- assert(@ws.auto_fit_data.size == 2, "a data item for each column")
125
-
126
- assert_equal(@ws.auto_fit_data[0], {:sz=>2,:longest=>"chasing windmills"}, "adding a row updates auto_fit_data if the product of the string length and font is greater for the column")
127
-
128
-
129
- @ws.add_row ["mule"], :style=>big
130
- assert_equal(@ws.auto_fit_data[0], {:sz=>10,:longest=>"mule"}, "adding a row updates auto_fit_data if the product of the string length and font is greater for the column")
131
- end
132
-
133
- def test_auto_width
134
- assert(@ws.send(:auto_width, {:sz=>11, :longest=>"fisheries"}) > @ws.send(:auto_width, {:sz=>11, :longest=>"fish"}), "longer strings get a longer auto_width at the same font size")
135
- assert(@ws.send(:auto_width, {:sz=>12, :longest=>"fish"}) > @ws.send(:auto_width, {:sz=>11, :longest=>"fish"}), "larger font size gets a longer auto_width using the same text")
136
- end
137
-
138
- end