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,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  ##########################################################################
2
3
  # test_40_property_types.rb
3
4
  #
@@ -23,7 +24,7 @@ def test_pack_a_VT_I2
23
24
  02 00 00 00 E4 04 00 00
24
25
  ).join(' ')
25
26
 
26
- result = unpack_record( pack_VT_I2(1252) )
27
+ result = unpack_record(pack_VT_I2(1252))
27
28
  assert_equal(target, result, caption)
28
29
  end
29
30
 
@@ -35,7 +36,7 @@ def test_pack_a_VT_LPSTR_string_and_check_for_padding
35
36
  1E 00 00 00 01 00 00 00 00 00 00 00
36
37
  ).join(' ')
37
38
 
38
- result = unpack_record( pack_VT_LPSTR(string, codepage) )
39
+ result = unpack_record(pack_VT_LPSTR(string, codepage))
39
40
  assert_equal(target, result, caption)
40
41
  end
41
42
 
@@ -47,7 +48,7 @@ def test_pack_a_VT_LPSTR_string_and_check_for_padding_2
47
48
  1E 00 00 00 02 00 00 00 61 00 00 00
48
49
  ).join(' ')
49
50
 
50
- result = unpack_record( pack_VT_LPSTR(string, codepage) )
51
+ result = unpack_record(pack_VT_LPSTR(string, codepage))
51
52
  assert_equal(target, result, caption)
52
53
  end
53
54
 
@@ -59,7 +60,7 @@ def test_pack_a_VT_LPSTR_string_and_check_for_padding_3
59
60
  1E 00 00 00 03 00 00 00 62 62 00 00
60
61
  ).join(' ')
61
62
 
62
- result = unpack_record( pack_VT_LPSTR(string, codepage) )
63
+ result = unpack_record(pack_VT_LPSTR(string, codepage))
63
64
  assert_equal(target, result, caption)
64
65
  end
65
66
 
@@ -71,7 +72,7 @@ def test_pack_a_VT_LPSTR_string_and_check_for_padding_4
71
72
  1E 00 00 00 04 00 00 00 63 63 63 00
72
73
  ).join(' ')
73
74
 
74
- result = unpack_record( pack_VT_LPSTR(string, codepage) )
75
+ result = unpack_record(pack_VT_LPSTR(string, codepage))
75
76
  assert_equal(target, result, caption)
76
77
  end
77
78
 
@@ -83,7 +84,7 @@ def test_pack_a_VT_LPSTR_string_and_check_for_padding_5
83
84
  1E 00 00 00 05 00 00 00 64 64 64 64 00 00 00 00
84
85
  ).join(' ')
85
86
 
86
- result = unpack_record( pack_VT_LPSTR(string, codepage) )
87
+ result = unpack_record(pack_VT_LPSTR(string, codepage))
87
88
  assert_equal(target, result, caption)
88
89
  end
89
90
 
@@ -96,7 +97,7 @@ def test_pack_a_VT_LPSTR_string_and_check_for_padding_6
96
97
  00 00 00 00
97
98
  ).join(' ')
98
99
 
99
- result = unpack_record( pack_VT_LPSTR(string, codepage) )
100
+ result = unpack_record(pack_VT_LPSTR(string, codepage))
100
101
  assert_equal(target, result, caption)
101
102
  end
102
103
 
@@ -108,7 +109,7 @@ def test_pack_a_VT_LPSTR_UTF8_string
108
109
  1E 00 00 00 04 00 00 00 E2 98 BA 00
109
110
  ).join(' ')
110
111
 
111
- result = unpack_record( pack_VT_LPSTR(string, codepage) )
112
+ result = unpack_record(pack_VT_LPSTR(string, codepage))
112
113
  assert_equal(target, result, caption)
113
114
  end
114
115
 
@@ -120,7 +121,7 @@ def test_pack_a_VT_LPSTR_UTF8_string_2
120
121
  1E 00 00 00 05 00 00 00 61 E2 98 BA 00 00 00 00
121
122
  ).join(' ')
122
123
 
123
- result = unpack_record( pack_VT_LPSTR(string, codepage) )
124
+ result = unpack_record(pack_VT_LPSTR(string, codepage))
124
125
  assert_equal(target, result, caption)
125
126
  end
126
127
 
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  ##########################################################################
2
3
  # test_41_properties.rb
3
4
  #
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  ##########################################################################
2
3
  # test_42_set_properties.rb
3
4
  #
@@ -16,6 +17,7 @@
16
17
  #
17
18
  #########################################################################
18
19
  require 'helper'
20
+ require 'stringio'
19
21
 
20
22
  class TC_set_properties < Test::Unit::TestCase
21
23
 
@@ -24,13 +26,10 @@ def test_dummy
24
26
  end
25
27
 
26
28
  def setup
27
- t = Time.now.strftime("%Y%m%d")
28
- path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
29
- @test_file = File.join(Dir.tmpdir, path)
29
+ @test_file = StringIO.new
30
30
  end
31
31
 
32
32
  def teardown
33
- File.unlink(@test_file) if FileTest.exist?(@test_file)
34
33
  end
35
34
 
36
35
  def test_same_as_previous_plus_creation_date
@@ -86,7 +85,7 @@ def test_same_as_previous_plus_creation_date
86
85
 
87
86
  ###############################################################################
88
87
  #
89
- # Test 3. _get_property_set_codepage() for perl 5.8 utf8 strings.
88
+ # Test 3. _get_property_set_codepage() for utf8 strings.
90
89
  #
91
90
  params = {
92
91
  :title => 'Title' + smiley,
@@ -130,7 +129,7 @@ def test_same_as_previous_plus_creation_date
130
129
  02 00 00 00 E4 04 00 00
131
130
  ).join(' ')
132
131
 
133
- result = unpack_record( workbook.summary )
132
+ result = unpack_record(workbook.summary)
134
133
  assert_equal(target, result, caption)
135
134
 
136
135
  ###############################################################################
@@ -153,7 +152,7 @@ def test_same_as_previous_plus_creation_date
153
152
  1E 00 00 00 06 00 00 00 54 69 74 6C 65 00 00 00
154
153
  ).join(' ')
155
154
 
156
- result = unpack_record( workbook.summary )
155
+ result = unpack_record(workbook.summary)
157
156
  assert_equal(target, result, caption)
158
157
 
159
158
  ###############################################################################
@@ -179,7 +178,7 @@ def test_same_as_previous_plus_creation_date
179
178
  53 75 62 6A 65 63 74 00
180
179
  ).join(' ')
181
180
 
182
- result = unpack_record( workbook.summary )
181
+ result = unpack_record(workbook.summary)
183
182
  assert_equal(target, result, caption)
184
183
 
185
184
  ###############################################################################
@@ -207,7 +206,7 @@ def test_same_as_previous_plus_creation_date
207
206
  1E 00 00 00 07 00 00 00 41 75 74 68 6F 72 00 00
208
207
  ).join(' ')
209
208
 
210
- result = unpack_record( workbook.summary )
209
+ result = unpack_record(workbook.summary)
211
210
  assert_equal(target, result, caption)
212
211
 
213
212
  ###############################################################################
@@ -238,7 +237,7 @@ def test_same_as_previous_plus_creation_date
238
237
  4B 65 79 77 6F 72 64 73 00 00 00 00
239
238
  ).join(' ')
240
239
 
241
- result = unpack_record( workbook.summary )
240
+ result = unpack_record(workbook.summary)
242
241
  assert_equal(target, result, caption)
243
242
 
244
243
  ###############################################################################
@@ -272,7 +271,7 @@ def test_same_as_previous_plus_creation_date
272
271
  65 6E 74 73 00 00 00 00
273
272
  ).join(' ')
274
273
 
275
- result = unpack_record( workbook.summary )
274
+ result = unpack_record(workbook.summary)
276
275
  assert_equal(target, result, caption)
277
276
 
278
277
  ###############################################################################
@@ -309,7 +308,7 @@ def test_same_as_previous_plus_creation_date
309
308
  00 00 00 00
310
309
  ).join(' ')
311
310
 
312
- result = unpack_record( workbook.summary )
311
+ result = unpack_record(workbook.summary)
313
312
  assert_equal(target, result, caption)
314
313
 
315
314
  ###############################################################################
@@ -353,7 +352,7 @@ def test_same_as_previous_plus_creation_date
353
352
  80 74 89 21 52 02 C9 01
354
353
  ).join(' ')
355
354
 
356
- result = unpack_record( workbook.summary )
355
+ result = unpack_record(workbook.summary)
357
356
  assert_equal(target, result, caption)
358
357
 
359
358
  ###############################################################################
@@ -396,7 +395,7 @@ def test_same_as_previous_plus_creation_date
396
395
  80 74 89 21 52 02 C9 01
397
396
  ).join(' ')
398
397
 
399
- result = unpack_record( workbook.summary )
398
+ result = unpack_record(workbook.summary)
400
399
  assert_equal(target, result, caption)
401
400
 
402
401
  ###############################################################################
@@ -420,7 +419,7 @@ def test_same_as_previous_plus_creation_date
420
419
  00 00 00 00
421
420
  ).join(' ')
422
421
 
423
- result = unpack_record( workbook.summary )
422
+ result = unpack_record(workbook.summary)
424
423
  assert_equal(target, result, caption)
425
424
 
426
425
  workbook.close
@@ -1,302 +1,299 @@
1
- ##########################################################################
2
- # test_50_name_stored.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_Stored < Test::Unit::TestCase
16
- def setup
17
- @test_file = StringIO.new
18
- @workbook = WriteExcel.new(@test_file)
19
- @worksheet = @workbook.add_worksheet
20
- end
21
-
22
- def test_print_area_name_with_simple_range
23
- caption = " \tNAME for worksheet1.print_area('A1:B12')"
24
- name = [0x06].pack('C')
25
- encoding = 0
26
- sheet_index = 1
27
- formula = ['3B000000000B0000000100'].pack('H*')
28
-
29
- result = @workbook.store_name(
30
- name,
31
- encoding,
32
- sheet_index,
33
- formula
34
- )
35
- target = [%w(
36
- 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
37
- 00 00 00 06 3B 00 00 00 00 0B 00 00 00 01 00
38
- ).join('')].pack('H*')
39
-
40
- result = _unpack_name(result)
41
- target = _unpack_name(target)
42
- assert_equal(result, target)
43
- end
44
-
45
- def test_print_area_name_with_simple_range_in_sheet_3
46
- caption = " \tNAME for worksheet3.print_area('G7:H8')"
47
- name = [0x06].pack('C')
48
- encoding = 0
49
- sheet_index = 3
50
- formula = ['3B02000600070006000700'].pack('H*')
51
-
52
- result = @workbook.store_name(
53
- name,
54
- encoding,
55
- sheet_index,
56
- formula
57
- )
58
-
59
- target = [%w(
60
- 18 00 1B 00 20 00 00 01 0B 00 00 00 03 00 00 00
61
- 00 00 00 06 3B 02 00 06 00 07 00 06 00 07 00
62
- ).join('')].pack('H*')
63
-
64
- result = _unpack_name(result)
65
- target = _unpack_name(target)
66
- assert_equal(result, target)
67
- end
68
-
69
- def test_for_repeat_rows_name
70
- caption = " \tNAME for worksheet1.repeat_rows(0, 9)"
71
- name = [0x07].pack('C')
72
- encoding = 0
73
- sheet_index = 1
74
- formula = ['3B0000000009000000FF00'].pack('H*')
75
-
76
- result = @workbook.store_name(
77
- name,
78
- encoding,
79
- sheet_index,
80
- formula
81
- )
82
-
83
- target = [%w(
84
- 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
85
- 00 00 00 07 3B 00 00 00 00 09 00 00 00 FF 00
86
- ).join('')].pack('H*')
87
-
88
- result = _unpack_name(result)
89
- target = _unpack_name(target)
90
- assert_equal(result, target)
91
- end
92
-
93
- def test_for_repeat_rows_name_on_sheet_3
94
- caption = " \tNAME for worksheet3.repeat_rows(6, 7)"
95
- name = [0x07].pack('C')
96
- encoding = 0
97
- sheet_index = 1
98
- formula = ['3B0000000009000000FF00'].pack('H*')
99
-
100
- result = @workbook.store_name(
101
- name,
102
- encoding,
103
- sheet_index,
104
- formula
105
- )
106
-
107
- target = [%w(
108
- 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
109
- 00 00 00 07 3B 00 00 00 00 09 00 00 00 FF 00
110
- ).join('')].pack('H*')
111
-
112
- result = _unpack_name(result)
113
- target = _unpack_name(target)
114
- assert_equal(result, target)
115
- end
116
-
117
- def test_for_repeat_columns_name
118
- caption = " \tNAME for worksheet1.repeat_columns('A:J')"
119
- name = [0x07].pack('C')
120
- encoding = 0
121
- sheet_index = 1
122
- formula = ['3B00000000FFFF00000900'].pack('H*')
123
-
124
- result = @workbook.store_name(
125
- name,
126
- encoding,
127
- sheet_index,
128
- formula
129
- )
130
-
131
- target = [%w(
132
- 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
133
- 00 00 00 07 3B 00 00 00 00 FF FF 00 00 09 00
134
- ).join('')].pack('H*')
135
-
136
- result = _unpack_name(result)
137
- target = _unpack_name(target)
138
- assert_equal(result, target)
139
- end
140
-
141
- def test_for_repeat_rows_and_repeat_columns_together_name
142
- caption = " \tNAME for repeat_rows(1, 2) repeat_columns(3, 4)"
143
- name = [0x07].pack('C')
144
- encoding = 0
145
- sheet_index = 1
146
- formula = ['2917003B00000000FFFF030004003B0000010002000000FF0010'].pack('H*')
147
-
148
- result = @workbook.store_name(
149
- name,
150
- encoding,
151
- sheet_index,
152
- formula
153
- )
154
-
155
- target = [%w(
156
- 18 00 2A 00 20 00 00 01 1A 00 00 00 01 00 00 00
157
- 00 00 00 07 29 17 00 3B 00 00 00 00 FF FF 03 00
158
- 04 00 3B 00 00 01 00 02 00 00 00 FF 00 10
159
- ).join('')].pack('H*')
160
-
161
- result = _unpack_name(result)
162
- target = _unpack_name(target)
163
- assert_equal(result, target)
164
- end
165
-
166
- def test_for_print_area_name_with_simple_range
167
- caption = " \tNAME for worksheet1.autofilter('A1:C5')"
168
- name = [0x0D].pack('C')
169
- encoding = 0
170
- sheet_index = 1
171
- formula = ['3B00000000040000000200'].pack('H*')
172
-
173
- result = @workbook.store_name(
174
- name,
175
- encoding,
176
- sheet_index,
177
- formula
178
- )
179
-
180
- target = [%w(
181
- 18 00 1B 00 21 00 00 01 0B 00 00 00 01 00 00 00
182
- 00 00 00 0D 3B 00 00 00 00 04 00 00 00 02 00
183
- ).join('')].pack('H*')
184
-
185
- result = _unpack_name(result)
186
- target = _unpack_name(target)
187
- assert_equal(result, target)
188
- end
189
-
190
- def test_for_define_name_global_name
191
- caption = " \tNAME for worksheet1.define_name('Foo', ...)"
192
- name = 'Foo'
193
- encoding = 0
194
- sheet_index = 0
195
- formula = ['3A000007000100'].pack('H*')
196
-
197
- result = @workbook.store_name(
198
- name,
199
- encoding,
200
- sheet_index,
201
- formula
202
- )
203
-
204
- target = [%w(
205
- 18 00 19 00 00 00 00 03 07 00 00 00 00 00 00 00
206
- 00 00 00 46 6F 6F 3A 00 00 07 00 01 00
207
- ).join('')].pack('H*')
208
-
209
- result = _unpack_name(result)
210
- target = _unpack_name(target)
211
- assert_equal(result, target)
212
- end
213
-
214
- ###############################################################################
215
- #
216
- # Unpack the binary data into a format suitable for printing in tests.
217
- #
218
- def unpack_record(data)
219
- data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
220
- end
221
-
222
- ###############################################################################
223
- #
224
- # _unpack_name()
225
- #
226
- # Unpack 1 or more NAME structures into a AoH for easier comparison.
227
- #
228
- def _unpack_name(data)
229
- names = Array.new
230
- while data.length > 0
231
- name = Hash.new
232
-
233
- name['record'] = data[0, 2].unpack('v')[0]
234
- data[0, 2] = ''
235
- name['length'] = data[0, 2].unpack('v')[0]
236
- data[0, 2] = ''
237
- name['flags'] = data[0, 2].unpack('v')[0]
238
- data[0, 2] = ''
239
- name['shortcut'] = data[0, 1].unpack('C')[0]
240
- data[0, 1] = ''
241
- name['str_len'] = data[0, 1].unpack('C')[0]
242
- data[0, 1] = ''
243
- name['formula_len'] = data[0, 2].unpack('v')[0]
244
- data[0, 2] = ''
245
- name['itals'] = data[0, 2].unpack('v')[0]
246
- data[0, 2] = ''
247
- name['sheet_index'] = data[0, 2].unpack('v')[0]
248
- data[0, 2] = ''
249
- name['menu_len'] = data[0, 1].unpack('C')[0]
250
- data[0, 1] = ''
251
- name['desc_len'] = data[0, 1].unpack('C')[0]
252
- data[0, 1] = ''
253
- name['help_len'] = data[0, 1].unpack('C')[0]
254
- data[0, 1] = ''
255
- name['status_len'] = data[0, 1].unpack('C')[0]
256
- data[0, 1] = ''
257
- name['encoding'] = data[0, 1].unpack('C')[0]
258
- data[0, 1] = ''
259
-
260
- # Decode the individual flag fields.
261
- flag = Hash.new
262
- flag['hidden'] = name['flags'] & 0x0001
263
- flag['function'] = name['flags'] & 0x0002
264
- flag['vb'] = name['flags'] & 0x0004
265
- flag['macro'] = name['flags'] & 0x0008
266
- flag['complex'] = name['flags'] & 0x0010
267
- flag['builtin'] = name['flags'] & 0x0020
268
- flag['group'] = name['flags'] & 0x0FC0
269
- flag['binary'] = name['flags'] & 0x1000
270
- name['flags'] = flag
271
-
272
- # Decode the string part of the NAME structure.
273
- if name['encoding'] == 1
274
- # UTF-16 name. Leave in hex.
275
- name['string'] = data[0, 2 * name['str_len']].unpack('H*')[0].upcase
276
- data[0, 2 * name['str_len']] = ''
277
- elsif flag['builtin'] != 0
278
- # 1 digit builtin name. Leave in hex.
279
- name['string'] = data[0, name['str_len']].unpack('H*')[0].upcase
280
- data[0, name['str_len']] = ''
281
- else
282
- # ASCII name.
283
- name['string'] = data[0, name['str_len']].unpack('C*').pack('C*')
284
- data[0, name['str_len']] = ''
285
- end
286
-
287
- # Keep the formula as a hex string.
288
- name['formula'] = data[0, name['formula_len']].unpack('H*')[0].upcase
289
- data[0, name['formula_len']] = ''
290
-
291
- names << name
292
- end
293
- names
294
- end
295
-
296
- def assert_hash_equal?(result, target)
297
- assert_equal(result.keys.sort, target.keys.sort)
298
- result.each_key do |key|
299
- assert_equal(result[key], target[key])
300
- end
301
- end
302
- end
1
+ # -*- coding: utf-8 -*-
2
+ ##########################################################################
3
+ # test_50_name_stored.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_Stored < Test::Unit::TestCase
17
+ def setup
18
+ @test_file = StringIO.new
19
+ @workbook = WriteExcel.new(@test_file)
20
+ @worksheet = @workbook.add_worksheet
21
+ end
22
+
23
+ def teardown
24
+ @workbook.close
25
+ end
26
+
27
+ def test_print_area_name_with_simple_range
28
+ caption = " \tNAME for worksheet1.print_area('A1:B12')"
29
+ name = [0x06].pack('C')
30
+ encoding = 0
31
+ sheet_index = 1
32
+ formula = ['3B000000000B0000000100'].pack('H*')
33
+
34
+ result = @workbook.store_name(
35
+ name,
36
+ encoding,
37
+ sheet_index,
38
+ formula
39
+ )
40
+ target = [%w(
41
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
42
+ 00 00 00 06 3B 00 00 00 00 0B 00 00 00 01 00
43
+ ).join('')].pack('H*')
44
+
45
+ # result = _unpack_name(result)
46
+ # target = _unpack_name(target)
47
+ assert_equal(unpack_record(target), unpack_record(result))
48
+ end
49
+
50
+ def test_print_area_name_with_simple_range_in_sheet_3
51
+ caption = " \tNAME for worksheet3.print_area('G7:H8')"
52
+ name = [0x06].pack('C')
53
+ encoding = 0
54
+ sheet_index = 3
55
+ formula = ['3B02000600070006000700'].pack('H*')
56
+
57
+ result = @workbook.store_name(
58
+ name,
59
+ encoding,
60
+ sheet_index,
61
+ formula
62
+ )
63
+
64
+ target = [%w(
65
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 03 00 00 00
66
+ 00 00 00 06 3B 02 00 06 00 07 00 06 00 07 00
67
+ ).join('')].pack('H*')
68
+
69
+ # result = _unpack_name(result)
70
+ # target = _unpack_name(target)
71
+ assert_equal(unpack_record(target), unpack_record(result))
72
+ end
73
+
74
+ def test_for_repeat_rows_name
75
+ caption = " \tNAME for worksheet1.repeat_rows(0, 9)"
76
+ name = [0x07].pack('C')
77
+ encoding = 0
78
+ sheet_index = 1
79
+ formula = ['3B0000000009000000FF00'].pack('H*')
80
+
81
+ result = @workbook.store_name(
82
+ name,
83
+ encoding,
84
+ sheet_index,
85
+ formula
86
+ )
87
+
88
+ target = [%w(
89
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
90
+ 00 00 00 07 3B 00 00 00 00 09 00 00 00 FF 00
91
+ ).join('')].pack('H*')
92
+
93
+ # result = _unpack_name(result)
94
+ # target = _unpack_name(target)
95
+ assert_equal(unpack_record(target), unpack_record(result))
96
+ end
97
+
98
+ def test_for_repeat_rows_name_on_sheet_3
99
+ caption = " \tNAME for worksheet3.repeat_rows(6, 7)"
100
+ name = [0x07].pack('C')
101
+ encoding = 0
102
+ sheet_index = 1
103
+ formula = ['3B0000000009000000FF00'].pack('H*')
104
+
105
+ result = @workbook.store_name(
106
+ name,
107
+ encoding,
108
+ sheet_index,
109
+ formula
110
+ )
111
+
112
+ target = [%w(
113
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
114
+ 00 00 00 07 3B 00 00 00 00 09 00 00 00 FF 00
115
+ ).join('')].pack('H*')
116
+
117
+ # result = _unpack_name(result)
118
+ # target = _unpack_name(target)
119
+ assert_equal(unpack_record(target), unpack_record(result))
120
+ end
121
+
122
+ def test_for_repeat_columns_name
123
+ caption = " \tNAME for worksheet1.repeat_columns('A:J')"
124
+ name = [0x07].pack('C')
125
+ encoding = 0
126
+ sheet_index = 1
127
+ formula = ['3B00000000FFFF00000900'].pack('H*')
128
+
129
+ result = @workbook.store_name(
130
+ name,
131
+ encoding,
132
+ sheet_index,
133
+ formula
134
+ )
135
+
136
+ target = [%w(
137
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
138
+ 00 00 00 07 3B 00 00 00 00 FF FF 00 00 09 00
139
+ ).join('')].pack('H*')
140
+
141
+ # result = _unpack_name(result)
142
+ # target = _unpack_name(target)
143
+ assert_equal(unpack_record(target), unpack_record(result))
144
+ end
145
+
146
+ def test_for_repeat_rows_and_repeat_columns_together_name
147
+ caption = " \tNAME for repeat_rows(1, 2) repeat_columns(3, 4)"
148
+ name = [0x07].pack('C')
149
+ encoding = 0
150
+ sheet_index = 1
151
+ formula = ['2917003B00000000FFFF030004003B0000010002000000FF0010'].pack('H*')
152
+
153
+ result = @workbook.store_name(
154
+ name,
155
+ encoding,
156
+ sheet_index,
157
+ formula
158
+ )
159
+
160
+ target = [%w(
161
+ 18 00 2A 00 20 00 00 01 1A 00 00 00 01 00 00 00
162
+ 00 00 00 07 29 17 00 3B 00 00 00 00 FF FF 03 00
163
+ 04 00 3B 00 00 01 00 02 00 00 00 FF 00 10
164
+ ).join('')].pack('H*')
165
+
166
+ # result = _unpack_name(result)
167
+ # target = _unpack_name(target)
168
+ assert_equal(unpack_record(target), unpack_record(result))
169
+ end
170
+
171
+ def test_for_print_area_name_with_simple_range
172
+ caption = " \tNAME for worksheet1.autofilter('A1:C5')"
173
+ name = [0x0D].pack('C')
174
+ encoding = 0
175
+ sheet_index = 1
176
+ formula = ['3B00000000040000000200'].pack('H*')
177
+
178
+ result = @workbook.store_name(
179
+ name,
180
+ encoding,
181
+ sheet_index,
182
+ formula
183
+ )
184
+
185
+ target = [%w(
186
+ 18 00 1B 00 21 00 00 01 0B 00 00 00 01 00 00 00
187
+ 00 00 00 0D 3B 00 00 00 00 04 00 00 00 02 00
188
+ ).join('')].pack('H*')
189
+
190
+ # result = _unpack_name(result)
191
+ # target = _unpack_name(target)
192
+ assert_equal(unpack_record(target), unpack_record(result))
193
+ end
194
+
195
+ def test_for_define_name_global_name
196
+ caption = " \tNAME for worksheet1.define_name('Foo', ...)"
197
+ name = 'Foo'
198
+ encoding = 0
199
+ sheet_index = 0
200
+ formula = ['3A000007000100'].pack('H*')
201
+
202
+ result = @workbook.store_name(
203
+ name,
204
+ encoding,
205
+ sheet_index,
206
+ formula
207
+ )
208
+
209
+ target = [%w(
210
+ 18 00 19 00 00 00 00 03 07 00 00 00 00 00 00 00
211
+ 00 00 00 46 6F 6F 3A 00 00 07 00 01 00
212
+ ).join('')].pack('H*')
213
+
214
+ # result = _unpack_name(result)
215
+ # target = _unpack_name(target)
216
+ assert_equal(unpack_record(target), unpack_record(result))
217
+ end
218
+
219
+ ###############################################################################
220
+ #
221
+ # _unpack_name()
222
+ #
223
+ # Unpack 1 or more NAME structures into a AoH for easier comparison.
224
+ #
225
+ def _unpack_name(data)
226
+ names = Array.new
227
+ while data.length > 0
228
+ name = Hash.new
229
+
230
+ name['record'] = data[0, 2].unpack('v')[0]
231
+ data[0, 2] = ''
232
+ name['length'] = data[0, 2].unpack('v')[0]
233
+ data[0, 2] = ''
234
+ name['flags'] = data[0, 2].unpack('v')[0]
235
+ data[0, 2] = ''
236
+ name['shortcut'] = data[0, 1].unpack('C')[0]
237
+ data[0, 1] = ''
238
+ name['str_len'] = data[0, 1].unpack('C')[0]
239
+ data[0, 1] = ''
240
+ name['formula_len'] = data[0, 2].unpack('v')[0]
241
+ data[0, 2] = ''
242
+ name['itals'] = data[0, 2].unpack('v')[0]
243
+ data[0, 2] = ''
244
+ name['sheet_index'] = data[0, 2].unpack('v')[0]
245
+ data[0, 2] = ''
246
+ name['menu_len'] = data[0, 1].unpack('C')[0]
247
+ data[0, 1] = ''
248
+ name['desc_len'] = data[0, 1].unpack('C')[0]
249
+ data[0, 1] = ''
250
+ name['help_len'] = data[0, 1].unpack('C')[0]
251
+ data[0, 1] = ''
252
+ name['status_len'] = data[0, 1].unpack('C')[0]
253
+ data[0, 1] = ''
254
+ name['encoding'] = data[0, 1].unpack('C')[0]
255
+ data[0, 1] = ''
256
+
257
+ # Decode the individual flag fields.
258
+ flag = Hash.new
259
+ flag['hidden'] = name['flags'] & 0x0001
260
+ flag['function'] = name['flags'] & 0x0002
261
+ flag['vb'] = name['flags'] & 0x0004
262
+ flag['macro'] = name['flags'] & 0x0008
263
+ flag['complex'] = name['flags'] & 0x0010
264
+ flag['builtin'] = name['flags'] & 0x0020
265
+ flag['group'] = name['flags'] & 0x0FC0
266
+ flag['binary'] = name['flags'] & 0x1000
267
+ name['flags'] = flag
268
+
269
+ # Decode the string part of the NAME structure.
270
+ if name['encoding'] == 1
271
+ # UTF-16 name. Leave in hex.
272
+ name['string'] = data[0, 2 * name['str_len']].unpack('H*')[0].upcase
273
+ data[0, 2 * name['str_len']] = ''
274
+ elsif flag['builtin'] != 0
275
+ # 1 digit builtin name. Leave in hex.
276
+ name['string'] = data[0, name['str_len']].unpack('H*')[0].upcase
277
+ data[0, name['str_len']] = ''
278
+ else
279
+ # ASCII name.
280
+ name['string'] = data[0, name['str_len']].unpack('C*').pack('C*')
281
+ data[0, name['str_len']] = ''
282
+ end
283
+
284
+ # Keep the formula as a hex string.
285
+ name['formula'] = data[0, name['formula_len']].unpack('H*')[0].upcase
286
+ data[0, name['formula_len']] = ''
287
+
288
+ names << name
289
+ end
290
+ names
291
+ end
292
+
293
+ def assert_hash_equal?(result, target)
294
+ assert_equal(result.keys.sort, target.keys.sort)
295
+ result.each_key do |key|
296
+ assert_equal(result[key], target[key])
297
+ end
298
+ end
299
+ end