writeexcel 0.3.5 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitattributes +1 -0
- data/README.rdoc +12 -6
- data/VERSION +1 -1
- data/charts/chartex.rb +316 -315
- data/charts/demo1.rb +1 -0
- data/charts/demo2.rb +1 -0
- data/charts/demo3.rb +117 -116
- data/charts/demo4.rb +119 -118
- data/charts/demo5.rb +48 -47
- data/examples/a_simple.rb +1 -0
- data/examples/autofilter.rb +1 -0
- data/examples/bigfile.rb +30 -29
- data/examples/chart_area.rb +121 -120
- data/examples/chart_bar.rb +120 -119
- data/examples/chart_column.rb +120 -119
- data/examples/chart_line.rb +120 -119
- data/examples/chart_pie.rb +108 -107
- data/examples/chart_scatter.rb +121 -120
- data/examples/chart_stock.rb +148 -147
- data/examples/chess.rb +1 -0
- data/examples/colors.rb +1 -0
- data/examples/comments1.rb +1 -0
- data/examples/comments2.rb +3 -2
- data/examples/copyformat.rb +1 -0
- data/examples/data_validate.rb +1 -0
- data/examples/date_time.rb +1 -0
- data/examples/defined_name.rb +1 -0
- data/examples/demo.rb +1 -0
- data/examples/diag_border.rb +1 -0
- data/examples/formats.rb +1 -0
- data/examples/formula_result.rb +1 -0
- data/examples/header.rb +1 -0
- data/examples/hide_sheet.rb +1 -0
- data/examples/hyperlink.rb +1 -0
- data/examples/images.rb +1 -0
- data/examples/indent.rb +1 -0
- data/examples/merge1.rb +1 -0
- data/examples/merge2.rb +1 -0
- data/examples/merge3.rb +1 -0
- data/examples/merge4.rb +1 -0
- data/examples/merge5.rb +1 -0
- data/examples/merge6.rb +67 -66
- data/examples/outline.rb +1 -0
- data/examples/outline_collapsed.rb +1 -0
- data/examples/panes.rb +1 -0
- data/examples/properties.rb +1 -0
- data/examples/properties_jp.rb +1 -0
- data/examples/protection.rb +1 -0
- data/examples/regions.rb +1 -0
- data/examples/repeat.rb +1 -0
- data/examples/right_to_left.rb +1 -0
- data/examples/row_wrap.rb +1 -0
- data/examples/stats.rb +1 -0
- data/examples/stocks.rb +1 -0
- data/examples/tab_colors.rb +1 -0
- data/examples/write_arrays.rb +1 -0
- data/lib/writeexcel.rb +6 -1
- data/lib/writeexcel/biffwriter.rb +21 -20
- data/lib/writeexcel/chart.rb +25 -12
- data/lib/writeexcel/charts/area.rb +153 -152
- data/lib/writeexcel/charts/bar.rb +178 -177
- data/lib/writeexcel/charts/column.rb +157 -156
- data/lib/writeexcel/charts/external.rb +62 -61
- data/lib/writeexcel/charts/line.rb +153 -152
- data/lib/writeexcel/charts/pie.rb +170 -169
- data/lib/writeexcel/charts/scatter.rb +4 -3
- data/lib/writeexcel/charts/stock.rb +212 -211
- data/lib/writeexcel/compatibility.rb +320 -0
- data/lib/writeexcel/excelformulaparser.rb +587 -586
- data/lib/writeexcel/format.rb +12 -13
- data/lib/writeexcel/formula.rb +30 -28
- data/lib/writeexcel/helper.rb +23 -0
- data/lib/writeexcel/olewriter.rb +5 -16
- data/lib/writeexcel/properties.rb +43 -54
- data/lib/writeexcel/storage_lite.rb +981 -968
- data/lib/writeexcel/workbook.rb +94 -73
- data/lib/writeexcel/worksheet.rb +230 -210
- data/test/helper.rb +19 -0
- data/test/test_00_IEEE_double.rb +1 -0
- data/test/test_01_add_worksheet.rb +1 -0
- data/test/test_02_merge_formats.rb +3 -5
- data/test/test_04_dimensions.rb +3 -5
- data/test/test_05_rows.rb +6 -6
- data/test/test_06_extsst.rb +8 -8
- data/test/test_11_date_time.rb +3 -5
- data/test/test_12_date_only.rb +3 -5
- data/test/test_13_date_seconds.rb +4 -6
- data/test/test_21_escher.rb +3 -5
- data/test/test_22_mso_drawing_group.rb +20 -22
- data/test/test_23_note.rb +5 -7
- data/test/test_24_txo.rb +3 -5
- data/test/test_25_position_object.rb +84 -79
- data/test/test_26_autofilter.rb +3 -13
- data/test/test_27_autofilter.rb +3 -13
- data/test/test_28_autofilter.rb +3 -13
- data/test/test_29_process_jpg.rb +5 -0
- data/test/test_30_validation_dval.rb +3 -5
- data/test/test_31_validation_dv_strings.rb +3 -5
- data/test/test_32_validation_dv_formula.rb +3 -5
- data/test/test_40_property_types.rb +10 -9
- data/test/test_41_properties.rb +1 -0
- data/test/test_42_set_properties.rb +14 -15
- data/test/test_50_name_stored.rb +299 -302
- data/test/test_51_name_print_area.rb +357 -360
- data/test/test_52_name_print_titles.rb +454 -457
- data/test/test_53_autofilter.rb +203 -206
- data/test/test_60_chart_generic.rb +5 -0
- data/test/test_61_chart_subclasses.rb +95 -94
- data/test/test_62_chart_formats.rb +272 -267
- data/test/test_63_chart_area_formats.rb +649 -644
- data/test/test_biff.rb +12 -38
- data/test/test_compatibility.rb +627 -0
- data/test/test_example_match.rb +3 -18
- data/test/test_format.rb +46 -105
- data/test/test_formula.rb +1 -0
- data/test/test_ole.rb +3 -4
- data/test/test_storage_lite.rb +125 -146
- data/test/test_workbook.rb +2 -23
- data/test/test_worksheet.rb +4 -5
- data/utils/add_magic_comment.rb +80 -0
- data/writeexcel.gemspec +8 -2
- 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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
124
|
+
result = unpack_record(pack_VT_LPSTR(string, codepage))
|
124
125
|
assert_equal(target, result, caption)
|
125
126
|
end
|
126
127
|
|
data/test/test_41_properties.rb
CHANGED
@@ -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
|
-
|
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
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
422
|
+
result = unpack_record(workbook.summary)
|
424
423
|
assert_equal(target, result, caption)
|
425
424
|
|
426
425
|
workbook.close
|
data/test/test_50_name_stored.rb
CHANGED
@@ -1,302 +1,299 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
require '
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@
|
19
|
-
@
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
#
|
224
|
-
#
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
data[0, 2]
|
235
|
-
|
236
|
-
data[0,
|
237
|
-
|
238
|
-
data[0,
|
239
|
-
|
240
|
-
data[0,
|
241
|
-
|
242
|
-
data[0,
|
243
|
-
|
244
|
-
data[0, 2]
|
245
|
-
|
246
|
-
data[0,
|
247
|
-
|
248
|
-
data[0,
|
249
|
-
|
250
|
-
data[0, 1]
|
251
|
-
|
252
|
-
data[0, 1]
|
253
|
-
|
254
|
-
data[0, 1]
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
flag
|
262
|
-
flag['
|
263
|
-
flag['
|
264
|
-
flag['
|
265
|
-
flag['
|
266
|
-
flag['
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
name['
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
data[0,
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
data[0, name['str_len']]
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
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
|