WriteExcel 0.2.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 (80) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +17 -0
  5. data/Rakefile +47 -0
  6. data/VERSION +1 -0
  7. data/examples/a_simple.rb +42 -0
  8. data/examples/autofilters.rb +266 -0
  9. data/examples/bigfile.rb +30 -0
  10. data/examples/copyformat.rb +51 -0
  11. data/examples/data_validate.rb +278 -0
  12. data/examples/date_time.rb +86 -0
  13. data/examples/demo.rb +118 -0
  14. data/examples/diag_border.rb +35 -0
  15. data/examples/formats.rb +489 -0
  16. data/examples/header.rb +136 -0
  17. data/examples/hidden.rb +28 -0
  18. data/examples/hyperlink.rb +42 -0
  19. data/examples/images.rb +52 -0
  20. data/examples/merge1.rb +39 -0
  21. data/examples/merge2.rb +44 -0
  22. data/examples/merge3.rb +65 -0
  23. data/examples/merge4.rb +82 -0
  24. data/examples/merge5.rb +79 -0
  25. data/examples/protection.rb +46 -0
  26. data/examples/regions.rb +52 -0
  27. data/examples/repeat.rb +42 -0
  28. data/examples/stats.rb +75 -0
  29. data/examples/stocks.rb +80 -0
  30. data/examples/tab_colors.rb +30 -0
  31. data/lib/WriteExcel.rb +30 -0
  32. data/lib/WriteExcel/biffwriter.rb +259 -0
  33. data/lib/WriteExcel/chart.rb +217 -0
  34. data/lib/WriteExcel/excelformula.y +138 -0
  35. data/lib/WriteExcel/excelformulaparser.rb +573 -0
  36. data/lib/WriteExcel/format.rb +1108 -0
  37. data/lib/WriteExcel/formula.rb +986 -0
  38. data/lib/WriteExcel/olewriter.rb +322 -0
  39. data/lib/WriteExcel/properties.rb +250 -0
  40. data/lib/WriteExcel/storage_lite.rb +590 -0
  41. data/lib/WriteExcel/workbook.rb +2602 -0
  42. data/lib/WriteExcel/worksheet.rb +6378 -0
  43. data/spec/WriteExcel_spec.rb +7 -0
  44. data/spec/spec.opts +1 -0
  45. data/spec/spec_helper.rb +9 -0
  46. data/test/tc_all.rb +31 -0
  47. data/test/tc_biff.rb +104 -0
  48. data/test/tc_chart.rb +22 -0
  49. data/test/tc_example_match.rb +1280 -0
  50. data/test/tc_format.rb +1264 -0
  51. data/test/tc_formula.rb +63 -0
  52. data/test/tc_ole.rb +110 -0
  53. data/test/tc_storage_lite.rb +102 -0
  54. data/test/tc_workbook.rb +115 -0
  55. data/test/tc_worksheet.rb +115 -0
  56. data/test/test_00_IEEE_double.rb +14 -0
  57. data/test/test_01_add_worksheet.rb +12 -0
  58. data/test/test_02_merge_formats.rb +58 -0
  59. data/test/test_04_dimensions.rb +397 -0
  60. data/test/test_05_rows.rb +182 -0
  61. data/test/test_06_extsst.rb +80 -0
  62. data/test/test_11_date_time.rb +484 -0
  63. data/test/test_12_date_only.rb +506 -0
  64. data/test/test_13_date_seconds.rb +486 -0
  65. data/test/test_21_escher.rb +629 -0
  66. data/test/test_22_mso_drawing_group.rb +739 -0
  67. data/test/test_23_note.rb +78 -0
  68. data/test/test_24_txo.rb +80 -0
  69. data/test/test_26_autofilter.rb +327 -0
  70. data/test/test_27_autofilter.rb +144 -0
  71. data/test/test_28_autofilter.rb +174 -0
  72. data/test/test_29_process_jpg.rb +131 -0
  73. data/test/test_30_validation_dval.rb +82 -0
  74. data/test/test_31_validation_dv_strings.rb +131 -0
  75. data/test/test_32_validation_dv_formula.rb +211 -0
  76. data/test/test_40_property_types.rb +191 -0
  77. data/test/test_41_properties.rb +238 -0
  78. data/test/test_42_set_properties.rb +430 -0
  79. data/test/ts_all.rb +34 -0
  80. metadata +154 -0
@@ -0,0 +1,78 @@
1
+ ##########################################################################
2
+ # test_23_note.rb
3
+ #
4
+ # Tests for some of the internal method used to write the NOTE record that
5
+ # is used in cell comments.
6
+ #
7
+ # reverse('©'), September 2005, 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_note < 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
+ end
27
+
28
+ def teardown
29
+ @workbook.close
30
+ File.unlink(@test_file) if FileTest.exist?(@test_file)
31
+ end
32
+
33
+ def test_blank_author_name
34
+ data = @worksheet.comment_params(2,0,'Test')
35
+ row = data[0]
36
+ col = data[1]
37
+ author = data[4]
38
+ encoding = data[5]
39
+ visible = data[6]
40
+ obj_id = 1
41
+
42
+ caption = sprintf(" \tstore_note")
43
+ target = %w(
44
+ 1C 00 0C 00 02 00 00 00 00 00 01 00 00 00 00 00
45
+ ).join(' ')
46
+ result = unpack_record(
47
+ @worksheet.store_note(row,col,obj_id,author,encoding,visible))
48
+ assert_equal(target, result, caption)
49
+ end
50
+
51
+ def test_defined_author_name
52
+ data = @worksheet.comment_params(2,0,'Test', :author => 'Username')
53
+ row = data[0]
54
+ col = data[1]
55
+ author = data[4]
56
+ encoding = data[5]
57
+ visible = data[6]
58
+ obj_id = 1
59
+
60
+ caption = sprintf(" \tstore_note")
61
+ target = %w(
62
+ 1C 00 14 00 02 00 00 00 00 00 01 00 08 00 00 55
63
+ 73 65 72 6E 61 6D 65 00
64
+ ).join(' ')
65
+ result = unpack_record(
66
+ @worksheet.store_note(row,col,obj_id,author,encoding,visible))
67
+ assert_equal(target, result, caption)
68
+ end
69
+
70
+ ###############################################################################
71
+ #
72
+ # Unpack the binary data into a format suitable for printing in tests.
73
+ #
74
+ def unpack_record(data)
75
+ data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
76
+ end
77
+
78
+ end
@@ -0,0 +1,80 @@
1
+ ##########################################################################
2
+ # test_24_txo.rb
3
+ #
4
+ # Tests for some of the internal method used to write the NOTE record that
5
+ # is used in cell comments.
6
+ #
7
+ # reverse('©'), September 2005, 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_txo < 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
+ end
27
+
28
+ def teardown
29
+ @workbook.close
30
+ File.unlink(@test_file) if FileTest.exist?(@test_file)
31
+ end
32
+
33
+ def test_txo
34
+ string = 'aaa'
35
+ caption = " \t_store_txo()"
36
+ target = %w(
37
+ B6 01 12 00 12 02 00 00 00 00 00 00 00 00 03 00
38
+ 10 00 00 00 00 00
39
+ ).join(' ')
40
+
41
+ result = unpack_record(@worksheet.store_txo(string.length))
42
+ assert_equal(target, result, caption)
43
+ end
44
+
45
+ def test_first_continue_record_after_txo
46
+ string = 'aaa'
47
+ caption = " \t_store_txo_continue_1()"
48
+ target = %w(
49
+ 3C 00 04 00 00 61 61 61
50
+ ).join(' ')
51
+
52
+ result = unpack_record(@worksheet.store_txo_continue_1(string))
53
+ assert_equal(target, result, caption)
54
+ end
55
+
56
+ def test_second_continue_record_after_txo
57
+ string = 'aaa'
58
+ caption = " \t_store_txo_continue_2()"
59
+ target = %w(
60
+ 3C 00 10 00 00 00 00 00 00 00 00 00 03 00 00 00
61
+ 00 00 00 00
62
+ ).join(' ')
63
+ formats = [
64
+ [0, 0],
65
+ [string.length, 0]
66
+ ]
67
+
68
+ result = unpack_record(@worksheet.store_txo_continue_2(formats))
69
+ assert_equal(target, result, caption)
70
+ end
71
+
72
+ ###############################################################################
73
+ #
74
+ # Unpack the binary data into a format suitable for printing in tests.
75
+ #
76
+ def unpack_record(data)
77
+ data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
78
+ end
79
+
80
+ end
@@ -0,0 +1,327 @@
1
+ ##########################################################################
2
+ # test_26_autofilter.rb
3
+ #
4
+ # Tests for the internal methods used to write the AUTOFILTER record.
5
+ #
6
+ # reverse('©'), September 2005, John McNamara, jmcnamara@cpan.org
7
+ #
8
+ # original written in Perl by John McNamara
9
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
10
+ #
11
+ #########################################################################
12
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
13
+
14
+ require "test/unit"
15
+ require 'WriteExcel'
16
+
17
+ class TC_26_autofilter < Test::Unit::TestCase
18
+
19
+ def test_26_autofilter
20
+ @tests.each do |test|
21
+ column = test['column']
22
+ expression = test['expression']
23
+ tokens = @worksheet.extract_filter_tokens(expression)
24
+ tokens = @worksheet.parse_filter_expression(expression, tokens)
25
+
26
+ result = @worksheet.store_autofilter(column, *tokens)
27
+
28
+ target = test['data'].join(" ")
29
+
30
+ caption = " \tfilter_column(#{column}, '#{expression}')"
31
+
32
+ result = unpack_record(result)
33
+ assert_equal(target, result, caption)
34
+ end
35
+ end
36
+
37
+ ###############################################################################
38
+ #
39
+ # Unpack the binary data into a format suitable for printing in tests.
40
+ #
41
+ def unpack_record(data)
42
+ data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
43
+ end
44
+
45
+ def setup
46
+ t = Time.now.strftime("%Y%m%d")
47
+ path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
48
+ @test_file = File.join(Dir.tmpdir, path)
49
+ @workbook = Spreadsheet::WriteExcel.new(@test_file)
50
+ @worksheet = @workbook.add_worksheet
51
+ @tests = [
52
+ {
53
+ 'column' => 0,
54
+ 'expression' => 'x = Blanks',
55
+ 'data' => [%w(
56
+ 9E 00 18 00 00 00 84 32 0C 02 00 00 00 00 00 00
57
+ 00 00 00 00 00 00 00 00 00 00 00 00
58
+
59
+ )]
60
+ },
61
+ {
62
+ 'column' => 1,
63
+ 'expression' => 'x = Nonblanks',
64
+ 'data' => [%w(
65
+ 9E 00 18 00 01 00 84 32 0E 05 00 00 00 00 00 00
66
+ 00 00 00 00 00 00 00 00 00 00 00 00
67
+
68
+ )]
69
+ },
70
+ {
71
+ 'column' => 2,
72
+ 'expression' => 'x > 1.001',
73
+ 'data' => [%w(
74
+ 9E 00 18 00 02 00 80 32 04 04 6A BC 74 93 18 04
75
+ F0 3F 00 00 00 00 00 00 00 00 00 00
76
+
77
+ )]
78
+ },
79
+ {
80
+ 'column' => 3,
81
+ 'expression' => 'x >= 1.001',
82
+ 'data' => [%w(
83
+ 9E 00 18 00 03 00 80 32 04 06 6A BC 74 93 18 04
84
+ F0 3F 00 00 00 00 00 00 00 00 00 00
85
+
86
+ )]
87
+ },
88
+ {
89
+ 'column' => 4,
90
+ 'expression' => 'x < 1.001',
91
+ 'data' => [%w(
92
+ 9E 00 18 00 04 00 80 32 04 01 6A BC 74 93 18 04
93
+ F0 3F 00 00 00 00 00 00 00 00 00 00
94
+
95
+ )]
96
+ },
97
+ {
98
+ 'column' => 5,
99
+ 'expression' => 'x <= 1.001',
100
+ 'data' => [%w(
101
+ 9E 00 18 00 05 00 80 32 04 03 6A BC 74 93 18 04
102
+ F0 3F 00 00 00 00 00 00 00 00 00 00
103
+
104
+ )]
105
+ },
106
+ {
107
+ 'column' => 6,
108
+ 'expression' => 'x > 1.001 and x <= 5.001',
109
+ 'data' => [%w(
110
+ 9E 00 18 00 06 00 80 32 04 04 6A BC 74 93 18 04
111
+ F0 3F 04 03 1B 2F DD 24 06 01 14 40
112
+
113
+ )]
114
+ },
115
+ {
116
+ 'column' => 7,
117
+ 'expression' => 'x > 1.001 or x <= 5.001',
118
+ 'data' => [%w(
119
+ 9E 00 18 00 07 00 81 32 04 04 6A BC 74 93 18 04
120
+ F0 3F 04 03 1B 2F DD 24 06 01 14 40
121
+
122
+ )]
123
+ },
124
+ {
125
+ 'column' => 8,
126
+ 'expression' => 'x <> 2.001',
127
+ 'data' => [%w(
128
+ 9E 00 18 00 08 00 80 32 04 05 35 5E BA 49 0C 02
129
+ 00 40 00 00 00 00 00 00 00 00 00 00
130
+
131
+ )]
132
+ },
133
+ {
134
+ 'column' => 9,
135
+ 'expression' => 'x = 1.001',
136
+ 'data' => [%w(
137
+ 9E 00 1E 00 09 00 84 32 06 02 00 00 00 00 05 00
138
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 31 2E 30
139
+ 30 31
140
+
141
+ )]
142
+ },
143
+ {
144
+ 'column' => 10,
145
+ 'expression' => 'x = West',
146
+ 'data' => [%w(
147
+ 9E 00 1D 00 0A 00 84 32 06 02 00 00 00 00 04 00
148
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 57 65 73
149
+ 74
150
+
151
+ )]
152
+ },
153
+ {
154
+ 'column' => 11,
155
+ 'expression' => 'x = East',
156
+ 'data' => [%w(
157
+ 9E 00 1D 00 0B 00 84 32 06 02 00 00 00 00 04 00
158
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 45 61 73
159
+ 74
160
+
161
+ )]
162
+ },
163
+ {
164
+ 'column' => 12,
165
+ 'expression' => 'x <> West',
166
+ 'data' => [%w(
167
+ 9E 00 1D 00 0C 00 80 32 06 05 00 00 00 00 04 00
168
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 57 65 73
169
+ 74
170
+
171
+ )]
172
+ },
173
+ {
174
+ 'column' => 13,
175
+ 'expression' => 'x =~ b*',
176
+ 'data' => [%w(
177
+ 9E 00 1B 00 0D 00 80 32 06 02 00 00 00 00 02 00
178
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 62 2A
179
+
180
+ )]
181
+ },
182
+ {
183
+ 'column' => 14,
184
+ 'expression' => 'x !~ b*',
185
+ 'data' => [%w(
186
+ 9E 00 1B 00 0E 00 80 32 06 05 00 00 00 00 02 00
187
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 62 2A
188
+
189
+ )]
190
+ },
191
+ {
192
+ 'column' => 15,
193
+ 'expression' => 'x =~ *b',
194
+ 'data' => [%w(
195
+ 9E 00 1B 00 0F 00 80 32 06 02 00 00 00 00 02 00
196
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 2A 62
197
+
198
+ )]
199
+ },
200
+ {
201
+ 'column' => 16,
202
+ 'expression' => 'x !~ *b',
203
+ 'data' => [%w(
204
+ 9E 00 1B 00 10 00 80 32 06 05 00 00 00 00 02 00
205
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 2A 62
206
+
207
+ )]
208
+ },
209
+ {
210
+ 'column' => 17,
211
+ 'expression' => 'x =~ *b*',
212
+ 'data' => [%w(
213
+ 9E 00 1C 00 11 00 80 32 06 02 00 00 00 00 03 00
214
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 2A 62 2A
215
+
216
+ )]
217
+ },
218
+ {
219
+ 'column' => 18,
220
+ 'expression' => 'x !~ *b*',
221
+ 'data' => [%w(
222
+ 9E 00 1C 00 12 00 80 32 06 05 00 00 00 00 03 00
223
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 2A 62 2A
224
+
225
+ )]
226
+ },
227
+ {
228
+ 'column' => 19,
229
+ 'expression' => 'x = fo?',
230
+ 'data' => [%w(
231
+ 9E 00 1C 00 13 00 80 32 06 02 00 00 00 00 03 00
232
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 66 6F 3F
233
+
234
+ )]
235
+ },
236
+ {
237
+ 'column' => 20,
238
+ 'expression' => 'x = fo~?',
239
+ 'data' => [%w(
240
+ 9E 00 1D 00 14 00 80 32 06 02 00 00 00 00 04 00
241
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 66 6F 7E
242
+ 3F
243
+
244
+ )]
245
+ },
246
+ {
247
+ 'column' => 21,
248
+ 'expression' => 'x = East and x = West',
249
+ 'data' => [%w(
250
+ 9E 00 22 00 15 00 8C 32 06 02 00 00 00 00 04 00
251
+ 00 00 06 02 00 00 00 00 04 00 00 00 00 45 61 73
252
+ 74 00 57 65 73 74
253
+
254
+ )]
255
+ },
256
+ {
257
+ 'column' => 22,
258
+ 'expression' => 'top 10 items',
259
+ 'data' => [%w(
260
+ 9E 00 18 00 16 00 30 05 04 06 00 00 00 00 00 00
261
+ 00 00 00 00 00 00 00 00 00 00 00 00
262
+
263
+ )]
264
+ },
265
+ {
266
+ 'column' => 23,
267
+ 'expression' => 'top 10 %',
268
+ 'data' => [%w(
269
+ 9E 00 18 00 17 00 70 05 04 06 00 00 00 00 00 00
270
+ 00 00 00 00 00 00 00 00 00 00 00 00
271
+
272
+ )]
273
+ },
274
+ {
275
+ 'column' => 24,
276
+ 'expression' => 'bottom 10 items',
277
+ 'data' => [%w(
278
+ 9E 00 18 00 18 00 10 05 04 03 00 00 00 00 00 00
279
+ 00 00 00 00 00 00 00 00 00 00 00 00
280
+
281
+ )]
282
+ },
283
+ {
284
+ 'column' => 25,
285
+ 'expression' => 'bottom 10 %',
286
+ 'data' => [%w(
287
+ 9E 00 18 00 19 00 50 05 04 03 00 00 00 00 00 00
288
+ 00 00 00 00 00 00 00 00 00 00 00 00
289
+
290
+ )]
291
+ },
292
+ {
293
+ 'column' => 26,
294
+ 'expression' => 'top 5 items',
295
+ 'data' => [%w(
296
+ 9E 00 18 00 1A 00 B0 02 04 06 00 00 00 00 00 00
297
+ 00 00 00 00 00 00 00 00 00 00 00 00
298
+
299
+ )]
300
+ },
301
+ {
302
+ 'column' => 27,
303
+ 'expression' => 'top 100 items',
304
+ 'data' => [%w(
305
+ 9E 00 18 00 1B 00 30 32 04 06 00 00 00 00 00 00
306
+ 00 00 00 00 00 00 00 00 00 00 00 00
307
+
308
+ )]
309
+ },
310
+ {
311
+ 'column' => 28,
312
+ 'expression' => 'top 101 items',
313
+ 'data' => [%w(
314
+ 9E 00 18 00 1C 00 B0 32 04 06 00 00 00 00 00 00
315
+ 00 00 00 00 00 00 00 00 00 00 00 00
316
+
317
+ )]
318
+ }
319
+ ]
320
+ end
321
+
322
+ def teardown
323
+ @workbook.close
324
+ File.unlink(@test_file) if FileTest.exist?(@test_file)
325
+ end
326
+
327
+ end