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,419 +1,442 @@
1
- ##########################################################################
2
- # test_42_set_properties.rb
3
- #
4
- # Tests for Workbook property_sets() interface.
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 'rubygems'
16
- require 'writeexcel'
17
-
18
- class TC_set_properties < Test::Unit::TestCase
19
-
20
- def test_same_as_previous_plus_creation_date
21
- test_file = 'temp_test_file.xls'
22
- smiley = '' # chr 0x263A; in perl
23
-
24
- workbook = Spreadsheet::WriteExcel.new(test_file)
25
- worksheet = workbook.add_worksheet
26
-
27
- ###############################################################################
28
- #
29
- # Test 1. _get_property_set_codepage() for default latin1 strings.
30
- #
31
- params ={
32
- :title => 'Title',
33
- :subject => 'Subject',
34
- :author => 'Author',
35
- :keywords => 'Keywords',
36
- :comments => 'Comments',
37
- :last_author => 'Username',
38
- }
39
-
40
- strings = %w(title subject author keywords comments last_author)
41
-
42
- caption = " \t_get_property_set_codepage('latin1')"
43
- target = 0x04E4
44
-
45
- result = workbook.get_property_set_codepage(params, strings)
46
- assert_equal(target, result, caption)
47
-
48
- ###############################################################################
49
- #
50
- # Test 2. _get_property_set_codepage() for manual utf8 strings.
51
- #
52
-
53
- params = {
54
- :title => 'Title',
55
- :subject => 'Subject',
56
- :author => 'Author',
57
- :keywords => 'Keywords',
58
- :comments => 'Comments',
59
- :last_author => 'Username',
60
- :utf8 => 1,
61
- }
62
-
63
- strings = %w(title subject author keywords comments last_author)
64
-
65
- caption = " \t_get_property_set_codepage('utf8')"
66
- target = 0xFDE9
67
-
68
- result = workbook.get_property_set_codepage(params, strings)
69
- assert_equal(target, result, caption)
70
-
71
- ###############################################################################
72
- #
73
- # Test 3. _get_property_set_codepage() for perl 5.8 utf8 strings.
74
- #
75
- params = {
76
- :title => 'Title' + smiley,
77
- :subject => 'Subject',
78
- :author => 'Author',
79
- :keywords => 'Keywords',
80
- :comments => 'Comments',
81
- :last_author => 'Username',
82
- }
83
-
84
- strings = %w(title subject author keywords comments last_author)
85
-
86
- caption = " \t_get_property_set_codepage('utf8')";
87
- target = 0xFDE9;
88
-
89
- result = workbook.get_property_set_codepage(params, strings)
90
- assert_equal(target, result, caption)
91
-
92
- ###############################################################################
93
- #
94
- # Note, the "created => nil" parameters in some of the following tests is
95
- # used to avoid adding the default date to the property sets.
96
-
97
-
98
- ###############################################################################
99
- #
100
- # Test 4. Codepage only.
101
- #
102
-
103
- workbook.set_properties(
104
- :created => nil
105
- )
106
-
107
- caption = " \tset_properties(codepage)"
108
- target = %w(
109
- FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
110
- 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
111
- F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
112
- 18 00 00 00 01 00 00 00 01 00 00 00 10 00 00 00
113
- 02 00 00 00 E4 04 00 00
114
- ).join(' ')
115
-
116
- result = unpack_record( workbook.summary )
117
- assert_equal(target, result, caption)
118
-
119
- ###############################################################################
120
- #
121
- # Test 5. Same as previous + Title.
122
- #
123
-
124
- workbook.set_properties(
125
- :title => 'Title',
126
- :created => nil
127
- )
128
-
129
- caption = " \tset_properties('Title')"
130
- target = %w(
131
- FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
132
- 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
133
- F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
134
- 30 00 00 00 02 00 00 00 01 00 00 00 18 00 00 00
135
- 02 00 00 00 20 00 00 00 02 00 00 00 E4 04 00 00
136
- 1E 00 00 00 06 00 00 00 54 69 74 6C 65 00 00 00
137
- ).join(' ')
138
-
139
- result = unpack_record( workbook.summary )
140
- assert_equal(target, result, caption)
141
-
142
- ###############################################################################
143
- #
144
- # Test 6. Same as previous + Subject.
145
- #
146
-
147
- workbook.set_properties(
148
- :title => 'Title',
149
- :subject => 'Subject',
150
- :created => nil
151
- )
152
-
153
- caption = " \tset_properties('+ Subject')"
154
- target = %w(
155
- FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
156
- 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
157
- F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
158
- 48 00 00 00 03 00 00 00 01 00 00 00 20 00 00 00
159
- 02 00 00 00 28 00 00 00 03 00 00 00 38 00 00 00
160
- 02 00 00 00 E4 04 00 00 1E 00 00 00 06 00 00 00
161
- 54 69 74 6C 65 00 00 00 1E 00 00 00 08 00 00 00
162
- 53 75 62 6A 65 63 74 00
163
- ).join(' ')
164
-
165
- result = unpack_record( workbook.summary )
166
- assert_equal(target, result, caption)
167
-
168
- ###############################################################################
169
- #
170
- # Test 7. Same as previous + Author.
171
- #
172
-
173
- workbook.set_properties(
174
- :title => 'Title',
175
- :subject => 'Subject',
176
- :author => 'Author',
177
- :created => nil
178
- )
179
-
180
- caption = " \tset_properties('+ Author')"
181
- target = %w(
182
- FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
183
- 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
184
- F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
185
- 60 00 00 00 04 00 00 00 01 00 00 00 28 00 00 00
186
- 02 00 00 00 30 00 00 00 03 00 00 00 40 00 00 00
187
- 04 00 00 00 50 00 00 00 02 00 00 00 E4 04 00 00
188
- 1E 00 00 00 06 00 00 00 54 69 74 6C 65 00 00 00
189
- 1E 00 00 00 08 00 00 00 53 75 62 6A 65 63 74 00
190
- 1E 00 00 00 07 00 00 00 41 75 74 68 6F 72 00 00
191
- ).join(' ')
192
-
193
- result = unpack_record( workbook.summary )
194
- assert_equal(target, result, caption)
195
-
196
- ###############################################################################
197
- #
198
- # Test 8. Same as previous + Keywords.
199
- #
200
-
201
- workbook.set_properties(
202
- :title => 'Title',
203
- :subject => 'Subject',
204
- :author => 'Author',
205
- :keywords => 'Keywords',
206
- :created => nil
207
- )
208
-
209
- caption = " \tset_properties('+ Keywords')"
210
- target = %w(
211
- FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
212
- 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
213
- F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
214
- 7C 00 00 00 05 00 00 00 01 00 00 00 30 00 00 00
215
- 02 00 00 00 38 00 00 00 03 00 00 00 48 00 00 00
216
- 04 00 00 00 58 00 00 00 05 00 00 00 68 00 00 00
217
- 02 00 00 00 E4 04 00 00 1E 00 00 00 06 00 00 00
218
- 54 69 74 6C 65 00 00 00 1E 00 00 00 08 00 00 00
219
- 53 75 62 6A 65 63 74 00 1E 00 00 00 07 00 00 00
220
- 41 75 74 68 6F 72 00 00 1E 00 00 00 09 00 00 00
221
- 4B 65 79 77 6F 72 64 73 00 00 00 00
222
- ).join(' ')
223
-
224
- result = unpack_record( workbook.summary )
225
- assert_equal(target, result, caption)
226
-
227
- ###############################################################################
228
- #
229
- # Test 9. Same as previous + Comments.
230
- #
231
-
232
- workbook.set_properties(
233
- :title => 'Title',
234
- :subject => 'Subject',
235
- :author => 'Author',
236
- :keywords => 'Keywords',
237
- :comments => 'Comments',
238
- :created => nil
239
- )
240
-
241
- caption = " \tset_properties('+ Comments')"
242
- target = %w(
243
- FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
244
- 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
245
- F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
246
- 98 00 00 00 06 00 00 00 01 00 00 00 38 00 00 00
247
- 02 00 00 00 40 00 00 00 03 00 00 00 50 00 00 00
248
- 04 00 00 00 60 00 00 00 05 00 00 00 70 00 00 00
249
- 06 00 00 00 84 00 00 00 02 00 00 00 E4 04 00 00
250
- 1E 00 00 00 06 00 00 00 54 69 74 6C 65 00 00 00
251
- 1E 00 00 00 08 00 00 00 53 75 62 6A 65 63 74 00
252
- 1E 00 00 00 07 00 00 00 41 75 74 68 6F 72 00 00
253
- 1E 00 00 00 09 00 00 00 4B 65 79 77 6F 72 64 73
254
- 00 00 00 00 1E 00 00 00 09 00 00 00 43 6F 6D 6D
255
- 65 6E 74 73 00 00 00 00
256
- ).join(' ')
257
-
258
- result = unpack_record( workbook.summary )
259
- assert_equal(target, result, caption)
260
-
261
- ###############################################################################
262
- #
263
- # Test 10. Same as previous + Last author.
264
- #
265
-
266
- workbook.set_properties(
267
- :title => 'Title',
268
- :subject => 'Subject',
269
- :author => 'Author',
270
- :keywords => 'Keywords',
271
- :comments => 'Comments',
272
- :last_author => 'Username',
273
- :created => nil
274
- )
275
-
276
- caption = " \tset_properties('+ Last author')"
277
- target = %w(
278
- FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
279
- 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
280
- F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
281
- B4 00 00 00 07 00 00 00 01 00 00 00 40 00 00 00
282
- 02 00 00 00 48 00 00 00 03 00 00 00 58 00 00 00
283
- 04 00 00 00 68 00 00 00 05 00 00 00 78 00 00 00
284
- 06 00 00 00 8C 00 00 00 08 00 00 00 A0 00 00 00
285
- 02 00 00 00 E4 04 00 00 1E 00 00 00 06 00 00 00
286
- 54 69 74 6C 65 00 00 00 1E 00 00 00 08 00 00 00
287
- 53 75 62 6A 65 63 74 00 1E 00 00 00 07 00 00 00
288
- 41 75 74 68 6F 72 00 00 1E 00 00 00 09 00 00 00
289
- 4B 65 79 77 6F 72 64 73 00 00 00 00 1E 00 00 00
290
- 09 00 00 00 43 6F 6D 6D 65 6E 74 73 00 00 00 00
291
- 1E 00 00 00 09 00 00 00 55 73 65 72 6E 61 6D 65
292
- 00 00 00 00
293
- ).join(' ')
294
-
295
- result = unpack_record( workbook.summary )
296
- assert_equal(target, result, caption)
297
-
298
- ###############################################################################
299
- #
300
- # Test 11. Same as previous + Creation date.
301
- #
302
-
303
- # Aug 19 23:20:13 2008
304
- # $sec,$min,$hour,$mday,$mon,$year
305
- # We normalise the time using timegm() so that the tests don't fail due to
306
- # different timezones.
307
-
308
- filetime = Time.gm(2008,8,19,23,20,13)
309
- workbook.set_properties(
310
- :title => 'Title',
311
- :subject => 'Subject',
312
- :author => 'Author',
313
- :keywords => 'Keywords',
314
- :comments => 'Comments',
315
- :last_author => 'Username',
316
- :created => filetime
317
- )
318
-
319
- caption = " \tset_properties('+ Creation date')"
320
- target = %w(
321
- FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
322
- 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
323
- F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
324
- C8 00 00 00 08 00 00 00 01 00 00 00 48 00 00 00
325
- 02 00 00 00 50 00 00 00 03 00 00 00 60 00 00 00
326
- 04 00 00 00 70 00 00 00 05 00 00 00 80 00 00 00
327
- 06 00 00 00 94 00 00 00 08 00 00 00 A8 00 00 00
328
- 0C 00 00 00 BC 00 00 00 02 00 00 00 E4 04 00 00
329
- 1E 00 00 00 06 00 00 00 54 69 74 6C 65 00 00 00
330
- 1E 00 00 00 08 00 00 00 53 75 62 6A 65 63 74 00
331
- 1E 00 00 00 07 00 00 00 41 75 74 68 6F 72 00 00
332
- 1E 00 00 00 09 00 00 00 4B 65 79 77 6F 72 64 73
333
- 00 00 00 00 1E 00 00 00 09 00 00 00 43 6F 6D 6D
334
- 65 6E 74 73 00 00 00 00 1E 00 00 00 09 00 00 00
335
- 55 73 65 72 6E 61 6D 65 00 00 00 00 40 00 00 00
336
- 80 74 89 21 52 02 C9 01
337
- ).join(' ')
338
-
339
- result = unpack_record( workbook.summary )
340
- assert_equal(target, result, caption)
341
-
342
- ###############################################################################
343
- #
344
- # Test 12. Same as previous. Date set at the workbook level.
345
- #
346
-
347
- # Wed Aug 20 00:20:13 2008
348
- # $sec,$min,$hour,$mday,$mon,$year
349
- # We normalise the time using timegm() so that the tests don't fail due to
350
- # different timezones.
351
- workbook.localtime = Time.gm(2008,8,19,23,20,13)
352
-
353
- workbook.set_properties(
354
- :title => 'Title',
355
- :subject => 'Subject',
356
- :author => 'Author',
357
- :keywords => 'Keywords',
358
- :comments => 'Comments',
359
- :last_author => 'Username'
360
- )
361
-
362
- caption = " \tset_properties('+ Creation date')"
363
- target = %w(
364
- FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
365
- 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
366
- F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
367
- C8 00 00 00 08 00 00 00 01 00 00 00 48 00 00 00
368
- 02 00 00 00 50 00 00 00 03 00 00 00 60 00 00 00
369
- 04 00 00 00 70 00 00 00 05 00 00 00 80 00 00 00
370
- 06 00 00 00 94 00 00 00 08 00 00 00 A8 00 00 00
371
- 0C 00 00 00 BC 00 00 00 02 00 00 00 E4 04 00 00
372
- 1E 00 00 00 06 00 00 00 54 69 74 6C 65 00 00 00
373
- 1E 00 00 00 08 00 00 00 53 75 62 6A 65 63 74 00
374
- 1E 00 00 00 07 00 00 00 41 75 74 68 6F 72 00 00
375
- 1E 00 00 00 09 00 00 00 4B 65 79 77 6F 72 64 73
376
- 00 00 00 00 1E 00 00 00 09 00 00 00 43 6F 6D 6D
377
- 65 6E 74 73 00 00 00 00 1E 00 00 00 09 00 00 00
378
- 55 73 65 72 6E 61 6D 65 00 00 00 00 40 00 00 00
379
- 80 74 89 21 52 02 C9 01
380
- ).join(' ')
381
-
382
- result = unpack_record( workbook.summary )
383
- assert_equal(target, result, caption)
384
-
385
- ###############################################################################
386
- #
387
- # Test 14. UTF-8 string used.
388
- #
389
-
390
- workbook.set_properties(
391
- :title => 'Title' + smiley,
392
- :created => nil
393
- )
394
-
395
- caption = " \tset_properties(utf8)"
396
- target = %w(
397
- FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
398
- 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
399
- F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
400
- 34 00 00 00 02 00 00 00 01 00 00 00 18 00 00 00
401
- 02 00 00 00 20 00 00 00 02 00 00 00 E9 FD 00 00
402
- 1E 00 00 00 09 00 00 00 54 69 74 6C 65 E2 98 BA
403
- 00 00 00 00
404
- ).join(' ')
405
-
406
- result = unpack_record( workbook.summary )
407
- assert_equal(target, result, caption)
408
-
409
- end
410
-
411
- ###############################################################################
412
- #
413
- # Unpack the binary data into a format suitable for printing in tests.
414
- #
415
- def unpack_record(data)
416
- data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
417
- end
418
-
419
- end
1
+ ##########################################################################
2
+ # test_42_set_properties.rb
3
+ #
4
+ # Tests for Workbook property_sets() interface.
5
+ #
6
+ # some test is commented out because related method was set to
7
+ # private method. Before that, all test passed.
8
+ #
9
+ #
10
+ #
11
+ #
12
+ # reverse('©'), September 2005, John McNamara, jmcnamara@cpan.org
13
+ #
14
+ # original written in Perl by John McNamara
15
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
16
+ #
17
+ #########################################################################
18
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
19
+
20
+ require 'test/unit'
21
+ require 'rubygems'
22
+ require 'writeexcel'
23
+
24
+ class TC_set_properties < Test::Unit::TestCase
25
+
26
+ def test_dummy
27
+ assert(true)
28
+ end
29
+
30
+ def setup
31
+ t = Time.now.strftime("%Y%m%d")
32
+ path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
33
+ @test_file = File.join(Dir.tmpdir, path)
34
+ end
35
+
36
+ def teardown
37
+ File.unlink(@test_file) if FileTest.exist?(@test_file)
38
+ end
39
+
40
+ def test_same_as_previous_plus_creation_date
41
+ smiley = '☺' # chr 0x263A; in perl
42
+
43
+ workbook = WriteExcel.new(@test_file)
44
+ worksheet = workbook.add_worksheet
45
+
46
+ =begin
47
+ ###############################################################################
48
+ #
49
+ # Test 1. _get_property_set_codepage() for default latin1 strings.
50
+ #
51
+ params ={
52
+ :title => 'Title',
53
+ :subject => 'Subject',
54
+ :author => 'Author',
55
+ :keywords => 'Keywords',
56
+ :comments => 'Comments',
57
+ :last_author => 'Username',
58
+ }
59
+
60
+ strings = %w(title subject author keywords comments last_author)
61
+
62
+ caption = " \t_get_property_set_codepage('latin1')"
63
+ target = 0x04E4
64
+
65
+ result = workbook.get_property_set_codepage(params, strings)
66
+ assert_equal(target, result, caption)
67
+
68
+ ###############################################################################
69
+ #
70
+ # Test 2. _get_property_set_codepage() for manual utf8 strings.
71
+ #
72
+
73
+ params = {
74
+ :title => 'Title',
75
+ :subject => 'Subject',
76
+ :author => 'Author',
77
+ :keywords => 'Keywords',
78
+ :comments => 'Comments',
79
+ :last_author => 'Username',
80
+ :utf8 => 1,
81
+ }
82
+
83
+ strings = %w(title subject author keywords comments last_author)
84
+
85
+ caption = " \t_get_property_set_codepage('utf8')"
86
+ target = 0xFDE9
87
+
88
+ result = workbook.get_property_set_codepage(params, strings)
89
+ assert_equal(target, result, caption)
90
+
91
+ ###############################################################################
92
+ #
93
+ # Test 3. _get_property_set_codepage() for perl 5.8 utf8 strings.
94
+ #
95
+ params = {
96
+ :title => 'Title' + smiley,
97
+ :subject => 'Subject',
98
+ :author => 'Author',
99
+ :keywords => 'Keywords',
100
+ :comments => 'Comments',
101
+ :last_author => 'Username',
102
+ }
103
+
104
+ strings = %w(title subject author keywords comments last_author)
105
+
106
+ caption = " \t_get_property_set_codepage('utf8')";
107
+ target = 0xFDE9;
108
+
109
+ result = workbook.get_property_set_codepage(params, strings)
110
+ assert_equal(target, result, caption)
111
+ =end
112
+
113
+ ###############################################################################
114
+ #
115
+ # Note, the "created => nil" parameters in some of the following tests is
116
+ # used to avoid adding the default date to the property sets.
117
+
118
+
119
+ ###############################################################################
120
+ #
121
+ # Test 4. Codepage only.
122
+ #
123
+
124
+ workbook.set_properties(
125
+ :created => nil
126
+ )
127
+
128
+ caption = " \tset_properties(codepage)"
129
+ target = %w(
130
+ FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
131
+ 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
132
+ F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
133
+ 18 00 00 00 01 00 00 00 01 00 00 00 10 00 00 00
134
+ 02 00 00 00 E4 04 00 00
135
+ ).join(' ')
136
+
137
+ result = unpack_record( workbook.summary )
138
+ assert_equal(target, result, caption)
139
+
140
+ ###############################################################################
141
+ #
142
+ # Test 5. Same as previous + Title.
143
+ #
144
+
145
+ workbook.set_properties(
146
+ :title => 'Title',
147
+ :created => nil
148
+ )
149
+
150
+ caption = " \tset_properties('Title')"
151
+ target = %w(
152
+ FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
153
+ 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
154
+ F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
155
+ 30 00 00 00 02 00 00 00 01 00 00 00 18 00 00 00
156
+ 02 00 00 00 20 00 00 00 02 00 00 00 E4 04 00 00
157
+ 1E 00 00 00 06 00 00 00 54 69 74 6C 65 00 00 00
158
+ ).join(' ')
159
+
160
+ result = unpack_record( workbook.summary )
161
+ assert_equal(target, result, caption)
162
+
163
+ ###############################################################################
164
+ #
165
+ # Test 6. Same as previous + Subject.
166
+ #
167
+
168
+ workbook.set_properties(
169
+ :title => 'Title',
170
+ :subject => 'Subject',
171
+ :created => nil
172
+ )
173
+
174
+ caption = " \tset_properties('+ Subject')"
175
+ target = %w(
176
+ FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
177
+ 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
178
+ F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
179
+ 48 00 00 00 03 00 00 00 01 00 00 00 20 00 00 00
180
+ 02 00 00 00 28 00 00 00 03 00 00 00 38 00 00 00
181
+ 02 00 00 00 E4 04 00 00 1E 00 00 00 06 00 00 00
182
+ 54 69 74 6C 65 00 00 00 1E 00 00 00 08 00 00 00
183
+ 53 75 62 6A 65 63 74 00
184
+ ).join(' ')
185
+
186
+ result = unpack_record( workbook.summary )
187
+ assert_equal(target, result, caption)
188
+
189
+ ###############################################################################
190
+ #
191
+ # Test 7. Same as previous + Author.
192
+ #
193
+
194
+ workbook.set_properties(
195
+ :title => 'Title',
196
+ :subject => 'Subject',
197
+ :author => 'Author',
198
+ :created => nil
199
+ )
200
+
201
+ caption = " \tset_properties('+ Author')"
202
+ target = %w(
203
+ FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
204
+ 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
205
+ F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
206
+ 60 00 00 00 04 00 00 00 01 00 00 00 28 00 00 00
207
+ 02 00 00 00 30 00 00 00 03 00 00 00 40 00 00 00
208
+ 04 00 00 00 50 00 00 00 02 00 00 00 E4 04 00 00
209
+ 1E 00 00 00 06 00 00 00 54 69 74 6C 65 00 00 00
210
+ 1E 00 00 00 08 00 00 00 53 75 62 6A 65 63 74 00
211
+ 1E 00 00 00 07 00 00 00 41 75 74 68 6F 72 00 00
212
+ ).join(' ')
213
+
214
+ result = unpack_record( workbook.summary )
215
+ assert_equal(target, result, caption)
216
+
217
+ ###############################################################################
218
+ #
219
+ # Test 8. Same as previous + Keywords.
220
+ #
221
+
222
+ workbook.set_properties(
223
+ :title => 'Title',
224
+ :subject => 'Subject',
225
+ :author => 'Author',
226
+ :keywords => 'Keywords',
227
+ :created => nil
228
+ )
229
+
230
+ caption = " \tset_properties('+ Keywords')"
231
+ target = %w(
232
+ FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
233
+ 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
234
+ F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
235
+ 7C 00 00 00 05 00 00 00 01 00 00 00 30 00 00 00
236
+ 02 00 00 00 38 00 00 00 03 00 00 00 48 00 00 00
237
+ 04 00 00 00 58 00 00 00 05 00 00 00 68 00 00 00
238
+ 02 00 00 00 E4 04 00 00 1E 00 00 00 06 00 00 00
239
+ 54 69 74 6C 65 00 00 00 1E 00 00 00 08 00 00 00
240
+ 53 75 62 6A 65 63 74 00 1E 00 00 00 07 00 00 00
241
+ 41 75 74 68 6F 72 00 00 1E 00 00 00 09 00 00 00
242
+ 4B 65 79 77 6F 72 64 73 00 00 00 00
243
+ ).join(' ')
244
+
245
+ result = unpack_record( workbook.summary )
246
+ assert_equal(target, result, caption)
247
+
248
+ ###############################################################################
249
+ #
250
+ # Test 9. Same as previous + Comments.
251
+ #
252
+
253
+ workbook.set_properties(
254
+ :title => 'Title',
255
+ :subject => 'Subject',
256
+ :author => 'Author',
257
+ :keywords => 'Keywords',
258
+ :comments => 'Comments',
259
+ :created => nil
260
+ )
261
+
262
+ caption = " \tset_properties('+ Comments')"
263
+ target = %w(
264
+ FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
265
+ 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
266
+ F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
267
+ 98 00 00 00 06 00 00 00 01 00 00 00 38 00 00 00
268
+ 02 00 00 00 40 00 00 00 03 00 00 00 50 00 00 00
269
+ 04 00 00 00 60 00 00 00 05 00 00 00 70 00 00 00
270
+ 06 00 00 00 84 00 00 00 02 00 00 00 E4 04 00 00
271
+ 1E 00 00 00 06 00 00 00 54 69 74 6C 65 00 00 00
272
+ 1E 00 00 00 08 00 00 00 53 75 62 6A 65 63 74 00
273
+ 1E 00 00 00 07 00 00 00 41 75 74 68 6F 72 00 00
274
+ 1E 00 00 00 09 00 00 00 4B 65 79 77 6F 72 64 73
275
+ 00 00 00 00 1E 00 00 00 09 00 00 00 43 6F 6D 6D
276
+ 65 6E 74 73 00 00 00 00
277
+ ).join(' ')
278
+
279
+ result = unpack_record( workbook.summary )
280
+ assert_equal(target, result, caption)
281
+
282
+ ###############################################################################
283
+ #
284
+ # Test 10. Same as previous + Last author.
285
+ #
286
+
287
+ workbook.set_properties(
288
+ :title => 'Title',
289
+ :subject => 'Subject',
290
+ :author => 'Author',
291
+ :keywords => 'Keywords',
292
+ :comments => 'Comments',
293
+ :last_author => 'Username',
294
+ :created => nil
295
+ )
296
+
297
+ caption = " \tset_properties('+ Last author')"
298
+ target = %w(
299
+ FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
300
+ 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
301
+ F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
302
+ B4 00 00 00 07 00 00 00 01 00 00 00 40 00 00 00
303
+ 02 00 00 00 48 00 00 00 03 00 00 00 58 00 00 00
304
+ 04 00 00 00 68 00 00 00 05 00 00 00 78 00 00 00
305
+ 06 00 00 00 8C 00 00 00 08 00 00 00 A0 00 00 00
306
+ 02 00 00 00 E4 04 00 00 1E 00 00 00 06 00 00 00
307
+ 54 69 74 6C 65 00 00 00 1E 00 00 00 08 00 00 00
308
+ 53 75 62 6A 65 63 74 00 1E 00 00 00 07 00 00 00
309
+ 41 75 74 68 6F 72 00 00 1E 00 00 00 09 00 00 00
310
+ 4B 65 79 77 6F 72 64 73 00 00 00 00 1E 00 00 00
311
+ 09 00 00 00 43 6F 6D 6D 65 6E 74 73 00 00 00 00
312
+ 1E 00 00 00 09 00 00 00 55 73 65 72 6E 61 6D 65
313
+ 00 00 00 00
314
+ ).join(' ')
315
+
316
+ result = unpack_record( workbook.summary )
317
+ assert_equal(target, result, caption)
318
+
319
+ ###############################################################################
320
+ #
321
+ # Test 11. Same as previous + Creation date.
322
+ #
323
+
324
+ # Aug 19 23:20:13 2008
325
+ # $sec,$min,$hour,$mday,$mon,$year
326
+ # We normalise the time using timegm() so that the tests don't fail due to
327
+ # different timezones.
328
+
329
+ filetime = Time.gm(2008,8,19,23,20,13)
330
+ workbook.set_properties(
331
+ :title => 'Title',
332
+ :subject => 'Subject',
333
+ :author => 'Author',
334
+ :keywords => 'Keywords',
335
+ :comments => 'Comments',
336
+ :last_author => 'Username',
337
+ :created => filetime
338
+ )
339
+
340
+ caption = " \tset_properties('+ Creation date')"
341
+ target = %w(
342
+ FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
343
+ 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
344
+ F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
345
+ C8 00 00 00 08 00 00 00 01 00 00 00 48 00 00 00
346
+ 02 00 00 00 50 00 00 00 03 00 00 00 60 00 00 00
347
+ 04 00 00 00 70 00 00 00 05 00 00 00 80 00 00 00
348
+ 06 00 00 00 94 00 00 00 08 00 00 00 A8 00 00 00
349
+ 0C 00 00 00 BC 00 00 00 02 00 00 00 E4 04 00 00
350
+ 1E 00 00 00 06 00 00 00 54 69 74 6C 65 00 00 00
351
+ 1E 00 00 00 08 00 00 00 53 75 62 6A 65 63 74 00
352
+ 1E 00 00 00 07 00 00 00 41 75 74 68 6F 72 00 00
353
+ 1E 00 00 00 09 00 00 00 4B 65 79 77 6F 72 64 73
354
+ 00 00 00 00 1E 00 00 00 09 00 00 00 43 6F 6D 6D
355
+ 65 6E 74 73 00 00 00 00 1E 00 00 00 09 00 00 00
356
+ 55 73 65 72 6E 61 6D 65 00 00 00 00 40 00 00 00
357
+ 80 74 89 21 52 02 C9 01
358
+ ).join(' ')
359
+
360
+ result = unpack_record( workbook.summary )
361
+ assert_equal(target, result, caption)
362
+
363
+ ###############################################################################
364
+ #
365
+ # Test 12. Same as previous. Date set at the workbook level.
366
+ #
367
+
368
+ # Wed Aug 20 00:20:13 2008
369
+ # $sec,$min,$hour,$mday,$mon,$year
370
+ # We normalise the time using timegm() so that the tests don't fail due to
371
+ # different timezones.
372
+ workbook.localtime = Time.gm(2008,8,19,23,20,13)
373
+
374
+ workbook.set_properties(
375
+ :title => 'Title',
376
+ :subject => 'Subject',
377
+ :author => 'Author',
378
+ :keywords => 'Keywords',
379
+ :comments => 'Comments',
380
+ :last_author => 'Username'
381
+ )
382
+
383
+ caption = " \tset_properties('+ Creation date')"
384
+ target = %w(
385
+ FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
386
+ 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
387
+ F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
388
+ C8 00 00 00 08 00 00 00 01 00 00 00 48 00 00 00
389
+ 02 00 00 00 50 00 00 00 03 00 00 00 60 00 00 00
390
+ 04 00 00 00 70 00 00 00 05 00 00 00 80 00 00 00
391
+ 06 00 00 00 94 00 00 00 08 00 00 00 A8 00 00 00
392
+ 0C 00 00 00 BC 00 00 00 02 00 00 00 E4 04 00 00
393
+ 1E 00 00 00 06 00 00 00 54 69 74 6C 65 00 00 00
394
+ 1E 00 00 00 08 00 00 00 53 75 62 6A 65 63 74 00
395
+ 1E 00 00 00 07 00 00 00 41 75 74 68 6F 72 00 00
396
+ 1E 00 00 00 09 00 00 00 4B 65 79 77 6F 72 64 73
397
+ 00 00 00 00 1E 00 00 00 09 00 00 00 43 6F 6D 6D
398
+ 65 6E 74 73 00 00 00 00 1E 00 00 00 09 00 00 00
399
+ 55 73 65 72 6E 61 6D 65 00 00 00 00 40 00 00 00
400
+ 80 74 89 21 52 02 C9 01
401
+ ).join(' ')
402
+
403
+ result = unpack_record( workbook.summary )
404
+ assert_equal(target, result, caption)
405
+
406
+ ###############################################################################
407
+ #
408
+ # Test 14. UTF-8 string used.
409
+ #
410
+
411
+ workbook.set_properties(
412
+ :title => 'Title' + smiley,
413
+ :created => nil
414
+ )
415
+
416
+ caption = " \tset_properties(utf8)"
417
+ target = %w(
418
+ FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
419
+ 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
420
+ F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
421
+ 34 00 00 00 02 00 00 00 01 00 00 00 18 00 00 00
422
+ 02 00 00 00 20 00 00 00 02 00 00 00 E9 FD 00 00
423
+ 1E 00 00 00 09 00 00 00 54 69 74 6C 65 E2 98 BA
424
+ 00 00 00 00
425
+ ).join(' ')
426
+
427
+ result = unpack_record( workbook.summary )
428
+ assert_equal(target, result, caption)
429
+
430
+ workbook.close
431
+
432
+ end
433
+
434
+ ###############################################################################
435
+ #
436
+ # Unpack the binary data into a format suitable for printing in tests.
437
+ #
438
+ def unpack_record(data)
439
+ data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
440
+ end
441
+
442
+ end