writeexcel 0.3.5 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/.gitattributes +1 -0
  2. data/README.rdoc +12 -6
  3. data/VERSION +1 -1
  4. data/charts/chartex.rb +316 -315
  5. data/charts/demo1.rb +1 -0
  6. data/charts/demo2.rb +1 -0
  7. data/charts/demo3.rb +117 -116
  8. data/charts/demo4.rb +119 -118
  9. data/charts/demo5.rb +48 -47
  10. data/examples/a_simple.rb +1 -0
  11. data/examples/autofilter.rb +1 -0
  12. data/examples/bigfile.rb +30 -29
  13. data/examples/chart_area.rb +121 -120
  14. data/examples/chart_bar.rb +120 -119
  15. data/examples/chart_column.rb +120 -119
  16. data/examples/chart_line.rb +120 -119
  17. data/examples/chart_pie.rb +108 -107
  18. data/examples/chart_scatter.rb +121 -120
  19. data/examples/chart_stock.rb +148 -147
  20. data/examples/chess.rb +1 -0
  21. data/examples/colors.rb +1 -0
  22. data/examples/comments1.rb +1 -0
  23. data/examples/comments2.rb +3 -2
  24. data/examples/copyformat.rb +1 -0
  25. data/examples/data_validate.rb +1 -0
  26. data/examples/date_time.rb +1 -0
  27. data/examples/defined_name.rb +1 -0
  28. data/examples/demo.rb +1 -0
  29. data/examples/diag_border.rb +1 -0
  30. data/examples/formats.rb +1 -0
  31. data/examples/formula_result.rb +1 -0
  32. data/examples/header.rb +1 -0
  33. data/examples/hide_sheet.rb +1 -0
  34. data/examples/hyperlink.rb +1 -0
  35. data/examples/images.rb +1 -0
  36. data/examples/indent.rb +1 -0
  37. data/examples/merge1.rb +1 -0
  38. data/examples/merge2.rb +1 -0
  39. data/examples/merge3.rb +1 -0
  40. data/examples/merge4.rb +1 -0
  41. data/examples/merge5.rb +1 -0
  42. data/examples/merge6.rb +67 -66
  43. data/examples/outline.rb +1 -0
  44. data/examples/outline_collapsed.rb +1 -0
  45. data/examples/panes.rb +1 -0
  46. data/examples/properties.rb +1 -0
  47. data/examples/properties_jp.rb +1 -0
  48. data/examples/protection.rb +1 -0
  49. data/examples/regions.rb +1 -0
  50. data/examples/repeat.rb +1 -0
  51. data/examples/right_to_left.rb +1 -0
  52. data/examples/row_wrap.rb +1 -0
  53. data/examples/stats.rb +1 -0
  54. data/examples/stocks.rb +1 -0
  55. data/examples/tab_colors.rb +1 -0
  56. data/examples/write_arrays.rb +1 -0
  57. data/lib/writeexcel.rb +6 -1
  58. data/lib/writeexcel/biffwriter.rb +21 -20
  59. data/lib/writeexcel/chart.rb +25 -12
  60. data/lib/writeexcel/charts/area.rb +153 -152
  61. data/lib/writeexcel/charts/bar.rb +178 -177
  62. data/lib/writeexcel/charts/column.rb +157 -156
  63. data/lib/writeexcel/charts/external.rb +62 -61
  64. data/lib/writeexcel/charts/line.rb +153 -152
  65. data/lib/writeexcel/charts/pie.rb +170 -169
  66. data/lib/writeexcel/charts/scatter.rb +4 -3
  67. data/lib/writeexcel/charts/stock.rb +212 -211
  68. data/lib/writeexcel/compatibility.rb +320 -0
  69. data/lib/writeexcel/excelformulaparser.rb +587 -586
  70. data/lib/writeexcel/format.rb +12 -13
  71. data/lib/writeexcel/formula.rb +30 -28
  72. data/lib/writeexcel/helper.rb +23 -0
  73. data/lib/writeexcel/olewriter.rb +5 -16
  74. data/lib/writeexcel/properties.rb +43 -54
  75. data/lib/writeexcel/storage_lite.rb +981 -968
  76. data/lib/writeexcel/workbook.rb +94 -73
  77. data/lib/writeexcel/worksheet.rb +230 -210
  78. data/test/helper.rb +19 -0
  79. data/test/test_00_IEEE_double.rb +1 -0
  80. data/test/test_01_add_worksheet.rb +1 -0
  81. data/test/test_02_merge_formats.rb +3 -5
  82. data/test/test_04_dimensions.rb +3 -5
  83. data/test/test_05_rows.rb +6 -6
  84. data/test/test_06_extsst.rb +8 -8
  85. data/test/test_11_date_time.rb +3 -5
  86. data/test/test_12_date_only.rb +3 -5
  87. data/test/test_13_date_seconds.rb +4 -6
  88. data/test/test_21_escher.rb +3 -5
  89. data/test/test_22_mso_drawing_group.rb +20 -22
  90. data/test/test_23_note.rb +5 -7
  91. data/test/test_24_txo.rb +3 -5
  92. data/test/test_25_position_object.rb +84 -79
  93. data/test/test_26_autofilter.rb +3 -13
  94. data/test/test_27_autofilter.rb +3 -13
  95. data/test/test_28_autofilter.rb +3 -13
  96. data/test/test_29_process_jpg.rb +5 -0
  97. data/test/test_30_validation_dval.rb +3 -5
  98. data/test/test_31_validation_dv_strings.rb +3 -5
  99. data/test/test_32_validation_dv_formula.rb +3 -5
  100. data/test/test_40_property_types.rb +10 -9
  101. data/test/test_41_properties.rb +1 -0
  102. data/test/test_42_set_properties.rb +14 -15
  103. data/test/test_50_name_stored.rb +299 -302
  104. data/test/test_51_name_print_area.rb +357 -360
  105. data/test/test_52_name_print_titles.rb +454 -457
  106. data/test/test_53_autofilter.rb +203 -206
  107. data/test/test_60_chart_generic.rb +5 -0
  108. data/test/test_61_chart_subclasses.rb +95 -94
  109. data/test/test_62_chart_formats.rb +272 -267
  110. data/test/test_63_chart_area_formats.rb +649 -644
  111. data/test/test_biff.rb +12 -38
  112. data/test/test_compatibility.rb +627 -0
  113. data/test/test_example_match.rb +3 -18
  114. data/test/test_format.rb +46 -105
  115. data/test/test_formula.rb +1 -0
  116. data/test/test_ole.rb +3 -4
  117. data/test/test_storage_lite.rb +125 -146
  118. data/test/test_workbook.rb +2 -23
  119. data/test/test_worksheet.rb +4 -5
  120. data/utils/add_magic_comment.rb +80 -0
  121. data/writeexcel.gemspec +8 -2
  122. metadata +10 -4
@@ -1,457 +1,454 @@
1
- ##########################################################################
2
- # test_52_name_print_titles.rb
3
- #
4
- # Tests for the Excel EXTERNSHEET and NAME records created by print_are()..
5
- #
6
- # reverse('ゥ'), September 2008, 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
- require 'helper'
13
- require 'stringio'
14
-
15
- class TC_Name_Print_Titles < Test::Unit::TestCase
16
- def setup
17
- @test_file = StringIO.new
18
- @workbook = WriteExcel.new(@test_file)
19
- @workbook.not_using_tmpfile
20
- end
21
-
22
- def test_repeat_rows_for_top_row_only
23
- worksheet1 = @workbook.add_worksheet
24
-
25
- worksheet1.repeat_rows(0)
26
-
27
- # Test the EXTERNSHEET record.
28
- @workbook.calculate_extern_sizes
29
- @workbook.store_externsheet
30
-
31
- target = [%w(
32
- 17 00 08 00 01 00 00 00 00 00 00 00
33
- ).join('')].pack('H*')
34
-
35
- caption = " \tExternsheet"
36
- result = _unpack_externsheet(@workbook.data)
37
- target = _unpack_externsheet(target)
38
- assert_equal(target, result)
39
-
40
- # Test the NAME record.
41
- @workbook.clear_data_for_test
42
- @workbook.store_names
43
-
44
- target = [%w(
45
- 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
46
- 00 00 00 07 3B 00 00 00 00 00 00 00 00 FF 00
47
- ).join('')].pack('H*')
48
-
49
- caption = " \t+ Name repeats ( Sheet1!1:1 )";
50
- result = _unpack_name(@workbook.data)
51
- target = _unpack_name(target)
52
- assert_equal(target, result)
53
- end
54
-
55
- def test_repeat_rows_for_top_10_rows
56
- worksheet1 = @workbook.add_worksheet
57
-
58
- worksheet1.repeat_rows(0, 9)
59
-
60
- # Test the EXTERNSHEET record.
61
- @workbook.calculate_extern_sizes
62
- @workbook.store_externsheet
63
-
64
- target = [%w(
65
- 17 00 08 00 01 00 00 00 00 00 00 00
66
- ).join('')].pack('H*')
67
-
68
- caption = " \tExternsheet"
69
- result = _unpack_externsheet(@workbook.data)
70
- target = _unpack_externsheet(target)
71
- assert_equal(target, result)
72
-
73
- # Test the NAME record.
74
- @workbook.clear_data_for_test
75
- @workbook.store_names
76
-
77
- target = [%w(
78
- 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
79
- 00 00 00 07 3B 00 00 00 00 09 00 00 00 FF 00
80
- ).join('')].pack('H*')
81
-
82
- caption = " \t+ Name repeats ( Sheet1!1:10 )";
83
- result = _unpack_name(@workbook.data)
84
- target = _unpack_name(target)
85
- assert_equal(target, result)
86
- end
87
-
88
- def test_repeat_columns_for_a_single_column
89
- worksheet1 = @workbook.add_worksheet
90
-
91
- worksheet1.repeat_columns(0)
92
-
93
- # Test the EXTERNSHEET record.
94
- @workbook.calculate_extern_sizes
95
- @workbook.store_externsheet
96
-
97
- target = [%w(
98
- 17 00 08 00 01 00 00 00 00 00 00 00
99
- ).join('')].pack('H*')
100
-
101
- caption = " \tExternsheet"
102
- result = _unpack_externsheet(@workbook.data)
103
- target = _unpack_externsheet(target)
104
- assert_equal(target, result)
105
-
106
- # Test the NAME record.
107
- @workbook.clear_data_for_test
108
- @workbook.store_names
109
-
110
- target = [%w(
111
- 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
112
- 00 00 00 07 3B 00 00 00 00 FF FF 00 00 00 00
113
- ).join('')].pack('H*')
114
-
115
- caption = " \t+ Name repeats ( Sheet1!A:A )";
116
- result = _unpack_name(@workbook.data)
117
- target = _unpack_name(target)
118
- assert_equal(target, result)
119
- end
120
-
121
- def test_repeat_columns_for_a_single_column_A1_notation
122
- worksheet1 = @workbook.add_worksheet
123
-
124
- worksheet1.repeat_columns('A:A')
125
-
126
- # Test the EXTERNSHEET record.
127
- @workbook.calculate_extern_sizes
128
- @workbook.store_externsheet
129
-
130
- target = [%w(
131
- 17 00 08 00 01 00 00 00 00 00 00 00
132
- ).join('')].pack('H*')
133
-
134
- caption = " \tExternsheet"
135
- result = _unpack_externsheet(@workbook.data)
136
- target = _unpack_externsheet(target)
137
- assert_equal(target, result)
138
-
139
- # Test the NAME record.
140
- @workbook.clear_data_for_test
141
- @workbook.store_names
142
-
143
- target = [%w(
144
- 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
145
- 00 00 00 07 3B 00 00 00 00 FF FF 00 00 00 00
146
- ).join('')].pack('H*')
147
-
148
- caption = " \t+ Name repeats ( Sheet1!A:A )";
149
- result = _unpack_name(@workbook.data)
150
- target = _unpack_name(target)
151
- assert_equal(target, result)
152
- end
153
-
154
- def test_repeat_columns_for_a_10_columns
155
- worksheet1 = @workbook.add_worksheet
156
-
157
- worksheet1.repeat_columns(0, 9)
158
-
159
- # Test the EXTERNSHEET record.
160
- @workbook.calculate_extern_sizes
161
- @workbook.store_externsheet
162
-
163
- target = [%w(
164
- 17 00 08 00 01 00 00 00 00 00 00 00
165
- ).join('')].pack('H*')
166
-
167
- caption = " \tExternsheet"
168
- result = _unpack_externsheet(@workbook.data)
169
- target = _unpack_externsheet(target)
170
- assert_equal(target, result)
171
-
172
- # Test the NAME record.
173
- @workbook.clear_data_for_test
174
- @workbook.store_names
175
-
176
- target = [%w(
177
- 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
178
- 00 00 00 07 3B 00 00 00 00 FF FF 00 00 09 00
179
- ).join('')].pack('H*')
180
-
181
- caption = " \t+ Name repeats ( Sheet1!A:J )";
182
- result = _unpack_name(@workbook.data)
183
- target = _unpack_name(target)
184
- assert_equal(target, result)
185
- end
186
-
187
- def test_repeat_columns_for_a_10_columns_A1_notation
188
- worksheet1 = @workbook.add_worksheet
189
-
190
- worksheet1.repeat_columns('A:J')
191
-
192
- # Test the EXTERNSHEET record.
193
- @workbook.calculate_extern_sizes
194
- @workbook.store_externsheet
195
-
196
- target = [%w(
197
- 17 00 08 00 01 00 00 00 00 00 00 00
198
- ).join('')].pack('H*')
199
-
200
- caption = " \tExternsheet"
201
- result = _unpack_externsheet(@workbook.data)
202
- target = _unpack_externsheet(target)
203
- assert_equal(target, result)
204
-
205
- # Test the NAME record.
206
- @workbook.clear_data_for_test
207
- @workbook.store_names
208
-
209
- target = [%w(
210
- 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
211
- 00 00 00 07 3B 00 00 00 00 FF FF 00 00 09 00
212
- ).join('')].pack('H*')
213
-
214
- caption = " \t+ Name repeats ( Sheet1!A:J )";
215
- result = _unpack_name(@workbook.data)
216
- target = _unpack_name(target)
217
- assert_equal(target, result)
218
- end
219
-
220
- def test_repeat_rows_on_multiple_sheets
221
- worksheet1 = @workbook.add_worksheet
222
- worksheet2 = @workbook.add_worksheet
223
- worksheet3 = @workbook.add_worksheet
224
-
225
- worksheet1.repeat_rows(0, 1)
226
- worksheet2.repeat_rows(3, 4)
227
- worksheet3.repeat_rows(6, 7)
228
-
229
- # Test the EXTERNSHEET record.
230
- @workbook.calculate_extern_sizes
231
- @workbook.store_externsheet
232
-
233
- target = [%w(
234
- 17 00 14 00 03 00 00 00 00 00 00 00 00 00 01 00
235
- 01 00 00 00 02 00 02 00
236
- ).join('')].pack('H*')
237
-
238
- caption = " \tExternsheet"
239
- result = _unpack_externsheet(@workbook.data)
240
- target = _unpack_externsheet(target)
241
- assert_equal(target, result)
242
-
243
- # Test the NAME record.
244
- @workbook.clear_data_for_test
245
- @workbook.store_names
246
-
247
- target = [%w(
248
- 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
249
- 00 00 00 07 3B 00 00 00 00 01 00 00 00 FF 00
250
-
251
- 18 00 1B 00 20 00 00 01 0B 00 00 00 02 00 00 00
252
- 00 00 00 07 3B 01 00 03 00 04 00 00 00 FF 00
253
-
254
- 18 00 1B 00 20 00 00 01 0B 00 00 00 03 00 00 00
255
- 00 00 00 07 3B 02 00 06 00 07 00 00 00 FF 00
256
- ).join('')].pack('H*')
257
-
258
- caption = " \t+ Name repeats ( Sheet1!1:2, Sheet2!4:5, Sheet3!7:8 )";
259
- result = _unpack_name(@workbook.data)
260
- target = _unpack_name(target)
261
- assert_equal(target, result)
262
- end
263
-
264
- def test_repeat_rows_on_multiple_sheets_with_sheets_spaced_out
265
- worksheet1 = @workbook.add_worksheet
266
- worksheet2 = @workbook.add_worksheet
267
- worksheet3 = @workbook.add_worksheet
268
- worksheet4 = @workbook.add_worksheet
269
- worksheet5 = @workbook.add_worksheet
270
-
271
- worksheet1.repeat_rows(0, 1)
272
- worksheet3.repeat_rows(3, 4)
273
- worksheet5.repeat_rows(6, 7)
274
-
275
- # Test the EXTERNSHEET record.
276
- @workbook.calculate_extern_sizes
277
- @workbook.store_externsheet
278
-
279
- target = [%w(
280
- 17 00 14 00 03 00 00 00 00 00 00 00 00 00 02 00
281
- 02 00 00 00 04 00 04 00
282
- ).join('')].pack('H*')
283
-
284
- caption = " \tExternsheet"
285
- result = _unpack_externsheet(@workbook.data)
286
- target = _unpack_externsheet(target)
287
- assert_equal(target, result)
288
-
289
- # Test the NAME record.
290
- @workbook.clear_data_for_test
291
- @workbook.store_names
292
-
293
- target = [%w(
294
- 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
295
- 00 00 00 07 3B 00 00 00 00 01 00 00 00 FF 00
296
-
297
- 18 00 1B 00 20 00 00 01 0B 00 00 00 03 00 00 00
298
- 00 00 00 07 3B 01 00 03 00 04 00 00 00 FF 00
299
-
300
- 18 00 1B 00 20 00 00 01 0B 00 00 00 05 00 00 00
301
- 00 00 00 07 3B 02 00 06 00 07 00 00 00 FF 00
302
- ).join('')].pack('H*')
303
-
304
- caption = " \t+ Name repeats ( Sheet1!1:2, Sheet3!4:5, Sheet5!7:8 )";
305
- result = _unpack_name(@workbook.data)
306
- target = _unpack_name(target)
307
- assert_equal(target, result)
308
- end
309
-
310
- def test_repeat_rows_and_repeat_columns_together
311
- worksheet1 = @workbook.add_worksheet
312
-
313
- worksheet1.repeat_rows(1, 2)
314
- worksheet1.repeat_columns(3, 4)
315
-
316
- # Test the EXTERNSHEET record.
317
- @workbook.calculate_extern_sizes
318
- @workbook.store_externsheet
319
-
320
- target = [%w(
321
- 17 00 08 00 01 00 00 00 00 00 00 00
322
- ).join('')].pack('H*')
323
-
324
- caption = " \tExternsheet"
325
- result = _unpack_externsheet(@workbook.data)
326
- target = _unpack_externsheet(target)
327
- assert_equal(target, result)
328
-
329
- # Test the NAME record.
330
- @workbook.clear_data_for_test
331
- @workbook.store_names
332
-
333
- target = [%w(
334
- 18 00 2A 00 20 00 00 01 1A 00 00 00 01 00 00 00
335
- 00 00 00 07 29 17 00 3B 00 00 00 00 FF FF 03 00
336
- 04 00 3B 00 00 01 00 02 00 00 00 FF 00 10
337
- ).join('')].pack('H*')
338
-
339
- caption = " \t+ Name repeats ( Sheet1!2:3, Sheet1!D:E )";
340
- result = _unpack_name(@workbook.data)
341
- target = _unpack_name(target)
342
- assert_equal(target, result)
343
- end
344
-
345
- ###############################################################################
346
- #
347
- # Unpack the binary data into a format suitable for printing in tests.
348
- #
349
- def unpack_record(data)
350
- data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
351
- end
352
-
353
- ###############################################################################
354
- #
355
- # _unpack_externsheet()
356
- #
357
- # Unpack the EXTERNSHEET recordfor easier comparison.
358
- #
359
- def _unpack_externsheet(data)
360
- externsheet = Hash.new
361
-
362
- externsheet['record'] = data[0, 2].unpack('v')[0]
363
- data[0, 2] = ''
364
- externsheet['length'] = data[0, 2].unpack('v')[0]
365
- data[0, 2] = ''
366
- externsheet['count'] = data[0, 2].unpack('v')[0]
367
- data[0, 2] = ''
368
- externsheet['array'] = [];
369
-
370
- externsheet['count'].times do
371
- externsheet['array'] << data[0, 6].unpack('vvv')
372
- data[0, 6] = ''
373
- end
374
- externsheet
375
- end
376
-
377
- ###############################################################################
378
- #
379
- # _unpack_name()
380
- #
381
- # Unpack 1 or more NAME structures into a AoH for easier comparison.
382
- #
383
- def _unpack_name(data)
384
- names = Array.new
385
- while data.length > 0
386
- name = Hash.new
387
-
388
- name['record'] = data[0, 2].unpack('v')[0]
389
- data[0, 2] = ''
390
- name['length'] = data[0, 2].unpack('v')[0]
391
- data[0, 2] = ''
392
- name['flags'] = data[0, 2].unpack('v')[0]
393
- data[0, 2] = ''
394
- name['shortcut'] = data[0, 1].unpack('C')[0]
395
- data[0, 1] = ''
396
- name['str_len'] = data[0, 1].unpack('C')[0]
397
- data[0, 1] = ''
398
- name['formula_len'] = data[0, 2].unpack('v')[0]
399
- data[0, 2] = ''
400
- name['itals'] = data[0, 2].unpack('v')[0]
401
- data[0, 2] = ''
402
- name['sheet_index'] = data[0, 2].unpack('v')[0]
403
- data[0, 2] = ''
404
- name['menu_len'] = data[0, 1].unpack('C')[0]
405
- data[0, 1] = ''
406
- name['desc_len'] = data[0, 1].unpack('C')[0]
407
- data[0, 1] = ''
408
- name['help_len'] = data[0, 1].unpack('C')[0]
409
- data[0, 1] = ''
410
- name['status_len'] = data[0, 1].unpack('C')[0]
411
- data[0, 1] = ''
412
- name['encoding'] = data[0, 1].unpack('C')[0]
413
- data[0, 1] = ''
414
-
415
- # Decode the individual flag fields.
416
- flag = Hash.new
417
- flag['hidden'] = name['flags'] & 0x0001
418
- flag['function'] = name['flags'] & 0x0002
419
- flag['vb'] = name['flags'] & 0x0004
420
- flag['macro'] = name['flags'] & 0x0008
421
- flag['complex'] = name['flags'] & 0x0010
422
- flag['builtin'] = name['flags'] & 0x0020
423
- flag['group'] = name['flags'] & 0x0FC0
424
- flag['binary'] = name['flags'] & 0x1000
425
- name['flags'] = flag
426
-
427
- # Decode the string part of the NAME structure.
428
- if name['encoding'] == 1
429
- # UTF-16 name. Leave in hex.
430
- name['string'] = data[0, 2 * name['str_len']].unpack('H*')[0].upcase
431
- data[0, 2 * name['str_len']] = ''
432
- elsif flag['builtin'] != 0
433
- # 1 digit builtin name. Leave in hex.
434
- name['string'] = data[0, name['str_len']].unpack('H*')[0].upcase
435
- data[0, name['str_len']] = ''
436
- else
437
- # ASCII name.
438
- name['string'] = data[0, name['str_len']].unpack('C*').pack('C*')
439
- data[0, name['str_len']] = ''
440
- end
441
-
442
- # Keep the formula as a hex string.
443
- name['formula'] = data[0, name['formula_len']].unpack('H*')[0].upcase
444
- data[0, name['formula_len']] = ''
445
-
446
- names << name
447
- end
448
- names
449
- end
450
-
451
- def assert_hash_equal?(result, target)
452
- assert_equal(result.keys.sort, target.keys.sort)
453
- result.each_key do |key|
454
- assert_equal(result[key], target[key])
455
- end
456
- end
457
- end
1
+ # -*- coding: utf-8 -*-
2
+ ##########################################################################
3
+ # test_52_name_print_titles.rb
4
+ #
5
+ # Tests for the Excel EXTERNSHEET and NAME records created by print_are()..
6
+ #
7
+ # reverse('ゥ'), September 2008, 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
+ require 'helper'
14
+ require 'stringio'
15
+
16
+ class TC_Name_Print_Titles < Test::Unit::TestCase
17
+ def setup
18
+ @test_file = StringIO.new
19
+ @workbook = WriteExcel.new(@test_file)
20
+ @workbook.not_using_tmpfile
21
+ end
22
+
23
+ def teardown
24
+ @workbook.close
25
+ end
26
+
27
+ def test_repeat_rows_for_top_row_only
28
+ worksheet1 = @workbook.add_worksheet
29
+
30
+ worksheet1.repeat_rows(0)
31
+
32
+ # Test the EXTERNSHEET record.
33
+ @workbook.calculate_extern_sizes
34
+ @workbook.store_externsheet
35
+
36
+ target = [%w(
37
+ 17 00 08 00 01 00 00 00 00 00 00 00
38
+ ).join('')].pack('H*')
39
+
40
+ caption = " \tExternsheet"
41
+ result = _unpack_externsheet(@workbook.data)
42
+ target = _unpack_externsheet(target)
43
+ assert_equal(target, result)
44
+
45
+ # Test the NAME record.
46
+ @workbook.clear_data_for_test
47
+ @workbook.store_names
48
+
49
+ target = [%w(
50
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
51
+ 00 00 00 07 3B 00 00 00 00 00 00 00 00 FF 00
52
+ ).join('')].pack('H*')
53
+
54
+ caption = " \t+ Name repeats ( Sheet1!1:1 )";
55
+ result = _unpack_name(@workbook.data)
56
+ target = _unpack_name(target)
57
+ assert_equal(target, result)
58
+ end
59
+
60
+ def test_repeat_rows_for_top_10_rows
61
+ worksheet1 = @workbook.add_worksheet
62
+
63
+ worksheet1.repeat_rows(0, 9)
64
+
65
+ # Test the EXTERNSHEET record.
66
+ @workbook.calculate_extern_sizes
67
+ @workbook.store_externsheet
68
+
69
+ target = [%w(
70
+ 17 00 08 00 01 00 00 00 00 00 00 00
71
+ ).join('')].pack('H*')
72
+
73
+ caption = " \tExternsheet"
74
+ result = _unpack_externsheet(@workbook.data)
75
+ target = _unpack_externsheet(target)
76
+ assert_equal(target, result)
77
+
78
+ # Test the NAME record.
79
+ @workbook.clear_data_for_test
80
+ @workbook.store_names
81
+
82
+ target = [%w(
83
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
84
+ 00 00 00 07 3B 00 00 00 00 09 00 00 00 FF 00
85
+ ).join('')].pack('H*')
86
+
87
+ caption = " \t+ Name repeats ( Sheet1!1:10 )";
88
+ result = _unpack_name(@workbook.data)
89
+ target = _unpack_name(target)
90
+ assert_equal(target, result)
91
+ end
92
+
93
+ def test_repeat_columns_for_a_single_column
94
+ worksheet1 = @workbook.add_worksheet
95
+
96
+ worksheet1.repeat_columns(0)
97
+
98
+ # Test the EXTERNSHEET record.
99
+ @workbook.calculate_extern_sizes
100
+ @workbook.store_externsheet
101
+
102
+ target = [%w(
103
+ 17 00 08 00 01 00 00 00 00 00 00 00
104
+ ).join('')].pack('H*')
105
+
106
+ caption = " \tExternsheet"
107
+ result = _unpack_externsheet(@workbook.data)
108
+ target = _unpack_externsheet(target)
109
+ assert_equal(target, result)
110
+
111
+ # Test the NAME record.
112
+ @workbook.clear_data_for_test
113
+ @workbook.store_names
114
+
115
+ target = [%w(
116
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
117
+ 00 00 00 07 3B 00 00 00 00 FF FF 00 00 00 00
118
+ ).join('')].pack('H*')
119
+
120
+ caption = " \t+ Name repeats ( Sheet1!A:A )";
121
+ result = _unpack_name(@workbook.data)
122
+ target = _unpack_name(target)
123
+ assert_equal(target, result)
124
+ end
125
+
126
+ def test_repeat_columns_for_a_single_column_A1_notation
127
+ worksheet1 = @workbook.add_worksheet
128
+
129
+ worksheet1.repeat_columns('A:A')
130
+
131
+ # Test the EXTERNSHEET record.
132
+ @workbook.calculate_extern_sizes
133
+ @workbook.store_externsheet
134
+
135
+ target = [%w(
136
+ 17 00 08 00 01 00 00 00 00 00 00 00
137
+ ).join('')].pack('H*')
138
+
139
+ caption = " \tExternsheet"
140
+ result = _unpack_externsheet(@workbook.data)
141
+ target = _unpack_externsheet(target)
142
+ assert_equal(target, result)
143
+
144
+ # Test the NAME record.
145
+ @workbook.clear_data_for_test
146
+ @workbook.store_names
147
+
148
+ target = [%w(
149
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
150
+ 00 00 00 07 3B 00 00 00 00 FF FF 00 00 00 00
151
+ ).join('')].pack('H*')
152
+
153
+ caption = " \t+ Name repeats ( Sheet1!A:A )";
154
+ result = _unpack_name(@workbook.data)
155
+ target = _unpack_name(target)
156
+ assert_equal(target, result)
157
+ end
158
+
159
+ def test_repeat_columns_for_a_10_columns
160
+ worksheet1 = @workbook.add_worksheet
161
+
162
+ worksheet1.repeat_columns(0, 9)
163
+
164
+ # Test the EXTERNSHEET record.
165
+ @workbook.calculate_extern_sizes
166
+ @workbook.store_externsheet
167
+
168
+ target = [%w(
169
+ 17 00 08 00 01 00 00 00 00 00 00 00
170
+ ).join('')].pack('H*')
171
+
172
+ caption = " \tExternsheet"
173
+ result = _unpack_externsheet(@workbook.data)
174
+ target = _unpack_externsheet(target)
175
+ assert_equal(target, result)
176
+
177
+ # Test the NAME record.
178
+ @workbook.clear_data_for_test
179
+ @workbook.store_names
180
+
181
+ target = [%w(
182
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
183
+ 00 00 00 07 3B 00 00 00 00 FF FF 00 00 09 00
184
+ ).join('')].pack('H*')
185
+
186
+ caption = " \t+ Name repeats ( Sheet1!A:J )";
187
+ result = _unpack_name(@workbook.data)
188
+ target = _unpack_name(target)
189
+ assert_equal(target, result)
190
+ end
191
+
192
+ def test_repeat_columns_for_a_10_columns_A1_notation
193
+ worksheet1 = @workbook.add_worksheet
194
+
195
+ worksheet1.repeat_columns('A:J')
196
+
197
+ # Test the EXTERNSHEET record.
198
+ @workbook.calculate_extern_sizes
199
+ @workbook.store_externsheet
200
+
201
+ target = [%w(
202
+ 17 00 08 00 01 00 00 00 00 00 00 00
203
+ ).join('')].pack('H*')
204
+
205
+ caption = " \tExternsheet"
206
+ result = _unpack_externsheet(@workbook.data)
207
+ target = _unpack_externsheet(target)
208
+ assert_equal(target, result)
209
+
210
+ # Test the NAME record.
211
+ @workbook.clear_data_for_test
212
+ @workbook.store_names
213
+
214
+ target = [%w(
215
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
216
+ 00 00 00 07 3B 00 00 00 00 FF FF 00 00 09 00
217
+ ).join('')].pack('H*')
218
+
219
+ caption = " \t+ Name repeats ( Sheet1!A:J )";
220
+ result = _unpack_name(@workbook.data)
221
+ target = _unpack_name(target)
222
+ assert_equal(target, result)
223
+ end
224
+
225
+ def test_repeat_rows_on_multiple_sheets
226
+ worksheet1 = @workbook.add_worksheet
227
+ worksheet2 = @workbook.add_worksheet
228
+ worksheet3 = @workbook.add_worksheet
229
+
230
+ worksheet1.repeat_rows(0, 1)
231
+ worksheet2.repeat_rows(3, 4)
232
+ worksheet3.repeat_rows(6, 7)
233
+
234
+ # Test the EXTERNSHEET record.
235
+ @workbook.calculate_extern_sizes
236
+ @workbook.store_externsheet
237
+
238
+ target = [%w(
239
+ 17 00 14 00 03 00 00 00 00 00 00 00 00 00 01 00
240
+ 01 00 00 00 02 00 02 00
241
+ ).join('')].pack('H*')
242
+
243
+ caption = " \tExternsheet"
244
+ result = _unpack_externsheet(@workbook.data)
245
+ target = _unpack_externsheet(target)
246
+ assert_equal(target, result)
247
+
248
+ # Test the NAME record.
249
+ @workbook.clear_data_for_test
250
+ @workbook.store_names
251
+
252
+ target = [%w(
253
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
254
+ 00 00 00 07 3B 00 00 00 00 01 00 00 00 FF 00
255
+
256
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 02 00 00 00
257
+ 00 00 00 07 3B 01 00 03 00 04 00 00 00 FF 00
258
+
259
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 03 00 00 00
260
+ 00 00 00 07 3B 02 00 06 00 07 00 00 00 FF 00
261
+ ).join('')].pack('H*')
262
+
263
+ caption = " \t+ Name repeats ( Sheet1!1:2, Sheet2!4:5, Sheet3!7:8 )";
264
+ result = _unpack_name(@workbook.data)
265
+ target = _unpack_name(target)
266
+ assert_equal(target, result)
267
+ end
268
+
269
+ def test_repeat_rows_on_multiple_sheets_with_sheets_spaced_out
270
+ worksheet1 = @workbook.add_worksheet
271
+ worksheet2 = @workbook.add_worksheet
272
+ worksheet3 = @workbook.add_worksheet
273
+ worksheet4 = @workbook.add_worksheet
274
+ worksheet5 = @workbook.add_worksheet
275
+
276
+ worksheet1.repeat_rows(0, 1)
277
+ worksheet3.repeat_rows(3, 4)
278
+ worksheet5.repeat_rows(6, 7)
279
+
280
+ # Test the EXTERNSHEET record.
281
+ @workbook.calculate_extern_sizes
282
+ @workbook.store_externsheet
283
+
284
+ target = [%w(
285
+ 17 00 14 00 03 00 00 00 00 00 00 00 00 00 02 00
286
+ 02 00 00 00 04 00 04 00
287
+ ).join('')].pack('H*')
288
+
289
+ caption = " \tExternsheet"
290
+ result = _unpack_externsheet(@workbook.data)
291
+ target = _unpack_externsheet(target)
292
+ assert_equal(target, result)
293
+
294
+ # Test the NAME record.
295
+ @workbook.clear_data_for_test
296
+ @workbook.store_names
297
+
298
+ target = [%w(
299
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
300
+ 00 00 00 07 3B 00 00 00 00 01 00 00 00 FF 00
301
+
302
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 03 00 00 00
303
+ 00 00 00 07 3B 01 00 03 00 04 00 00 00 FF 00
304
+
305
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 05 00 00 00
306
+ 00 00 00 07 3B 02 00 06 00 07 00 00 00 FF 00
307
+ ).join('')].pack('H*')
308
+
309
+ caption = " \t+ Name repeats ( Sheet1!1:2, Sheet3!4:5, Sheet5!7:8 )";
310
+ result = _unpack_name(@workbook.data)
311
+ target = _unpack_name(target)
312
+ assert_equal(target, result)
313
+ end
314
+
315
+ def test_repeat_rows_and_repeat_columns_together
316
+ worksheet1 = @workbook.add_worksheet
317
+
318
+ worksheet1.repeat_rows(1, 2)
319
+ worksheet1.repeat_columns(3, 4)
320
+
321
+ # Test the EXTERNSHEET record.
322
+ @workbook.calculate_extern_sizes
323
+ @workbook.store_externsheet
324
+
325
+ target = [%w(
326
+ 17 00 08 00 01 00 00 00 00 00 00 00
327
+ ).join('')].pack('H*')
328
+
329
+ caption = " \tExternsheet"
330
+ result = _unpack_externsheet(@workbook.data)
331
+ target = _unpack_externsheet(target)
332
+ assert_equal(target, result)
333
+
334
+ # Test the NAME record.
335
+ @workbook.clear_data_for_test
336
+ @workbook.store_names
337
+
338
+ target = [%w(
339
+ 18 00 2A 00 20 00 00 01 1A 00 00 00 01 00 00 00
340
+ 00 00 00 07 29 17 00 3B 00 00 00 00 FF FF 03 00
341
+ 04 00 3B 00 00 01 00 02 00 00 00 FF 00 10
342
+ ).join('')].pack('H*')
343
+
344
+ caption = " \t+ Name repeats ( Sheet1!2:3, Sheet1!D:E )";
345
+ result = _unpack_name(@workbook.data)
346
+ target = _unpack_name(target)
347
+ assert_equal(target, result)
348
+ end
349
+
350
+ ###############################################################################
351
+ #
352
+ # _unpack_externsheet()
353
+ #
354
+ # Unpack the EXTERNSHEET recordfor easier comparison.
355
+ #
356
+ def _unpack_externsheet(data)
357
+ externsheet = Hash.new
358
+
359
+ externsheet['record'] = data[0, 2].unpack('v')[0]
360
+ data[0, 2] = ''
361
+ externsheet['length'] = data[0, 2].unpack('v')[0]
362
+ data[0, 2] = ''
363
+ externsheet['count'] = data[0, 2].unpack('v')[0]
364
+ data[0, 2] = ''
365
+ externsheet['array'] = [];
366
+
367
+ externsheet['count'].times do
368
+ externsheet['array'] << data[0, 6].unpack('vvv')
369
+ data[0, 6] = ''
370
+ end
371
+ externsheet
372
+ end
373
+
374
+ ###############################################################################
375
+ #
376
+ # _unpack_name()
377
+ #
378
+ # Unpack 1 or more NAME structures into a AoH for easier comparison.
379
+ #
380
+ def _unpack_name(data)
381
+ names = Array.new
382
+ while data.length > 0
383
+ name = Hash.new
384
+
385
+ name['record'] = data[0, 2].unpack('v')[0]
386
+ data[0, 2] = ''
387
+ name['length'] = data[0, 2].unpack('v')[0]
388
+ data[0, 2] = ''
389
+ name['flags'] = data[0, 2].unpack('v')[0]
390
+ data[0, 2] = ''
391
+ name['shortcut'] = data[0, 1].unpack('C')[0]
392
+ data[0, 1] = ''
393
+ name['str_len'] = data[0, 1].unpack('C')[0]
394
+ data[0, 1] = ''
395
+ name['formula_len'] = data[0, 2].unpack('v')[0]
396
+ data[0, 2] = ''
397
+ name['itals'] = data[0, 2].unpack('v')[0]
398
+ data[0, 2] = ''
399
+ name['sheet_index'] = data[0, 2].unpack('v')[0]
400
+ data[0, 2] = ''
401
+ name['menu_len'] = data[0, 1].unpack('C')[0]
402
+ data[0, 1] = ''
403
+ name['desc_len'] = data[0, 1].unpack('C')[0]
404
+ data[0, 1] = ''
405
+ name['help_len'] = data[0, 1].unpack('C')[0]
406
+ data[0, 1] = ''
407
+ name['status_len'] = data[0, 1].unpack('C')[0]
408
+ data[0, 1] = ''
409
+ name['encoding'] = data[0, 1].unpack('C')[0]
410
+ data[0, 1] = ''
411
+
412
+ # Decode the individual flag fields.
413
+ flag = Hash.new
414
+ flag['hidden'] = name['flags'] & 0x0001
415
+ flag['function'] = name['flags'] & 0x0002
416
+ flag['vb'] = name['flags'] & 0x0004
417
+ flag['macro'] = name['flags'] & 0x0008
418
+ flag['complex'] = name['flags'] & 0x0010
419
+ flag['builtin'] = name['flags'] & 0x0020
420
+ flag['group'] = name['flags'] & 0x0FC0
421
+ flag['binary'] = name['flags'] & 0x1000
422
+ name['flags'] = flag
423
+
424
+ # Decode the string part of the NAME structure.
425
+ if name['encoding'] == 1
426
+ # UTF-16 name. Leave in hex.
427
+ name['string'] = data[0, 2 * name['str_len']].unpack('H*')[0].upcase
428
+ data[0, 2 * name['str_len']] = ''
429
+ elsif flag['builtin'] != 0
430
+ # 1 digit builtin name. Leave in hex.
431
+ name['string'] = data[0, name['str_len']].unpack('H*')[0].upcase
432
+ data[0, name['str_len']] = ''
433
+ else
434
+ # ASCII name.
435
+ name['string'] = data[0, name['str_len']].unpack('C*').pack('C*')
436
+ data[0, name['str_len']] = ''
437
+ end
438
+
439
+ # Keep the formula as a hex string.
440
+ name['formula'] = data[0, name['formula_len']].unpack('H*')[0].upcase
441
+ data[0, name['formula_len']] = ''
442
+
443
+ names << name
444
+ end
445
+ names
446
+ end
447
+
448
+ def assert_hash_equal?(result, target)
449
+ assert_equal(result.keys.sort, target.keys.sort)
450
+ result.each_key do |key|
451
+ assert_equal(result[key], target[key])
452
+ end
453
+ end
454
+ end