writeexcel 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. data/README +26 -31
  2. data/examples/a_simple.rb +42 -42
  3. data/examples/{autofilters.rb → autofilter.rb} +264 -266
  4. data/examples/bigfile.rb +29 -0
  5. data/examples/chart_area.rb +120 -0
  6. data/examples/chart_bar.rb +119 -0
  7. data/examples/chart_column.rb +119 -0
  8. data/examples/chart_line.rb +119 -0
  9. data/examples/chart_pie.rb +107 -0
  10. data/examples/chart_scatter.rb +120 -0
  11. data/examples/chart_stock.rb +147 -0
  12. data/examples/copyformat.rb +51 -51
  13. data/examples/data_validate.rb +278 -278
  14. data/examples/date_time.rb +86 -86
  15. data/examples/defined_name.rb +31 -0
  16. data/examples/demo.rb +120 -118
  17. data/examples/diag_border.rb +35 -35
  18. data/examples/formats.rb +489 -489
  19. data/examples/header.rb +136 -136
  20. data/examples/hidden.rb +28 -28
  21. data/examples/hyperlink.rb +42 -42
  22. data/examples/images.rb +52 -52
  23. data/examples/merge1.rb +39 -39
  24. data/examples/merge2.rb +44 -44
  25. data/examples/merge3.rb +65 -65
  26. data/examples/merge4.rb +82 -82
  27. data/examples/merge5.rb +79 -79
  28. data/examples/properties.rb +33 -0
  29. data/examples/properties_jp.rb +32 -0
  30. data/examples/protection.rb +46 -46
  31. data/examples/regions.rb +52 -52
  32. data/examples/repeat.rb +42 -42
  33. data/examples/stats.rb +75 -75
  34. data/examples/stocks.rb +80 -80
  35. data/examples/tab_colors.rb +30 -30
  36. data/examples/write_arrays.rb +82 -0
  37. data/lib/writeexcel.rb +1134 -18
  38. data/lib/writeexcel/biffwriter.rb +273 -260
  39. data/lib/writeexcel/chart.rb +2306 -217
  40. data/lib/writeexcel/charts/area.rb +152 -0
  41. data/lib/writeexcel/charts/bar.rb +177 -0
  42. data/lib/writeexcel/charts/column.rb +156 -0
  43. data/lib/writeexcel/charts/external.rb +61 -0
  44. data/lib/writeexcel/charts/line.rb +152 -0
  45. data/lib/writeexcel/charts/pie.rb +169 -0
  46. data/lib/writeexcel/charts/scatter.rb +192 -0
  47. data/lib/writeexcel/charts/stock.rb +211 -0
  48. data/lib/writeexcel/excelformulaparser.rb +208 -195
  49. data/lib/writeexcel/format.rb +1697 -1108
  50. data/lib/writeexcel/formula.rb +1050 -986
  51. data/lib/writeexcel/olewriter.rb +322 -322
  52. data/lib/writeexcel/properties.rb +251 -250
  53. data/lib/writeexcel/storage_lite.rb +968 -0
  54. data/lib/writeexcel/workbook.rb +3294 -2630
  55. data/lib/writeexcel/worksheet.rb +9012 -6377
  56. data/test/excelfile/Chart1.xls +0 -0
  57. data/test/excelfile/Chart2.xls +0 -0
  58. data/test/excelfile/Chart3.xls +0 -0
  59. data/test/excelfile/Chart4.xls +0 -0
  60. data/test/excelfile/Chart5.xls +0 -0
  61. data/test/perl_output/Chart1.xls.data +0 -0
  62. data/test/perl_output/Chart2.xls.data +0 -0
  63. data/test/perl_output/Chart3.xls.data +0 -0
  64. data/test/perl_output/Chart4.xls.data +0 -0
  65. data/test/perl_output/Chart5.xls.data +0 -0
  66. data/test/perl_output/a_simple.xls +0 -0
  67. data/test/perl_output/autofilter.xls +0 -0
  68. data/test/perl_output/chart_area.xls +0 -0
  69. data/test/perl_output/chart_bar.xls +0 -0
  70. data/test/perl_output/chart_column.xls +0 -0
  71. data/test/perl_output/chart_line.xls +0 -0
  72. data/test/perl_output/data_validate.xls +0 -0
  73. data/test/perl_output/date_time.xls +0 -0
  74. data/test/perl_output/demo.xls +0 -0
  75. data/test/perl_output/demo101.bin +0 -0
  76. data/test/perl_output/demo201.bin +0 -0
  77. data/test/perl_output/demo301.bin +0 -0
  78. data/test/perl_output/demo401.bin +0 -0
  79. data/test/perl_output/demo501.bin +0 -0
  80. data/test/perl_output/diag_border.xls +0 -0
  81. data/test/perl_output/headers.xls +0 -0
  82. data/test/perl_output/hyperlink.xls +0 -0
  83. data/test/perl_output/images.xls +0 -0
  84. data/test/perl_output/merge1.xls +0 -0
  85. data/test/perl_output/merge2.xls +0 -0
  86. data/test/perl_output/merge3.xls +0 -0
  87. data/test/perl_output/merge4.xls +0 -0
  88. data/test/perl_output/merge5.xls +0 -0
  89. data/test/perl_output/protection.xls +0 -0
  90. data/test/perl_output/regions.xls +0 -0
  91. data/test/perl_output/stats.xls +0 -0
  92. data/test/perl_output/stocks.xls +0 -0
  93. data/test/perl_output/tab_colors.xls +0 -0
  94. data/test/perl_output/unicode_cyrillic.xls +0 -0
  95. data/test/perl_output/workbook1.xls +0 -0
  96. data/test/perl_output/workbook2.xls +0 -0
  97. data/test/tc_all.rb +32 -31
  98. data/test/tc_biff.rb +104 -104
  99. data/test/tc_chart.rb +22 -22
  100. data/test/tc_example_match.rb +1944 -1280
  101. data/test/tc_format.rb +1254 -1267
  102. data/test/tc_formula.rb +63 -63
  103. data/test/tc_ole.rb +110 -110
  104. data/test/tc_storage_lite.rb +149 -0
  105. data/test/tc_workbook.rb +140 -115
  106. data/test/tc_worksheet.rb +115 -115
  107. data/test/test_00_IEEE_double.rb +14 -14
  108. data/test/test_01_add_worksheet.rb +12 -12
  109. data/test/test_02_merge_formats.rb +58 -58
  110. data/test/test_04_dimensions.rb +397 -397
  111. data/test/test_05_rows.rb +182 -182
  112. data/test/test_06_extsst.rb +80 -80
  113. data/test/test_11_date_time.rb +484 -484
  114. data/test/test_12_date_only.rb +506 -506
  115. data/test/test_13_date_seconds.rb +486 -486
  116. data/test/test_21_escher.rb +642 -629
  117. data/test/test_22_mso_drawing_group.rb +750 -739
  118. data/test/test_23_note.rb +78 -78
  119. data/test/test_24_txo.rb +80 -80
  120. data/test/test_25_position_object.rb +82 -0
  121. data/test/test_26_autofilter.rb +327 -327
  122. data/test/test_27_autofilter.rb +144 -144
  123. data/test/test_28_autofilter.rb +174 -174
  124. data/test/test_29_process_jpg.rb +681 -131
  125. data/test/test_30_validation_dval.rb +82 -82
  126. data/test/test_31_validation_dv_strings.rb +131 -131
  127. data/test/test_32_validation_dv_formula.rb +211 -211
  128. data/test/test_40_property_types.rb +191 -191
  129. data/test/test_41_properties.rb +238 -238
  130. data/test/test_42_set_properties.rb +442 -419
  131. data/test/test_50_name_stored.rb +305 -0
  132. data/test/test_51_name_print_area.rb +363 -0
  133. data/test/test_52_name_print_titles.rb +460 -0
  134. data/test/test_53_autofilter.rb +209 -0
  135. data/test/test_60_chart_generic.rb +576 -0
  136. data/test/test_61_chart_subclasses.rb +97 -0
  137. data/test/test_62_chart_formats.rb +270 -0
  138. data/test/test_63_chart_area_formats.rb +647 -0
  139. data/test/test_chartex.rb +35 -0
  140. data/test/ts_all.rb +46 -34
  141. data/writeexcel.gemspec +18 -0
  142. data/writeexcel.rdoc +583 -0
  143. metadata +162 -108
@@ -1,14 +1,14 @@
1
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
-
3
- require "test/unit"
4
-
5
- class TC_BIFFWriter < Test::Unit::TestCase
6
-
7
- def test_IEEE_double
8
- teststr = [1.2345].pack("d")
9
- hexdata = [0x8D, 0x97, 0x6E, 0x12, 0x83, 0xC0, 0xF3, 0x3F]
10
- number = hexdata.pack("C8")
11
-
12
- assert(number == teststr || number == teststr.reverse, "Not Little/Big endian. Give up.")
13
- end
14
- end
1
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
+
3
+ require "test/unit"
4
+
5
+ class TC_BIFFWriter < Test::Unit::TestCase
6
+
7
+ def test_IEEE_double
8
+ teststr = [1.2345].pack("d")
9
+ hexdata = [0x8D, 0x97, 0x6E, 0x12, 0x83, 0xC0, 0xF3, 0x3F]
10
+ number = hexdata.pack("C8")
11
+
12
+ assert(number == teststr || number == teststr.reverse, "Not Little/Big endian. Give up.")
13
+ end
14
+ end
@@ -1,12 +1,12 @@
1
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
-
3
- require "test/unit"
4
- require 'writeexcel'
5
-
6
- class TC_add_worksheet < Test::Unit::TestCase
7
-
8
- def test_true
9
- assert(true)
10
- end
11
-
12
- end
1
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
+
3
+ require "test/unit"
4
+ require 'writeexcel'
5
+
6
+ class TC_add_worksheet < Test::Unit::TestCase
7
+
8
+ def test_true
9
+ assert(true)
10
+ end
11
+
12
+ end
@@ -1,58 +1,58 @@
1
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
-
3
- require "test/unit"
4
- require 'writeexcel'
5
-
6
- class TC_merge_formats < Test::Unit::TestCase
7
-
8
- def setup
9
- t = Time.now.strftime("%Y%m%d")
10
- path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
11
- @test_file = File.join(Dir.tmpdir, path)
12
- @workbook = Spreadsheet::WriteExcel.new(@test_file)
13
- @worksheet = @workbook.add_worksheet
14
- @merged_format = @workbook.add_format(:bold => 1)
15
- @non_merged_format = @workbook.add_format(:bold => 1)
16
-
17
- @worksheet.set_row( 5, nil, @merged_format)
18
- @worksheet.set_column('G:G', nil, @merged_format)
19
- end
20
-
21
- def teardown
22
- @workbook.close
23
- File.unlink(@test_file) if FileTest.exist?(@test_file)
24
- end
25
-
26
- def test_some
27
- # Test 1 Normal usage.
28
- assert_nothing_raised { @worksheet.write('A1', 'Test', @non_merged_format) }
29
- assert_nothing_raised { @worksheet.write('A3:B4', 'Test', @merged_format) }
30
-
31
- # Test 2 Non merge format in merged cells.
32
- assert_nothing_raised {
33
- @worksheet.merge_range('D3:E4', 'Test', @non_merged_format)
34
- }
35
-
36
- # Test 3 Merge format in column.
37
- assert_nothing_raised { @worksheet.write('G1', 'Test') }
38
-
39
- # Test 4 Merge format in row.
40
- assert_nothing_raised { @worksheet.write('A6', 'Test') }
41
-
42
- # Test 5 Merge format in column and row.
43
- assert_nothing_raised { @worksheet.write('G6', 'Test') }
44
-
45
- # Test 6 No merge format in column and row.
46
- assert_nothing_raised { @worksheet.write('H7', 'Test') }
47
-
48
- # Test 7 Normal usage again.
49
- assert_nothing_raised {
50
- @worksheet.write('A1', 'Test', @non_merged_format)
51
- }
52
- assert_nothing_raised {
53
- @worksheet.merge_range('A3:B4', 'Test', @merged_format)
54
- }
55
- end
56
-
57
-
58
- end
1
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
+
3
+ require "test/unit"
4
+ require 'writeexcel'
5
+
6
+ class TC_merge_formats < Test::Unit::TestCase
7
+
8
+ def setup
9
+ t = Time.now.strftime("%Y%m%d")
10
+ path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
11
+ @test_file = File.join(Dir.tmpdir, path)
12
+ @workbook = WriteExcel.new(@test_file)
13
+ @worksheet = @workbook.add_worksheet
14
+ @merged_format = @workbook.add_format(:bold => 1)
15
+ @non_merged_format = @workbook.add_format(:bold => 1)
16
+
17
+ @worksheet.set_row( 5, nil, @merged_format)
18
+ @worksheet.set_column('G:G', nil, @merged_format)
19
+ end
20
+
21
+ def teardown
22
+ @workbook.close
23
+ File.unlink(@test_file) if FileTest.exist?(@test_file)
24
+ end
25
+
26
+ def test_some
27
+ # Test 1 Normal usage.
28
+ assert_nothing_raised { @worksheet.write('A1', 'Test', @non_merged_format) }
29
+ assert_nothing_raised { @worksheet.write('A3:B4', 'Test', @merged_format) }
30
+
31
+ # Test 2 Non merge format in merged cells.
32
+ assert_nothing_raised {
33
+ @worksheet.merge_range('D3:E4', 'Test', @non_merged_format)
34
+ }
35
+
36
+ # Test 3 Merge format in column.
37
+ assert_nothing_raised { @worksheet.write('G1', 'Test') }
38
+
39
+ # Test 4 Merge format in row.
40
+ assert_nothing_raised { @worksheet.write('A6', 'Test') }
41
+
42
+ # Test 5 Merge format in column and row.
43
+ assert_nothing_raised { @worksheet.write('G6', 'Test') }
44
+
45
+ # Test 6 No merge format in column and row.
46
+ assert_nothing_raised { @worksheet.write('H7', 'Test') }
47
+
48
+ # Test 7 Normal usage again.
49
+ assert_nothing_raised {
50
+ @worksheet.write('A1', 'Test', @non_merged_format)
51
+ }
52
+ assert_nothing_raised {
53
+ @worksheet.merge_range('A3:B4', 'Test', @merged_format)
54
+ }
55
+ end
56
+
57
+
58
+ end
@@ -1,397 +1,397 @@
1
- ###############################################################################
2
- #
3
- # A test for Spreadsheet::WriteExcel.
4
- #
5
- # Check that the Excel DIMENSIONS record is written correctly.
6
- #
7
- # reverse('©'), October 2007, John McNamara, jmcnamara@cpan.org
8
- #
9
- # original written in Perl by John McNamara
10
- # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
11
- #
12
- ############################################################################
13
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
14
-
15
- require "test/unit"
16
- require 'writeexcel'
17
-
18
- class TC_dimensions < Test::Unit::TestCase
19
-
20
- def setup
21
- t = Time.now.strftime("%Y%m%d")
22
- path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
23
- @test_file = File.join(Dir.tmpdir, path)
24
- @workbook = Spreadsheet::WriteExcel.new(@test_file)
25
- @worksheet = @workbook.add_worksheet
26
- @format = @workbook.add_format
27
- @dims = ['row_min', 'row_max', 'col_min', 'col_max']
28
- @smiley = [0x263a].pack('n')
29
- end
30
-
31
- def teardown
32
- @workbook.close
33
- File.unlink(@test_file) if FileTest.exist?(@test_file)
34
- end
35
-
36
- def test_no_worksheet_cell_data
37
- data = @worksheet.store_dimensions
38
-
39
- vals = data.unpack('x4 VVvv')
40
- alist = @dims.zip(vals)
41
- results = Hash[*alist.flatten]
42
-
43
- alist = @dims.zip([0, 0, 0, 0])
44
- expected = Hash[*alist.flatten]
45
-
46
- assert_equal(expected, results)
47
- end
48
-
49
- def test_data_in_cell_0_0
50
- @worksheet.write(0, 0, 'Test')
51
- data = @worksheet.store_dimensions
52
-
53
- vals = data.unpack('x4 VVvv')
54
- alist = @dims.zip(vals)
55
- results = Hash[*alist.flatten]
56
-
57
- alist = @dims.zip([0, 1, 0, 1])
58
- expected = Hash[*alist.flatten]
59
-
60
- assert_equal(expected, results)
61
- end
62
-
63
- def test_data_in_cell_0_255
64
- @worksheet.write(0, 255, 'Test')
65
- data = @worksheet.store_dimensions
66
-
67
- vals = data.unpack('x4 VVvv')
68
- alist = @dims.zip(vals)
69
- results = Hash[*alist.flatten]
70
-
71
- alist = @dims.zip([0, 1, 255, 256])
72
- expected = Hash[*alist.flatten]
73
-
74
- assert_equal(expected, results)
75
- end
76
-
77
- def test_data_in_cell_65535_0
78
- @worksheet.write(65535, 0, 'Test')
79
- data = @worksheet.store_dimensions
80
-
81
- vals = data.unpack('x4 VVvv')
82
- alist = @dims.zip(vals)
83
- results = Hash[*alist.flatten]
84
-
85
- alist = @dims.zip([65535, 65536, 0, 1])
86
- expected = Hash[*alist.flatten]
87
-
88
- assert_equal(expected, results)
89
- end
90
-
91
- def test_data_in_cell_65535_255
92
- @worksheet.write(65535, 255, 'Test')
93
- data = @worksheet.store_dimensions
94
-
95
- vals = data.unpack('x4 VVvv')
96
- alist = @dims.zip(vals)
97
- results = Hash[*alist.flatten]
98
-
99
- alist = @dims.zip([65535, 65536, 255, 256])
100
- expected = Hash[*alist.flatten]
101
-
102
- assert_equal(expected, results)
103
- end
104
-
105
- def test_set_row_for_row_4
106
- @worksheet.set_row(4, 20)
107
- data = @worksheet.store_dimensions
108
-
109
- vals = data.unpack('x4 VVvv')
110
- alist = @dims.zip(vals)
111
- results = Hash[*alist.flatten]
112
-
113
- alist = @dims.zip([4, 5, 0, 0])
114
- expected = Hash[*alist.flatten]
115
-
116
- assert_equal(expected, results)
117
- end
118
-
119
- def test_set_row_for_row_4_to_6
120
- @worksheet.set_row(4, 20)
121
- @worksheet.set_row(5, 20)
122
- @worksheet.set_row(6, 20)
123
- data = @worksheet.store_dimensions
124
-
125
- vals = data.unpack('x4 VVvv')
126
- alist = @dims.zip(vals)
127
- results = Hash[*alist.flatten]
128
-
129
- alist = @dims.zip([4, 7, 0, 0])
130
- expected = Hash[*alist.flatten]
131
-
132
- assert_equal(expected, results)
133
- end
134
-
135
- def test_set_column_for_row_4
136
- @worksheet.set_column(4, 4, 20)
137
- data = @worksheet.store_dimensions
138
-
139
- vals = data.unpack('x4 VVvv')
140
- alist = @dims.zip(vals)
141
- results = Hash[*alist.flatten]
142
-
143
- alist = @dims.zip([0, 0, 0, 0])
144
- expected = Hash[*alist.flatten]
145
-
146
- assert_equal(expected, results)
147
- end
148
-
149
- def test_data_in_cell_0_0_and_set_row_for_row_4
150
- @worksheet.write(0, 0, 'Test')
151
- @worksheet.set_row(4, 20)
152
- data = @worksheet.store_dimensions
153
-
154
- vals = data.unpack('x4 VVvv')
155
- alist = @dims.zip(vals)
156
- results = Hash[*alist.flatten]
157
-
158
- alist = @dims.zip([0, 5, 0, 1])
159
- expected = Hash[*alist.flatten]
160
-
161
- assert_equal(expected, results)
162
- end
163
-
164
- def test_data_in_cell_0_0_and_set_row_for_row_4_reverse_order
165
- @worksheet.set_row(4, 20)
166
- @worksheet.write(0, 0, 'Test')
167
- data = @worksheet.store_dimensions
168
-
169
- vals = data.unpack('x4 VVvv')
170
- alist = @dims.zip(vals)
171
- results = Hash[*alist.flatten]
172
-
173
- alist = @dims.zip([0, 5, 0, 1])
174
- expected = Hash[*alist.flatten]
175
-
176
- assert_equal(expected, results)
177
- end
178
-
179
- def test_data_in_cell_5_3_and_set_row_for_row_4
180
- @worksheet.write(5, 3, 'Test')
181
- @worksheet.set_row(4, 20)
182
- data = @worksheet.store_dimensions
183
-
184
- vals = data.unpack('x4 VVvv')
185
- alist = @dims.zip(vals)
186
- results = Hash[*alist.flatten]
187
-
188
- alist = @dims.zip([4, 6, 3, 4])
189
- expected = Hash[*alist.flatten]
190
-
191
- assert_equal(expected, results)
192
- end
193
-
194
- def test_comment_in_cell_5_3
195
- @worksheet.write_comment(5, 3, 'Test')
196
- data = @worksheet.store_dimensions
197
-
198
- vals = data.unpack('x4 VVvv')
199
- alist = @dims.zip(vals)
200
- results = Hash[*alist.flatten]
201
-
202
- alist = @dims.zip([5, 6, 3, 4])
203
- expected = Hash[*alist.flatten]
204
-
205
- assert_equal(expected, results)
206
- end
207
-
208
- def test_nil_value_for_row
209
- error = @worksheet.write_string(nil, 1, 'Test')
210
- data = @worksheet.store_dimensions
211
-
212
- vals = data.unpack('x4 VVvv')
213
- alist = @dims.zip(vals)
214
- results = Hash[*alist.flatten]
215
-
216
- alist = @dims.zip([0, 0, 0, 0])
217
- expected = Hash[*alist.flatten]
218
-
219
- assert_equal(expected, results)
220
- assert_equal(-2, error)
221
- end
222
-
223
- def test_data_in_cell_5_3_and_10_1
224
- @worksheet.write( 5, 3, 'Test')
225
- @worksheet.write(10, 1, 'Test')
226
- data = @worksheet.store_dimensions
227
-
228
- vals = data.unpack('x4 VVvv')
229
- alist = @dims.zip(vals)
230
- results = Hash[*alist.flatten]
231
-
232
- alist = @dims.zip([5, 11, 1, 4])
233
- expected = Hash[*alist.flatten]
234
-
235
- assert_equal(expected, results)
236
- end
237
-
238
- def test_data_in_cell_5_3_and_10_5
239
- @worksheet.write( 5, 3, 'Test')
240
- @worksheet.write(10, 5, 'Test')
241
- data = @worksheet.store_dimensions
242
-
243
- vals = data.unpack('x4 VVvv')
244
- alist = @dims.zip(vals)
245
- results = Hash[*alist.flatten]
246
-
247
- alist = @dims.zip([5, 11, 3, 6])
248
- expected = Hash[*alist.flatten]
249
-
250
- assert_equal(expected, results)
251
- end
252
-
253
- def test_write_string
254
- @worksheet.write_string(5, 3, 'Test')
255
- data = @worksheet.store_dimensions
256
-
257
- vals = data.unpack('x4 VVvv')
258
- alist = @dims.zip(vals)
259
- results = Hash[*alist.flatten]
260
-
261
- alist = @dims.zip([5, 6, 3, 4])
262
- expected = Hash[*alist.flatten]
263
-
264
- assert_equal(expected, results)
265
- end
266
-
267
- def test_write_number
268
- @worksheet.write_number(5, 3, 5)
269
- data = @worksheet.store_dimensions
270
-
271
- vals = data.unpack('x4 VVvv')
272
- alist = @dims.zip(vals)
273
- results = Hash[*alist.flatten]
274
-
275
- alist = @dims.zip([5, 6, 3, 4])
276
- expected = Hash[*alist.flatten]
277
-
278
- assert_equal(expected, results)
279
- end
280
-
281
- def test_write_url
282
- @worksheet.write_url(5, 3, 'http://www.ruby.com')
283
- data = @worksheet.store_dimensions
284
-
285
- vals = data.unpack('x4 VVvv')
286
- alist = @dims.zip(vals)
287
- results = Hash[*alist.flatten]
288
-
289
- alist = @dims.zip([5, 6, 3, 4])
290
- expected = Hash[*alist.flatten]
291
-
292
- assert_equal(expected, results)
293
- end
294
-
295
- def test_write_formula
296
- @worksheet.write_formula(5, 3, ' 1 + 2')
297
- data = @worksheet.store_dimensions
298
-
299
- vals = data.unpack('x4 VVvv')
300
- alist = @dims.zip(vals)
301
- results = Hash[*alist.flatten]
302
-
303
- alist = @dims.zip([5, 6, 3, 4])
304
- expected = Hash[*alist.flatten]
305
-
306
- assert_equal(expected, results)
307
- end
308
-
309
- def test_write_blank
310
- @worksheet.write_string(5, 3, @format)
311
- data = @worksheet.store_dimensions
312
-
313
- vals = data.unpack('x4 VVvv')
314
- alist = @dims.zip(vals)
315
- results = Hash[*alist.flatten]
316
-
317
- alist = @dims.zip([5, 6, 3, 4])
318
- expected = Hash[*alist.flatten]
319
-
320
- assert_equal(expected, results)
321
- end
322
-
323
- def test_write_blank_no_format
324
- @worksheet.write_string(5, 3)
325
- data = @worksheet.store_dimensions
326
-
327
- vals = data.unpack('x4 VVvv')
328
- alist = @dims.zip(vals)
329
- results = Hash[*alist.flatten]
330
-
331
- alist = @dims.zip([0, 0, 0, 0])
332
- expected = Hash[*alist.flatten]
333
-
334
- assert_equal(expected, results)
335
- end
336
-
337
- def test_write_utf16be_string
338
- @worksheet.write_utf16be_string(5, 3, @smiley)
339
- data = @worksheet.store_dimensions
340
-
341
- vals = data.unpack('x4 VVvv')
342
- alist = @dims.zip(vals)
343
- results = Hash[*alist.flatten]
344
-
345
- alist = @dims.zip([5, 6, 3, 4])
346
- expected = Hash[*alist.flatten]
347
-
348
- assert_equal(expected, results)
349
- end
350
-
351
- def test_write_utf16le_string
352
- @worksheet.write_utf16le_string(5, 3, @smiley)
353
- data = @worksheet.store_dimensions
354
-
355
- vals = data.unpack('x4 VVvv')
356
- alist = @dims.zip(vals)
357
- results = Hash[*alist.flatten]
358
-
359
- alist = @dims.zip([5, 6, 3, 4])
360
- expected = Hash[*alist.flatten]
361
-
362
- assert_equal(expected, results)
363
- end
364
-
365
- def test_repeat_formula
366
- formula = @worksheet.store_formula('=A1 * 3 + 50')
367
- @worksheet.repeat_formula(5, 3, formula, @format, 'A1', 'A2')
368
-
369
- data = @worksheet.store_dimensions
370
-
371
- vals = data.unpack('x4 VVvv')
372
- alist = @dims.zip(vals)
373
- results = Hash[*alist.flatten]
374
-
375
- alist = @dims.zip([5, 6, 3, 4])
376
- expected = Hash[*alist.flatten]
377
-
378
- assert_equal(expected, results)
379
- end
380
-
381
- def test_merge_range
382
- formula = @worksheet.store_formula('=A1 * 3 + 50')
383
- @worksheet.merge_range('C6:E8', 'Test', @format)
384
-
385
- data = @worksheet.store_dimensions
386
-
387
- vals = data.unpack('x4 VVvv')
388
- alist = @dims.zip(vals)
389
- results = Hash[*alist.flatten]
390
-
391
- alist = @dims.zip([5, 8, 2, 5])
392
- expected = Hash[*alist.flatten]
393
-
394
- assert_equal(expected, results)
395
- end
396
-
397
- end
1
+ ###############################################################################
2
+ #
3
+ # A test for WriteExcel.
4
+ #
5
+ # Check that the Excel DIMENSIONS record is written correctly.
6
+ #
7
+ # reverse('©'), October 2007, John McNamara, jmcnamara@cpan.org
8
+ #
9
+ # original written in Perl by John McNamara
10
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
11
+ #
12
+ ############################################################################
13
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
14
+
15
+ require "test/unit"
16
+ require 'writeexcel'
17
+
18
+ class TC_dimensions < Test::Unit::TestCase
19
+
20
+ def setup
21
+ t = Time.now.strftime("%Y%m%d")
22
+ path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
23
+ @test_file = File.join(Dir.tmpdir, path)
24
+ @workbook = WriteExcel.new(@test_file)
25
+ @worksheet = @workbook.add_worksheet
26
+ @format = @workbook.add_format
27
+ @dims = ['row_min', 'row_max', 'col_min', 'col_max']
28
+ @smiley = [0x263a].pack('n')
29
+ end
30
+
31
+ def teardown
32
+ @workbook.close
33
+ File.unlink(@test_file) if FileTest.exist?(@test_file)
34
+ end
35
+
36
+ def test_no_worksheet_cell_data
37
+ data = @worksheet.store_dimensions
38
+
39
+ vals = data.unpack('x4 VVvv')
40
+ alist = @dims.zip(vals)
41
+ results = Hash[*alist.flatten]
42
+
43
+ alist = @dims.zip([0, 0, 0, 0])
44
+ expected = Hash[*alist.flatten]
45
+
46
+ assert_equal(expected, results)
47
+ end
48
+
49
+ def test_data_in_cell_0_0
50
+ @worksheet.write(0, 0, 'Test')
51
+ data = @worksheet.store_dimensions
52
+
53
+ vals = data.unpack('x4 VVvv')
54
+ alist = @dims.zip(vals)
55
+ results = Hash[*alist.flatten]
56
+
57
+ alist = @dims.zip([0, 1, 0, 1])
58
+ expected = Hash[*alist.flatten]
59
+
60
+ assert_equal(expected, results)
61
+ end
62
+
63
+ def test_data_in_cell_0_255
64
+ @worksheet.write(0, 255, 'Test')
65
+ data = @worksheet.store_dimensions
66
+
67
+ vals = data.unpack('x4 VVvv')
68
+ alist = @dims.zip(vals)
69
+ results = Hash[*alist.flatten]
70
+
71
+ alist = @dims.zip([0, 1, 255, 256])
72
+ expected = Hash[*alist.flatten]
73
+
74
+ assert_equal(expected, results)
75
+ end
76
+
77
+ def test_data_in_cell_65535_0
78
+ @worksheet.write(65535, 0, 'Test')
79
+ data = @worksheet.store_dimensions
80
+
81
+ vals = data.unpack('x4 VVvv')
82
+ alist = @dims.zip(vals)
83
+ results = Hash[*alist.flatten]
84
+
85
+ alist = @dims.zip([65535, 65536, 0, 1])
86
+ expected = Hash[*alist.flatten]
87
+
88
+ assert_equal(expected, results)
89
+ end
90
+
91
+ def test_data_in_cell_65535_255
92
+ @worksheet.write(65535, 255, 'Test')
93
+ data = @worksheet.store_dimensions
94
+
95
+ vals = data.unpack('x4 VVvv')
96
+ alist = @dims.zip(vals)
97
+ results = Hash[*alist.flatten]
98
+
99
+ alist = @dims.zip([65535, 65536, 255, 256])
100
+ expected = Hash[*alist.flatten]
101
+
102
+ assert_equal(expected, results)
103
+ end
104
+
105
+ def test_set_row_for_row_4
106
+ @worksheet.set_row(4, 20)
107
+ data = @worksheet.store_dimensions
108
+
109
+ vals = data.unpack('x4 VVvv')
110
+ alist = @dims.zip(vals)
111
+ results = Hash[*alist.flatten]
112
+
113
+ alist = @dims.zip([4, 5, 0, 0])
114
+ expected = Hash[*alist.flatten]
115
+
116
+ assert_equal(expected, results)
117
+ end
118
+
119
+ def test_set_row_for_row_4_to_6
120
+ @worksheet.set_row(4, 20)
121
+ @worksheet.set_row(5, 20)
122
+ @worksheet.set_row(6, 20)
123
+ data = @worksheet.store_dimensions
124
+
125
+ vals = data.unpack('x4 VVvv')
126
+ alist = @dims.zip(vals)
127
+ results = Hash[*alist.flatten]
128
+
129
+ alist = @dims.zip([4, 7, 0, 0])
130
+ expected = Hash[*alist.flatten]
131
+
132
+ assert_equal(expected, results)
133
+ end
134
+
135
+ def test_set_column_for_row_4
136
+ @worksheet.set_column(4, 4, 20)
137
+ data = @worksheet.store_dimensions
138
+
139
+ vals = data.unpack('x4 VVvv')
140
+ alist = @dims.zip(vals)
141
+ results = Hash[*alist.flatten]
142
+
143
+ alist = @dims.zip([0, 0, 0, 0])
144
+ expected = Hash[*alist.flatten]
145
+
146
+ assert_equal(expected, results)
147
+ end
148
+
149
+ def test_data_in_cell_0_0_and_set_row_for_row_4
150
+ @worksheet.write(0, 0, 'Test')
151
+ @worksheet.set_row(4, 20)
152
+ data = @worksheet.store_dimensions
153
+
154
+ vals = data.unpack('x4 VVvv')
155
+ alist = @dims.zip(vals)
156
+ results = Hash[*alist.flatten]
157
+
158
+ alist = @dims.zip([0, 5, 0, 1])
159
+ expected = Hash[*alist.flatten]
160
+
161
+ assert_equal(expected, results)
162
+ end
163
+
164
+ def test_data_in_cell_0_0_and_set_row_for_row_4_reverse_order
165
+ @worksheet.set_row(4, 20)
166
+ @worksheet.write(0, 0, 'Test')
167
+ data = @worksheet.store_dimensions
168
+
169
+ vals = data.unpack('x4 VVvv')
170
+ alist = @dims.zip(vals)
171
+ results = Hash[*alist.flatten]
172
+
173
+ alist = @dims.zip([0, 5, 0, 1])
174
+ expected = Hash[*alist.flatten]
175
+
176
+ assert_equal(expected, results)
177
+ end
178
+
179
+ def test_data_in_cell_5_3_and_set_row_for_row_4
180
+ @worksheet.write(5, 3, 'Test')
181
+ @worksheet.set_row(4, 20)
182
+ data = @worksheet.store_dimensions
183
+
184
+ vals = data.unpack('x4 VVvv')
185
+ alist = @dims.zip(vals)
186
+ results = Hash[*alist.flatten]
187
+
188
+ alist = @dims.zip([4, 6, 3, 4])
189
+ expected = Hash[*alist.flatten]
190
+
191
+ assert_equal(expected, results)
192
+ end
193
+
194
+ def test_comment_in_cell_5_3
195
+ @worksheet.write_comment(5, 3, 'Test')
196
+ data = @worksheet.store_dimensions
197
+
198
+ vals = data.unpack('x4 VVvv')
199
+ alist = @dims.zip(vals)
200
+ results = Hash[*alist.flatten]
201
+
202
+ alist = @dims.zip([5, 6, 3, 4])
203
+ expected = Hash[*alist.flatten]
204
+
205
+ assert_equal(expected, results)
206
+ end
207
+
208
+ def test_nil_value_for_row
209
+ error = @worksheet.write_string(nil, 1, 'Test')
210
+ data = @worksheet.store_dimensions
211
+
212
+ vals = data.unpack('x4 VVvv')
213
+ alist = @dims.zip(vals)
214
+ results = Hash[*alist.flatten]
215
+
216
+ alist = @dims.zip([0, 0, 0, 0])
217
+ expected = Hash[*alist.flatten]
218
+
219
+ assert_equal(expected, results)
220
+ assert_equal(-2, error)
221
+ end
222
+
223
+ def test_data_in_cell_5_3_and_10_1
224
+ @worksheet.write( 5, 3, 'Test')
225
+ @worksheet.write(10, 1, 'Test')
226
+ data = @worksheet.store_dimensions
227
+
228
+ vals = data.unpack('x4 VVvv')
229
+ alist = @dims.zip(vals)
230
+ results = Hash[*alist.flatten]
231
+
232
+ alist = @dims.zip([5, 11, 1, 4])
233
+ expected = Hash[*alist.flatten]
234
+
235
+ assert_equal(expected, results)
236
+ end
237
+
238
+ def test_data_in_cell_5_3_and_10_5
239
+ @worksheet.write( 5, 3, 'Test')
240
+ @worksheet.write(10, 5, 'Test')
241
+ data = @worksheet.store_dimensions
242
+
243
+ vals = data.unpack('x4 VVvv')
244
+ alist = @dims.zip(vals)
245
+ results = Hash[*alist.flatten]
246
+
247
+ alist = @dims.zip([5, 11, 3, 6])
248
+ expected = Hash[*alist.flatten]
249
+
250
+ assert_equal(expected, results)
251
+ end
252
+
253
+ def test_write_string
254
+ @worksheet.write_string(5, 3, 'Test')
255
+ data = @worksheet.store_dimensions
256
+
257
+ vals = data.unpack('x4 VVvv')
258
+ alist = @dims.zip(vals)
259
+ results = Hash[*alist.flatten]
260
+
261
+ alist = @dims.zip([5, 6, 3, 4])
262
+ expected = Hash[*alist.flatten]
263
+
264
+ assert_equal(expected, results)
265
+ end
266
+
267
+ def test_write_number
268
+ @worksheet.write_number(5, 3, 5)
269
+ data = @worksheet.store_dimensions
270
+
271
+ vals = data.unpack('x4 VVvv')
272
+ alist = @dims.zip(vals)
273
+ results = Hash[*alist.flatten]
274
+
275
+ alist = @dims.zip([5, 6, 3, 4])
276
+ expected = Hash[*alist.flatten]
277
+
278
+ assert_equal(expected, results)
279
+ end
280
+
281
+ def test_write_url
282
+ @worksheet.write_url(5, 3, 'http://www.ruby.com')
283
+ data = @worksheet.store_dimensions
284
+
285
+ vals = data.unpack('x4 VVvv')
286
+ alist = @dims.zip(vals)
287
+ results = Hash[*alist.flatten]
288
+
289
+ alist = @dims.zip([5, 6, 3, 4])
290
+ expected = Hash[*alist.flatten]
291
+
292
+ assert_equal(expected, results)
293
+ end
294
+
295
+ def test_write_formula
296
+ @worksheet.write_formula(5, 3, ' 1 + 2')
297
+ data = @worksheet.store_dimensions
298
+
299
+ vals = data.unpack('x4 VVvv')
300
+ alist = @dims.zip(vals)
301
+ results = Hash[*alist.flatten]
302
+
303
+ alist = @dims.zip([5, 6, 3, 4])
304
+ expected = Hash[*alist.flatten]
305
+
306
+ assert_equal(expected, results)
307
+ end
308
+
309
+ def test_write_blank
310
+ @worksheet.write_string(5, 3, @format)
311
+ data = @worksheet.store_dimensions
312
+
313
+ vals = data.unpack('x4 VVvv')
314
+ alist = @dims.zip(vals)
315
+ results = Hash[*alist.flatten]
316
+
317
+ alist = @dims.zip([5, 6, 3, 4])
318
+ expected = Hash[*alist.flatten]
319
+
320
+ assert_equal(expected, results)
321
+ end
322
+
323
+ def test_write_blank_no_format
324
+ @worksheet.write_string(5, 3)
325
+ data = @worksheet.store_dimensions
326
+
327
+ vals = data.unpack('x4 VVvv')
328
+ alist = @dims.zip(vals)
329
+ results = Hash[*alist.flatten]
330
+
331
+ alist = @dims.zip([0, 0, 0, 0])
332
+ expected = Hash[*alist.flatten]
333
+
334
+ assert_equal(expected, results)
335
+ end
336
+
337
+ def test_write_utf16be_string
338
+ @worksheet.write_utf16be_string(5, 3, @smiley)
339
+ data = @worksheet.store_dimensions
340
+
341
+ vals = data.unpack('x4 VVvv')
342
+ alist = @dims.zip(vals)
343
+ results = Hash[*alist.flatten]
344
+
345
+ alist = @dims.zip([5, 6, 3, 4])
346
+ expected = Hash[*alist.flatten]
347
+
348
+ assert_equal(expected, results)
349
+ end
350
+
351
+ def test_write_utf16le_string
352
+ @worksheet.write_utf16le_string(5, 3, @smiley)
353
+ data = @worksheet.store_dimensions
354
+
355
+ vals = data.unpack('x4 VVvv')
356
+ alist = @dims.zip(vals)
357
+ results = Hash[*alist.flatten]
358
+
359
+ alist = @dims.zip([5, 6, 3, 4])
360
+ expected = Hash[*alist.flatten]
361
+
362
+ assert_equal(expected, results)
363
+ end
364
+
365
+ def test_repeat_formula
366
+ formula = @worksheet.store_formula('=A1 * 3 + 50')
367
+ @worksheet.repeat_formula(5, 3, formula, @format, 'A1', 'A2')
368
+
369
+ data = @worksheet.store_dimensions
370
+
371
+ vals = data.unpack('x4 VVvv')
372
+ alist = @dims.zip(vals)
373
+ results = Hash[*alist.flatten]
374
+
375
+ alist = @dims.zip([5, 6, 3, 4])
376
+ expected = Hash[*alist.flatten]
377
+
378
+ assert_equal(expected, results)
379
+ end
380
+
381
+ def test_merge_range
382
+ formula = @worksheet.store_formula('=A1 * 3 + 50')
383
+ @worksheet.merge_range('C6:E8', 'Test', @format)
384
+
385
+ data = @worksheet.store_dimensions
386
+
387
+ vals = data.unpack('x4 VVvv')
388
+ alist = @dims.zip(vals)
389
+ results = Hash[*alist.flatten]
390
+
391
+ alist = @dims.zip([5, 8, 2, 5])
392
+ expected = Hash[*alist.flatten]
393
+
394
+ assert_equal(expected, results)
395
+ end
396
+
397
+ end