WriteExcel 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +47 -0
- data/VERSION +1 -0
- data/examples/a_simple.rb +42 -0
- data/examples/autofilters.rb +266 -0
- data/examples/bigfile.rb +30 -0
- data/examples/copyformat.rb +51 -0
- data/examples/data_validate.rb +278 -0
- data/examples/date_time.rb +86 -0
- data/examples/demo.rb +118 -0
- data/examples/diag_border.rb +35 -0
- data/examples/formats.rb +489 -0
- data/examples/header.rb +136 -0
- data/examples/hidden.rb +28 -0
- data/examples/hyperlink.rb +42 -0
- data/examples/images.rb +52 -0
- data/examples/merge1.rb +39 -0
- data/examples/merge2.rb +44 -0
- data/examples/merge3.rb +65 -0
- data/examples/merge4.rb +82 -0
- data/examples/merge5.rb +79 -0
- data/examples/protection.rb +46 -0
- data/examples/regions.rb +52 -0
- data/examples/repeat.rb +42 -0
- data/examples/stats.rb +75 -0
- data/examples/stocks.rb +80 -0
- data/examples/tab_colors.rb +30 -0
- data/lib/WriteExcel.rb +30 -0
- data/lib/WriteExcel/biffwriter.rb +259 -0
- data/lib/WriteExcel/chart.rb +217 -0
- data/lib/WriteExcel/excelformula.y +138 -0
- data/lib/WriteExcel/excelformulaparser.rb +573 -0
- data/lib/WriteExcel/format.rb +1108 -0
- data/lib/WriteExcel/formula.rb +986 -0
- data/lib/WriteExcel/olewriter.rb +322 -0
- data/lib/WriteExcel/properties.rb +250 -0
- data/lib/WriteExcel/storage_lite.rb +590 -0
- data/lib/WriteExcel/workbook.rb +2602 -0
- data/lib/WriteExcel/worksheet.rb +6378 -0
- data/spec/WriteExcel_spec.rb +7 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- data/test/tc_all.rb +31 -0
- data/test/tc_biff.rb +104 -0
- data/test/tc_chart.rb +22 -0
- data/test/tc_example_match.rb +1280 -0
- data/test/tc_format.rb +1264 -0
- data/test/tc_formula.rb +63 -0
- data/test/tc_ole.rb +110 -0
- data/test/tc_storage_lite.rb +102 -0
- data/test/tc_workbook.rb +115 -0
- data/test/tc_worksheet.rb +115 -0
- data/test/test_00_IEEE_double.rb +14 -0
- data/test/test_01_add_worksheet.rb +12 -0
- data/test/test_02_merge_formats.rb +58 -0
- data/test/test_04_dimensions.rb +397 -0
- data/test/test_05_rows.rb +182 -0
- data/test/test_06_extsst.rb +80 -0
- data/test/test_11_date_time.rb +484 -0
- data/test/test_12_date_only.rb +506 -0
- data/test/test_13_date_seconds.rb +486 -0
- data/test/test_21_escher.rb +629 -0
- data/test/test_22_mso_drawing_group.rb +739 -0
- data/test/test_23_note.rb +78 -0
- data/test/test_24_txo.rb +80 -0
- data/test/test_26_autofilter.rb +327 -0
- data/test/test_27_autofilter.rb +144 -0
- data/test/test_28_autofilter.rb +174 -0
- data/test/test_29_process_jpg.rb +131 -0
- data/test/test_30_validation_dval.rb +82 -0
- data/test/test_31_validation_dv_strings.rb +131 -0
- data/test/test_32_validation_dv_formula.rb +211 -0
- data/test/test_40_property_types.rb +191 -0
- data/test/test_41_properties.rb +238 -0
- data/test/test_42_set_properties.rb +430 -0
- data/test/ts_all.rb +34 -0
- metadata +154 -0
@@ -0,0 +1,238 @@
|
|
1
|
+
##########################################################################
|
2
|
+
# test_41_properties.rb
|
3
|
+
#
|
4
|
+
# Tests for OLE property sets.
|
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_properties < Test::Unit::TestCase
|
19
|
+
|
20
|
+
def setup
|
21
|
+
@smiley = '☺' # chr 0x263A; in perl
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_codepage_only
|
25
|
+
properties = [[0x0001, 'VT_I2', 0x04E4]]
|
26
|
+
caption = " \tDoc properties: _create_property_set('Code page')"
|
27
|
+
target = %w(
|
28
|
+
FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
|
29
|
+
00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
|
30
|
+
F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
|
31
|
+
18 00 00 00 01 00 00 00 01 00 00 00 10 00 00 00
|
32
|
+
02 00 00 00 E4 04 00 00
|
33
|
+
).join(' ')
|
34
|
+
|
35
|
+
result = unpack_record( create_summary_property_set(properties))
|
36
|
+
assert_equal(target, result, caption)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_same_as_previous_plus_title
|
40
|
+
properties = [
|
41
|
+
[0x0001, 'VT_I2', 0x04E4 ],
|
42
|
+
[0x0002, 'VT_LPSTR', 'Title'],
|
43
|
+
]
|
44
|
+
caption = " \tDoc properties: _create_property_set('+ Title')"
|
45
|
+
target = %w(
|
46
|
+
FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
|
47
|
+
00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
|
48
|
+
F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
|
49
|
+
30 00 00 00 02 00 00 00 01 00 00 00 18 00 00 00
|
50
|
+
02 00 00 00 20 00 00 00 02 00 00 00 E4 04 00 00
|
51
|
+
1E 00 00 00 06 00 00 00 54 69 74 6C 65 00 00 00
|
52
|
+
).join(' ')
|
53
|
+
|
54
|
+
result = unpack_record( create_summary_property_set(properties))
|
55
|
+
assert_equal(target, result, caption)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_same_as_previous_plus_subject
|
59
|
+
properties = [
|
60
|
+
[0x0001, 'VT_I2', 0x04E4 ],
|
61
|
+
[0x0002, 'VT_LPSTR', 'Title'],
|
62
|
+
[0x0003, 'VT_LPSTR', 'Subject'],
|
63
|
+
]
|
64
|
+
caption = " \tDoc properties: _create_property_set('+ Subject')"
|
65
|
+
target = %w(
|
66
|
+
FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
|
67
|
+
00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
|
68
|
+
F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
|
69
|
+
48 00 00 00 03 00 00 00 01 00 00 00 20 00 00 00
|
70
|
+
02 00 00 00 28 00 00 00 03 00 00 00 38 00 00 00
|
71
|
+
02 00 00 00 E4 04 00 00 1E 00 00 00 06 00 00 00
|
72
|
+
54 69 74 6C 65 00 00 00 1E 00 00 00 08 00 00 00
|
73
|
+
53 75 62 6A 65 63 74 00
|
74
|
+
).join(' ')
|
75
|
+
|
76
|
+
result = unpack_record( create_summary_property_set(properties))
|
77
|
+
assert_equal(target, result, caption)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_same_as_previous_plus_author
|
81
|
+
properties = [
|
82
|
+
[0x0001, 'VT_I2', 0x04E4 ],
|
83
|
+
[0x0002, 'VT_LPSTR', 'Title'],
|
84
|
+
[0x0003, 'VT_LPSTR', 'Subject'],
|
85
|
+
[0x0004, 'VT_LPSTR', 'Author' ],
|
86
|
+
]
|
87
|
+
caption = " \tDoc properties: _create_property_set('+ Keywords')"
|
88
|
+
target = %w(
|
89
|
+
FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
|
90
|
+
00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
|
91
|
+
F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
|
92
|
+
60 00 00 00 04 00 00 00 01 00 00 00 28 00 00 00
|
93
|
+
02 00 00 00 30 00 00 00 03 00 00 00 40 00 00 00
|
94
|
+
04 00 00 00 50 00 00 00 02 00 00 00 E4 04 00 00
|
95
|
+
1E 00 00 00 06 00 00 00 54 69 74 6C 65 00 00 00
|
96
|
+
1E 00 00 00 08 00 00 00 53 75 62 6A 65 63 74 00
|
97
|
+
1E 00 00 00 07 00 00 00 41 75 74 68 6F 72 00 00
|
98
|
+
).join(' ')
|
99
|
+
|
100
|
+
result = unpack_record( create_summary_property_set(properties))
|
101
|
+
assert_equal(target, result, caption)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_same_as_previous_plus_keywords
|
105
|
+
properties = [
|
106
|
+
[0x0001, 'VT_I2', 0x04E4 ],
|
107
|
+
[0x0002, 'VT_LPSTR', 'Title'],
|
108
|
+
[0x0003, 'VT_LPSTR', 'Subject'],
|
109
|
+
[0x0004, 'VT_LPSTR', 'Author' ],
|
110
|
+
[0x0005, 'VT_LPSTR', 'Keywords'],
|
111
|
+
]
|
112
|
+
caption = " \tDoc properties: _create_property_set('+ Keywords')"
|
113
|
+
target = %w(
|
114
|
+
FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
|
115
|
+
00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
|
116
|
+
F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
|
117
|
+
7C 00 00 00 05 00 00 00 01 00 00 00 30 00 00 00
|
118
|
+
02 00 00 00 38 00 00 00 03 00 00 00 48 00 00 00
|
119
|
+
04 00 00 00 58 00 00 00 05 00 00 00 68 00 00 00
|
120
|
+
02 00 00 00 E4 04 00 00 1E 00 00 00 06 00 00 00
|
121
|
+
54 69 74 6C 65 00 00 00 1E 00 00 00 08 00 00 00
|
122
|
+
53 75 62 6A 65 63 74 00 1E 00 00 00 07 00 00 00
|
123
|
+
41 75 74 68 6F 72 00 00 1E 00 00 00 09 00 00 00
|
124
|
+
4B 65 79 77 6F 72 64 73 00 00 00 00
|
125
|
+
).join(' ')
|
126
|
+
|
127
|
+
result = unpack_record( create_summary_property_set(properties))
|
128
|
+
assert_equal(target, result, caption)
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_same_as_previous_plus_comments
|
132
|
+
properties = [
|
133
|
+
[0x0001, 'VT_I2', 0x04E4 ],
|
134
|
+
[0x0002, 'VT_LPSTR', 'Title'],
|
135
|
+
[0x0003, 'VT_LPSTR', 'Subject'],
|
136
|
+
[0x0004, 'VT_LPSTR', 'Author' ],
|
137
|
+
[0x0005, 'VT_LPSTR', 'Keywords'],
|
138
|
+
[0x0006, 'VT_LPSTR', 'Comments'],
|
139
|
+
]
|
140
|
+
caption = " \tDoc properties: _create_property_set('+ Comments')"
|
141
|
+
target = %w(
|
142
|
+
FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
|
143
|
+
00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
|
144
|
+
F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
|
145
|
+
98 00 00 00 06 00 00 00 01 00 00 00 38 00 00 00
|
146
|
+
02 00 00 00 40 00 00 00 03 00 00 00 50 00 00 00
|
147
|
+
04 00 00 00 60 00 00 00 05 00 00 00 70 00 00 00
|
148
|
+
06 00 00 00 84 00 00 00 02 00 00 00 E4 04 00 00
|
149
|
+
1E 00 00 00 06 00 00 00 54 69 74 6C 65 00 00 00
|
150
|
+
1E 00 00 00 08 00 00 00 53 75 62 6A 65 63 74 00
|
151
|
+
1E 00 00 00 07 00 00 00 41 75 74 68 6F 72 00 00
|
152
|
+
1E 00 00 00 09 00 00 00 4B 65 79 77 6F 72 64 73
|
153
|
+
00 00 00 00 1E 00 00 00 09 00 00 00 43 6F 6D 6D
|
154
|
+
65 6E 74 73 00 00 00 00
|
155
|
+
).join(' ')
|
156
|
+
|
157
|
+
result = unpack_record( create_summary_property_set(properties))
|
158
|
+
assert_equal(target, result, caption)
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_same_as_previous_plus_last_author
|
162
|
+
properties = [
|
163
|
+
[0x0001, 'VT_I2', 0x04E4 ],
|
164
|
+
[0x0002, 'VT_LPSTR', 'Title'],
|
165
|
+
[0x0003, 'VT_LPSTR', 'Subject'],
|
166
|
+
[0x0004, 'VT_LPSTR', 'Author' ],
|
167
|
+
[0x0005, 'VT_LPSTR', 'Keywords'],
|
168
|
+
[0x0006, 'VT_LPSTR', 'Comments'],
|
169
|
+
[0x0008, 'VT_LPSTR', 'Username'],
|
170
|
+
]
|
171
|
+
caption = " \tDoc properties: _create_property_set('+ Comments')"
|
172
|
+
target = %w(
|
173
|
+
FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
|
174
|
+
00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
|
175
|
+
F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
|
176
|
+
B4 00 00 00 07 00 00 00 01 00 00 00 40 00 00 00
|
177
|
+
02 00 00 00 48 00 00 00 03 00 00 00 58 00 00 00
|
178
|
+
04 00 00 00 68 00 00 00 05 00 00 00 78 00 00 00
|
179
|
+
06 00 00 00 8C 00 00 00 08 00 00 00 A0 00 00 00
|
180
|
+
02 00 00 00 E4 04 00 00 1E 00 00 00 06 00 00 00
|
181
|
+
54 69 74 6C 65 00 00 00 1E 00 00 00 08 00 00 00
|
182
|
+
53 75 62 6A 65 63 74 00 1E 00 00 00 07 00 00 00
|
183
|
+
41 75 74 68 6F 72 00 00 1E 00 00 00 09 00 00 00
|
184
|
+
4B 65 79 77 6F 72 64 73 00 00 00 00 1E 00 00 00
|
185
|
+
09 00 00 00 43 6F 6D 6D 65 6E 74 73 00 00 00 00
|
186
|
+
1E 00 00 00 09 00 00 00 55 73 65 72 6E 61 6D 65
|
187
|
+
00 00 00 00
|
188
|
+
).join(' ')
|
189
|
+
|
190
|
+
result = unpack_record( create_summary_property_set(properties))
|
191
|
+
assert_equal(target, result, caption)
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_same_as_previous_plus_creation_date
|
195
|
+
filetime = Time.gm(2008,8,19,23,20,13)
|
196
|
+
properties = [
|
197
|
+
[0x0001, 'VT_I2', 0x04E4 ],
|
198
|
+
[0x0002, 'VT_LPSTR', 'Title'],
|
199
|
+
[0x0003, 'VT_LPSTR', 'Subject'],
|
200
|
+
[0x0004, 'VT_LPSTR', 'Author' ],
|
201
|
+
[0x0005, 'VT_LPSTR', 'Keywords'],
|
202
|
+
[0x0006, 'VT_LPSTR', 'Comments'],
|
203
|
+
[0x0008, 'VT_LPSTR', 'Username'],
|
204
|
+
[0x000C, 'VT_FILETIME', filetime ],
|
205
|
+
]
|
206
|
+
caption = " \tDoc properties: _create_property_set('+ Comments')"
|
207
|
+
target = %w(
|
208
|
+
FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
|
209
|
+
00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
|
210
|
+
F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
|
211
|
+
C8 00 00 00 08 00 00 00 01 00 00 00 48 00 00 00
|
212
|
+
02 00 00 00 50 00 00 00 03 00 00 00 60 00 00 00
|
213
|
+
04 00 00 00 70 00 00 00 05 00 00 00 80 00 00 00
|
214
|
+
06 00 00 00 94 00 00 00 08 00 00 00 A8 00 00 00
|
215
|
+
0C 00 00 00 BC 00 00 00 02 00 00 00 E4 04 00 00
|
216
|
+
1E 00 00 00 06 00 00 00 54 69 74 6C 65 00 00 00
|
217
|
+
1E 00 00 00 08 00 00 00 53 75 62 6A 65 63 74 00
|
218
|
+
1E 00 00 00 07 00 00 00 41 75 74 68 6F 72 00 00
|
219
|
+
1E 00 00 00 09 00 00 00 4B 65 79 77 6F 72 64 73
|
220
|
+
00 00 00 00 1E 00 00 00 09 00 00 00 43 6F 6D 6D
|
221
|
+
65 6E 74 73 00 00 00 00 1E 00 00 00 09 00 00 00
|
222
|
+
55 73 65 72 6E 61 6D 65 00 00 00 00 40 00 00 00
|
223
|
+
80 74 89 21 52 02 C9 01
|
224
|
+
).join(' ')
|
225
|
+
|
226
|
+
result = unpack_record( create_summary_property_set(properties))
|
227
|
+
assert_equal(target, result, caption)
|
228
|
+
end
|
229
|
+
|
230
|
+
###############################################################################
|
231
|
+
#
|
232
|
+
# Unpack the binary data into a format suitable for printing in tests.
|
233
|
+
#
|
234
|
+
def unpack_record(data)
|
235
|
+
data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
|
236
|
+
end
|
237
|
+
|
238
|
+
end
|
@@ -0,0 +1,430 @@
|
|
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 setup
|
21
|
+
t = Time.now.strftime("%Y%m%d")
|
22
|
+
path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
23
|
+
@test_file = File.join(Dir.tmpdir, path)
|
24
|
+
end
|
25
|
+
|
26
|
+
def teardown
|
27
|
+
File.unlink(@test_file) if FileTest.exist?(@test_file)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_same_as_previous_plus_creation_date
|
31
|
+
smiley = '☺' # chr 0x263A; in perl
|
32
|
+
|
33
|
+
workbook = Spreadsheet::WriteExcel.new(@test_file)
|
34
|
+
worksheet = workbook.add_worksheet
|
35
|
+
|
36
|
+
###############################################################################
|
37
|
+
#
|
38
|
+
# Test 1. _get_property_set_codepage() for default latin1 strings.
|
39
|
+
#
|
40
|
+
params ={
|
41
|
+
:title => 'Title',
|
42
|
+
:subject => 'Subject',
|
43
|
+
:author => 'Author',
|
44
|
+
:keywords => 'Keywords',
|
45
|
+
:comments => 'Comments',
|
46
|
+
:last_author => 'Username',
|
47
|
+
}
|
48
|
+
|
49
|
+
strings = %w(title subject author keywords comments last_author)
|
50
|
+
|
51
|
+
caption = " \t_get_property_set_codepage('latin1')"
|
52
|
+
target = 0x04E4
|
53
|
+
|
54
|
+
result = workbook.get_property_set_codepage(params, strings)
|
55
|
+
assert_equal(target, result, caption)
|
56
|
+
|
57
|
+
###############################################################################
|
58
|
+
#
|
59
|
+
# Test 2. _get_property_set_codepage() for manual utf8 strings.
|
60
|
+
#
|
61
|
+
|
62
|
+
params = {
|
63
|
+
:title => 'Title',
|
64
|
+
:subject => 'Subject',
|
65
|
+
:author => 'Author',
|
66
|
+
:keywords => 'Keywords',
|
67
|
+
:comments => 'Comments',
|
68
|
+
:last_author => 'Username',
|
69
|
+
:utf8 => 1,
|
70
|
+
}
|
71
|
+
|
72
|
+
strings = %w(title subject author keywords comments last_author)
|
73
|
+
|
74
|
+
caption = " \t_get_property_set_codepage('utf8')"
|
75
|
+
target = 0xFDE9
|
76
|
+
|
77
|
+
result = workbook.get_property_set_codepage(params, strings)
|
78
|
+
assert_equal(target, result, caption)
|
79
|
+
|
80
|
+
###############################################################################
|
81
|
+
#
|
82
|
+
# Test 3. _get_property_set_codepage() for perl 5.8 utf8 strings.
|
83
|
+
#
|
84
|
+
params = {
|
85
|
+
:title => 'Title' + smiley,
|
86
|
+
:subject => 'Subject',
|
87
|
+
:author => 'Author',
|
88
|
+
:keywords => 'Keywords',
|
89
|
+
:comments => 'Comments',
|
90
|
+
:last_author => 'Username',
|
91
|
+
}
|
92
|
+
|
93
|
+
strings = %w(title subject author keywords comments last_author)
|
94
|
+
|
95
|
+
caption = " \t_get_property_set_codepage('utf8')";
|
96
|
+
target = 0xFDE9;
|
97
|
+
|
98
|
+
result = workbook.get_property_set_codepage(params, strings)
|
99
|
+
assert_equal(target, result, caption)
|
100
|
+
|
101
|
+
###############################################################################
|
102
|
+
#
|
103
|
+
# Note, the "created => nil" parameters in some of the following tests is
|
104
|
+
# used to avoid adding the default date to the property sets.
|
105
|
+
|
106
|
+
|
107
|
+
###############################################################################
|
108
|
+
#
|
109
|
+
# Test 4. Codepage only.
|
110
|
+
#
|
111
|
+
|
112
|
+
workbook.set_properties(
|
113
|
+
:created => nil
|
114
|
+
)
|
115
|
+
|
116
|
+
caption = " \tset_properties(codepage)"
|
117
|
+
target = %w(
|
118
|
+
FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
|
119
|
+
00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
|
120
|
+
F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
|
121
|
+
18 00 00 00 01 00 00 00 01 00 00 00 10 00 00 00
|
122
|
+
02 00 00 00 E4 04 00 00
|
123
|
+
).join(' ')
|
124
|
+
|
125
|
+
result = unpack_record( workbook.summary )
|
126
|
+
assert_equal(target, result, caption)
|
127
|
+
|
128
|
+
###############################################################################
|
129
|
+
#
|
130
|
+
# Test 5. Same as previous + Title.
|
131
|
+
#
|
132
|
+
|
133
|
+
workbook.set_properties(
|
134
|
+
:title => 'Title',
|
135
|
+
:created => nil
|
136
|
+
)
|
137
|
+
|
138
|
+
caption = " \tset_properties('Title')"
|
139
|
+
target = %w(
|
140
|
+
FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
|
141
|
+
00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
|
142
|
+
F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
|
143
|
+
30 00 00 00 02 00 00 00 01 00 00 00 18 00 00 00
|
144
|
+
02 00 00 00 20 00 00 00 02 00 00 00 E4 04 00 00
|
145
|
+
1E 00 00 00 06 00 00 00 54 69 74 6C 65 00 00 00
|
146
|
+
).join(' ')
|
147
|
+
|
148
|
+
result = unpack_record( workbook.summary )
|
149
|
+
assert_equal(target, result, caption)
|
150
|
+
|
151
|
+
###############################################################################
|
152
|
+
#
|
153
|
+
# Test 6. Same as previous + Subject.
|
154
|
+
#
|
155
|
+
|
156
|
+
workbook.set_properties(
|
157
|
+
:title => 'Title',
|
158
|
+
:subject => 'Subject',
|
159
|
+
:created => nil
|
160
|
+
)
|
161
|
+
|
162
|
+
caption = " \tset_properties('+ Subject')"
|
163
|
+
target = %w(
|
164
|
+
FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
|
165
|
+
00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
|
166
|
+
F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
|
167
|
+
48 00 00 00 03 00 00 00 01 00 00 00 20 00 00 00
|
168
|
+
02 00 00 00 28 00 00 00 03 00 00 00 38 00 00 00
|
169
|
+
02 00 00 00 E4 04 00 00 1E 00 00 00 06 00 00 00
|
170
|
+
54 69 74 6C 65 00 00 00 1E 00 00 00 08 00 00 00
|
171
|
+
53 75 62 6A 65 63 74 00
|
172
|
+
).join(' ')
|
173
|
+
|
174
|
+
result = unpack_record( workbook.summary )
|
175
|
+
assert_equal(target, result, caption)
|
176
|
+
|
177
|
+
###############################################################################
|
178
|
+
#
|
179
|
+
# Test 7. Same as previous + Author.
|
180
|
+
#
|
181
|
+
|
182
|
+
workbook.set_properties(
|
183
|
+
:title => 'Title',
|
184
|
+
:subject => 'Subject',
|
185
|
+
:author => 'Author',
|
186
|
+
:created => nil
|
187
|
+
)
|
188
|
+
|
189
|
+
caption = " \tset_properties('+ Author')"
|
190
|
+
target = %w(
|
191
|
+
FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
|
192
|
+
00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
|
193
|
+
F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
|
194
|
+
60 00 00 00 04 00 00 00 01 00 00 00 28 00 00 00
|
195
|
+
02 00 00 00 30 00 00 00 03 00 00 00 40 00 00 00
|
196
|
+
04 00 00 00 50 00 00 00 02 00 00 00 E4 04 00 00
|
197
|
+
1E 00 00 00 06 00 00 00 54 69 74 6C 65 00 00 00
|
198
|
+
1E 00 00 00 08 00 00 00 53 75 62 6A 65 63 74 00
|
199
|
+
1E 00 00 00 07 00 00 00 41 75 74 68 6F 72 00 00
|
200
|
+
).join(' ')
|
201
|
+
|
202
|
+
result = unpack_record( workbook.summary )
|
203
|
+
assert_equal(target, result, caption)
|
204
|
+
|
205
|
+
###############################################################################
|
206
|
+
#
|
207
|
+
# Test 8. Same as previous + Keywords.
|
208
|
+
#
|
209
|
+
|
210
|
+
workbook.set_properties(
|
211
|
+
:title => 'Title',
|
212
|
+
:subject => 'Subject',
|
213
|
+
:author => 'Author',
|
214
|
+
:keywords => 'Keywords',
|
215
|
+
:created => nil
|
216
|
+
)
|
217
|
+
|
218
|
+
caption = " \tset_properties('+ Keywords')"
|
219
|
+
target = %w(
|
220
|
+
FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
|
221
|
+
00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
|
222
|
+
F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
|
223
|
+
7C 00 00 00 05 00 00 00 01 00 00 00 30 00 00 00
|
224
|
+
02 00 00 00 38 00 00 00 03 00 00 00 48 00 00 00
|
225
|
+
04 00 00 00 58 00 00 00 05 00 00 00 68 00 00 00
|
226
|
+
02 00 00 00 E4 04 00 00 1E 00 00 00 06 00 00 00
|
227
|
+
54 69 74 6C 65 00 00 00 1E 00 00 00 08 00 00 00
|
228
|
+
53 75 62 6A 65 63 74 00 1E 00 00 00 07 00 00 00
|
229
|
+
41 75 74 68 6F 72 00 00 1E 00 00 00 09 00 00 00
|
230
|
+
4B 65 79 77 6F 72 64 73 00 00 00 00
|
231
|
+
).join(' ')
|
232
|
+
|
233
|
+
result = unpack_record( workbook.summary )
|
234
|
+
assert_equal(target, result, caption)
|
235
|
+
|
236
|
+
###############################################################################
|
237
|
+
#
|
238
|
+
# Test 9. Same as previous + Comments.
|
239
|
+
#
|
240
|
+
|
241
|
+
workbook.set_properties(
|
242
|
+
:title => 'Title',
|
243
|
+
:subject => 'Subject',
|
244
|
+
:author => 'Author',
|
245
|
+
:keywords => 'Keywords',
|
246
|
+
:comments => 'Comments',
|
247
|
+
:created => nil
|
248
|
+
)
|
249
|
+
|
250
|
+
caption = " \tset_properties('+ Comments')"
|
251
|
+
target = %w(
|
252
|
+
FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
|
253
|
+
00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
|
254
|
+
F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
|
255
|
+
98 00 00 00 06 00 00 00 01 00 00 00 38 00 00 00
|
256
|
+
02 00 00 00 40 00 00 00 03 00 00 00 50 00 00 00
|
257
|
+
04 00 00 00 60 00 00 00 05 00 00 00 70 00 00 00
|
258
|
+
06 00 00 00 84 00 00 00 02 00 00 00 E4 04 00 00
|
259
|
+
1E 00 00 00 06 00 00 00 54 69 74 6C 65 00 00 00
|
260
|
+
1E 00 00 00 08 00 00 00 53 75 62 6A 65 63 74 00
|
261
|
+
1E 00 00 00 07 00 00 00 41 75 74 68 6F 72 00 00
|
262
|
+
1E 00 00 00 09 00 00 00 4B 65 79 77 6F 72 64 73
|
263
|
+
00 00 00 00 1E 00 00 00 09 00 00 00 43 6F 6D 6D
|
264
|
+
65 6E 74 73 00 00 00 00
|
265
|
+
).join(' ')
|
266
|
+
|
267
|
+
result = unpack_record( workbook.summary )
|
268
|
+
assert_equal(target, result, caption)
|
269
|
+
|
270
|
+
###############################################################################
|
271
|
+
#
|
272
|
+
# Test 10. Same as previous + Last author.
|
273
|
+
#
|
274
|
+
|
275
|
+
workbook.set_properties(
|
276
|
+
:title => 'Title',
|
277
|
+
:subject => 'Subject',
|
278
|
+
:author => 'Author',
|
279
|
+
:keywords => 'Keywords',
|
280
|
+
:comments => 'Comments',
|
281
|
+
:last_author => 'Username',
|
282
|
+
:created => nil
|
283
|
+
)
|
284
|
+
|
285
|
+
caption = " \tset_properties('+ Last author')"
|
286
|
+
target = %w(
|
287
|
+
FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
|
288
|
+
00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
|
289
|
+
F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
|
290
|
+
B4 00 00 00 07 00 00 00 01 00 00 00 40 00 00 00
|
291
|
+
02 00 00 00 48 00 00 00 03 00 00 00 58 00 00 00
|
292
|
+
04 00 00 00 68 00 00 00 05 00 00 00 78 00 00 00
|
293
|
+
06 00 00 00 8C 00 00 00 08 00 00 00 A0 00 00 00
|
294
|
+
02 00 00 00 E4 04 00 00 1E 00 00 00 06 00 00 00
|
295
|
+
54 69 74 6C 65 00 00 00 1E 00 00 00 08 00 00 00
|
296
|
+
53 75 62 6A 65 63 74 00 1E 00 00 00 07 00 00 00
|
297
|
+
41 75 74 68 6F 72 00 00 1E 00 00 00 09 00 00 00
|
298
|
+
4B 65 79 77 6F 72 64 73 00 00 00 00 1E 00 00 00
|
299
|
+
09 00 00 00 43 6F 6D 6D 65 6E 74 73 00 00 00 00
|
300
|
+
1E 00 00 00 09 00 00 00 55 73 65 72 6E 61 6D 65
|
301
|
+
00 00 00 00
|
302
|
+
).join(' ')
|
303
|
+
|
304
|
+
result = unpack_record( workbook.summary )
|
305
|
+
assert_equal(target, result, caption)
|
306
|
+
|
307
|
+
###############################################################################
|
308
|
+
#
|
309
|
+
# Test 11. Same as previous + Creation date.
|
310
|
+
#
|
311
|
+
|
312
|
+
# Aug 19 23:20:13 2008
|
313
|
+
# $sec,$min,$hour,$mday,$mon,$year
|
314
|
+
# We normalise the time using timegm() so that the tests don't fail due to
|
315
|
+
# different timezones.
|
316
|
+
|
317
|
+
filetime = Time.gm(2008,8,19,23,20,13)
|
318
|
+
workbook.set_properties(
|
319
|
+
:title => 'Title',
|
320
|
+
:subject => 'Subject',
|
321
|
+
:author => 'Author',
|
322
|
+
:keywords => 'Keywords',
|
323
|
+
:comments => 'Comments',
|
324
|
+
:last_author => 'Username',
|
325
|
+
:created => filetime
|
326
|
+
)
|
327
|
+
|
328
|
+
caption = " \tset_properties('+ Creation date')"
|
329
|
+
target = %w(
|
330
|
+
FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
|
331
|
+
00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
|
332
|
+
F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
|
333
|
+
C8 00 00 00 08 00 00 00 01 00 00 00 48 00 00 00
|
334
|
+
02 00 00 00 50 00 00 00 03 00 00 00 60 00 00 00
|
335
|
+
04 00 00 00 70 00 00 00 05 00 00 00 80 00 00 00
|
336
|
+
06 00 00 00 94 00 00 00 08 00 00 00 A8 00 00 00
|
337
|
+
0C 00 00 00 BC 00 00 00 02 00 00 00 E4 04 00 00
|
338
|
+
1E 00 00 00 06 00 00 00 54 69 74 6C 65 00 00 00
|
339
|
+
1E 00 00 00 08 00 00 00 53 75 62 6A 65 63 74 00
|
340
|
+
1E 00 00 00 07 00 00 00 41 75 74 68 6F 72 00 00
|
341
|
+
1E 00 00 00 09 00 00 00 4B 65 79 77 6F 72 64 73
|
342
|
+
00 00 00 00 1E 00 00 00 09 00 00 00 43 6F 6D 6D
|
343
|
+
65 6E 74 73 00 00 00 00 1E 00 00 00 09 00 00 00
|
344
|
+
55 73 65 72 6E 61 6D 65 00 00 00 00 40 00 00 00
|
345
|
+
80 74 89 21 52 02 C9 01
|
346
|
+
).join(' ')
|
347
|
+
|
348
|
+
result = unpack_record( workbook.summary )
|
349
|
+
assert_equal(target, result, caption)
|
350
|
+
|
351
|
+
###############################################################################
|
352
|
+
#
|
353
|
+
# Test 12. Same as previous. Date set at the workbook level.
|
354
|
+
#
|
355
|
+
|
356
|
+
# Wed Aug 20 00:20:13 2008
|
357
|
+
# $sec,$min,$hour,$mday,$mon,$year
|
358
|
+
# We normalise the time using timegm() so that the tests don't fail due to
|
359
|
+
# different timezones.
|
360
|
+
workbook.localtime = Time.gm(2008,8,19,23,20,13)
|
361
|
+
|
362
|
+
workbook.set_properties(
|
363
|
+
:title => 'Title',
|
364
|
+
:subject => 'Subject',
|
365
|
+
:author => 'Author',
|
366
|
+
:keywords => 'Keywords',
|
367
|
+
:comments => 'Comments',
|
368
|
+
:last_author => 'Username'
|
369
|
+
)
|
370
|
+
|
371
|
+
caption = " \tset_properties('+ Creation date')"
|
372
|
+
target = %w(
|
373
|
+
FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
|
374
|
+
00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
|
375
|
+
F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
|
376
|
+
C8 00 00 00 08 00 00 00 01 00 00 00 48 00 00 00
|
377
|
+
02 00 00 00 50 00 00 00 03 00 00 00 60 00 00 00
|
378
|
+
04 00 00 00 70 00 00 00 05 00 00 00 80 00 00 00
|
379
|
+
06 00 00 00 94 00 00 00 08 00 00 00 A8 00 00 00
|
380
|
+
0C 00 00 00 BC 00 00 00 02 00 00 00 E4 04 00 00
|
381
|
+
1E 00 00 00 06 00 00 00 54 69 74 6C 65 00 00 00
|
382
|
+
1E 00 00 00 08 00 00 00 53 75 62 6A 65 63 74 00
|
383
|
+
1E 00 00 00 07 00 00 00 41 75 74 68 6F 72 00 00
|
384
|
+
1E 00 00 00 09 00 00 00 4B 65 79 77 6F 72 64 73
|
385
|
+
00 00 00 00 1E 00 00 00 09 00 00 00 43 6F 6D 6D
|
386
|
+
65 6E 74 73 00 00 00 00 1E 00 00 00 09 00 00 00
|
387
|
+
55 73 65 72 6E 61 6D 65 00 00 00 00 40 00 00 00
|
388
|
+
80 74 89 21 52 02 C9 01
|
389
|
+
).join(' ')
|
390
|
+
|
391
|
+
result = unpack_record( workbook.summary )
|
392
|
+
assert_equal(target, result, caption)
|
393
|
+
|
394
|
+
###############################################################################
|
395
|
+
#
|
396
|
+
# Test 14. UTF-8 string used.
|
397
|
+
#
|
398
|
+
|
399
|
+
workbook.set_properties(
|
400
|
+
:title => 'Title' + smiley,
|
401
|
+
:created => nil
|
402
|
+
)
|
403
|
+
|
404
|
+
caption = " \tset_properties(utf8)"
|
405
|
+
target = %w(
|
406
|
+
FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
|
407
|
+
00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
|
408
|
+
F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
|
409
|
+
34 00 00 00 02 00 00 00 01 00 00 00 18 00 00 00
|
410
|
+
02 00 00 00 20 00 00 00 02 00 00 00 E9 FD 00 00
|
411
|
+
1E 00 00 00 09 00 00 00 54 69 74 6C 65 E2 98 BA
|
412
|
+
00 00 00 00
|
413
|
+
).join(' ')
|
414
|
+
|
415
|
+
result = unpack_record( workbook.summary )
|
416
|
+
assert_equal(target, result, caption)
|
417
|
+
|
418
|
+
workbook.close
|
419
|
+
|
420
|
+
end
|
421
|
+
|
422
|
+
###############################################################################
|
423
|
+
#
|
424
|
+
# Unpack the binary data into a format suitable for printing in tests.
|
425
|
+
#
|
426
|
+
def unpack_record(data)
|
427
|
+
data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
|
428
|
+
end
|
429
|
+
|
430
|
+
end
|