writeexcel 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +26 -31
- data/examples/a_simple.rb +42 -42
- data/examples/{autofilters.rb → autofilter.rb} +264 -266
- data/examples/bigfile.rb +29 -0
- data/examples/chart_area.rb +120 -0
- data/examples/chart_bar.rb +119 -0
- data/examples/chart_column.rb +119 -0
- data/examples/chart_line.rb +119 -0
- data/examples/chart_pie.rb +107 -0
- data/examples/chart_scatter.rb +120 -0
- data/examples/chart_stock.rb +147 -0
- data/examples/copyformat.rb +51 -51
- data/examples/data_validate.rb +278 -278
- data/examples/date_time.rb +86 -86
- data/examples/defined_name.rb +31 -0
- data/examples/demo.rb +120 -118
- data/examples/diag_border.rb +35 -35
- data/examples/formats.rb +489 -489
- data/examples/header.rb +136 -136
- data/examples/hidden.rb +28 -28
- data/examples/hyperlink.rb +42 -42
- data/examples/images.rb +52 -52
- data/examples/merge1.rb +39 -39
- data/examples/merge2.rb +44 -44
- data/examples/merge3.rb +65 -65
- data/examples/merge4.rb +82 -82
- data/examples/merge5.rb +79 -79
- data/examples/properties.rb +33 -0
- data/examples/properties_jp.rb +32 -0
- data/examples/protection.rb +46 -46
- data/examples/regions.rb +52 -52
- data/examples/repeat.rb +42 -42
- data/examples/stats.rb +75 -75
- data/examples/stocks.rb +80 -80
- data/examples/tab_colors.rb +30 -30
- data/examples/write_arrays.rb +82 -0
- data/lib/writeexcel.rb +1134 -18
- data/lib/writeexcel/biffwriter.rb +273 -260
- data/lib/writeexcel/chart.rb +2306 -217
- data/lib/writeexcel/charts/area.rb +152 -0
- data/lib/writeexcel/charts/bar.rb +177 -0
- data/lib/writeexcel/charts/column.rb +156 -0
- data/lib/writeexcel/charts/external.rb +61 -0
- data/lib/writeexcel/charts/line.rb +152 -0
- data/lib/writeexcel/charts/pie.rb +169 -0
- data/lib/writeexcel/charts/scatter.rb +192 -0
- data/lib/writeexcel/charts/stock.rb +211 -0
- data/lib/writeexcel/excelformulaparser.rb +208 -195
- data/lib/writeexcel/format.rb +1697 -1108
- data/lib/writeexcel/formula.rb +1050 -986
- data/lib/writeexcel/olewriter.rb +322 -322
- data/lib/writeexcel/properties.rb +251 -250
- data/lib/writeexcel/storage_lite.rb +968 -0
- data/lib/writeexcel/workbook.rb +3294 -2630
- data/lib/writeexcel/worksheet.rb +9012 -6377
- data/test/excelfile/Chart1.xls +0 -0
- data/test/excelfile/Chart2.xls +0 -0
- data/test/excelfile/Chart3.xls +0 -0
- data/test/excelfile/Chart4.xls +0 -0
- data/test/excelfile/Chart5.xls +0 -0
- data/test/perl_output/Chart1.xls.data +0 -0
- data/test/perl_output/Chart2.xls.data +0 -0
- data/test/perl_output/Chart3.xls.data +0 -0
- data/test/perl_output/Chart4.xls.data +0 -0
- data/test/perl_output/Chart5.xls.data +0 -0
- data/test/perl_output/a_simple.xls +0 -0
- data/test/perl_output/autofilter.xls +0 -0
- data/test/perl_output/chart_area.xls +0 -0
- data/test/perl_output/chart_bar.xls +0 -0
- data/test/perl_output/chart_column.xls +0 -0
- data/test/perl_output/chart_line.xls +0 -0
- data/test/perl_output/data_validate.xls +0 -0
- data/test/perl_output/date_time.xls +0 -0
- data/test/perl_output/demo.xls +0 -0
- data/test/perl_output/demo101.bin +0 -0
- data/test/perl_output/demo201.bin +0 -0
- data/test/perl_output/demo301.bin +0 -0
- data/test/perl_output/demo401.bin +0 -0
- data/test/perl_output/demo501.bin +0 -0
- data/test/perl_output/diag_border.xls +0 -0
- data/test/perl_output/headers.xls +0 -0
- data/test/perl_output/hyperlink.xls +0 -0
- data/test/perl_output/images.xls +0 -0
- data/test/perl_output/merge1.xls +0 -0
- data/test/perl_output/merge2.xls +0 -0
- data/test/perl_output/merge3.xls +0 -0
- data/test/perl_output/merge4.xls +0 -0
- data/test/perl_output/merge5.xls +0 -0
- data/test/perl_output/protection.xls +0 -0
- data/test/perl_output/regions.xls +0 -0
- data/test/perl_output/stats.xls +0 -0
- data/test/perl_output/stocks.xls +0 -0
- data/test/perl_output/tab_colors.xls +0 -0
- data/test/perl_output/unicode_cyrillic.xls +0 -0
- data/test/perl_output/workbook1.xls +0 -0
- data/test/perl_output/workbook2.xls +0 -0
- data/test/tc_all.rb +32 -31
- data/test/tc_biff.rb +104 -104
- data/test/tc_chart.rb +22 -22
- data/test/tc_example_match.rb +1944 -1280
- data/test/tc_format.rb +1254 -1267
- data/test/tc_formula.rb +63 -63
- data/test/tc_ole.rb +110 -110
- data/test/tc_storage_lite.rb +149 -0
- data/test/tc_workbook.rb +140 -115
- data/test/tc_worksheet.rb +115 -115
- data/test/test_00_IEEE_double.rb +14 -14
- data/test/test_01_add_worksheet.rb +12 -12
- data/test/test_02_merge_formats.rb +58 -58
- data/test/test_04_dimensions.rb +397 -397
- data/test/test_05_rows.rb +182 -182
- data/test/test_06_extsst.rb +80 -80
- data/test/test_11_date_time.rb +484 -484
- data/test/test_12_date_only.rb +506 -506
- data/test/test_13_date_seconds.rb +486 -486
- data/test/test_21_escher.rb +642 -629
- data/test/test_22_mso_drawing_group.rb +750 -739
- data/test/test_23_note.rb +78 -78
- data/test/test_24_txo.rb +80 -80
- data/test/test_25_position_object.rb +82 -0
- data/test/test_26_autofilter.rb +327 -327
- data/test/test_27_autofilter.rb +144 -144
- data/test/test_28_autofilter.rb +174 -174
- data/test/test_29_process_jpg.rb +681 -131
- data/test/test_30_validation_dval.rb +82 -82
- data/test/test_31_validation_dv_strings.rb +131 -131
- data/test/test_32_validation_dv_formula.rb +211 -211
- data/test/test_40_property_types.rb +191 -191
- data/test/test_41_properties.rb +238 -238
- data/test/test_42_set_properties.rb +442 -419
- data/test/test_50_name_stored.rb +305 -0
- data/test/test_51_name_print_area.rb +363 -0
- data/test/test_52_name_print_titles.rb +460 -0
- data/test/test_53_autofilter.rb +209 -0
- data/test/test_60_chart_generic.rb +576 -0
- data/test/test_61_chart_subclasses.rb +97 -0
- data/test/test_62_chart_formats.rb +270 -0
- data/test/test_63_chart_area_formats.rb +647 -0
- data/test/test_chartex.rb +35 -0
- data/test/ts_all.rb +46 -34
- data/writeexcel.gemspec +18 -0
- data/writeexcel.rdoc +583 -0
- metadata +162 -108
@@ -1,82 +1,82 @@
|
|
1
|
-
##########################################################################
|
2
|
-
# test_30_validation_dval.rb
|
3
|
-
#
|
4
|
-
# Tests for the Excel DVAL structure used in data validation.
|
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 'writeexcel'
|
16
|
-
|
17
|
-
class TC_validation_dval < Test::Unit::TestCase
|
18
|
-
|
19
|
-
def setup
|
20
|
-
t = Time.now.strftime("%Y%m%d")
|
21
|
-
path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
22
|
-
@test_file = File.join(Dir.tmpdir, path)
|
23
|
-
@workbook =
|
24
|
-
@worksheet = @workbook.add_worksheet
|
25
|
-
end
|
26
|
-
|
27
|
-
def teardown
|
28
|
-
@workbook.close
|
29
|
-
File.unlink(@test_file) if FileTest.exist?(@test_file)
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_1
|
33
|
-
obj_id = 1
|
34
|
-
dv_count = 1
|
35
|
-
|
36
|
-
caption = " \tData validation: _store_dval(#{obj_id}, #{dv_count})"
|
37
|
-
target = %w(
|
38
|
-
B2 01 12 00 04 00 00 00 00 00 00 00 00 00 01 00
|
39
|
-
00 00 01 00 00 00
|
40
|
-
).join(' ')
|
41
|
-
|
42
|
-
result = unpack_record(@worksheet.store_dval(obj_id, dv_count))
|
43
|
-
assert_equal(target, result, caption)
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_2
|
47
|
-
obj_id = -1
|
48
|
-
dv_count = 1
|
49
|
-
|
50
|
-
caption = " \tData validation: _store_dval(#{obj_id}, #{dv_count})"
|
51
|
-
target = %w(
|
52
|
-
B2 01 12 00 04 00 00 00 00 00 00 00 00 00 FF FF
|
53
|
-
FF FF 01 00 00 00
|
54
|
-
).join(' ')
|
55
|
-
|
56
|
-
result = unpack_record(@worksheet.store_dval(obj_id, dv_count))
|
57
|
-
assert_equal(target, result, caption)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_3
|
61
|
-
obj_id = 1
|
62
|
-
dv_count = 2
|
63
|
-
|
64
|
-
caption = " \tData validation: _store_dval(#{obj_id}, #{dv_count})"
|
65
|
-
target = %w(
|
66
|
-
B2 01 12 00 04 00 00 00 00 00 00 00 00 00 01 00
|
67
|
-
00 00 02 00 00 00
|
68
|
-
).join(' ')
|
69
|
-
|
70
|
-
result = unpack_record(@worksheet.store_dval(obj_id, dv_count))
|
71
|
-
assert_equal(target, result, caption)
|
72
|
-
end
|
73
|
-
|
74
|
-
###############################################################################
|
75
|
-
#
|
76
|
-
# Unpack the binary data into a format suitable for printing in tests.
|
77
|
-
#
|
78
|
-
def unpack_record(data)
|
79
|
-
data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
1
|
+
##########################################################################
|
2
|
+
# test_30_validation_dval.rb
|
3
|
+
#
|
4
|
+
# Tests for the Excel DVAL structure used in data validation.
|
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 'writeexcel'
|
16
|
+
|
17
|
+
class TC_validation_dval < Test::Unit::TestCase
|
18
|
+
|
19
|
+
def setup
|
20
|
+
t = Time.now.strftime("%Y%m%d")
|
21
|
+
path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
22
|
+
@test_file = File.join(Dir.tmpdir, path)
|
23
|
+
@workbook = WriteExcel.new(@test_file)
|
24
|
+
@worksheet = @workbook.add_worksheet
|
25
|
+
end
|
26
|
+
|
27
|
+
def teardown
|
28
|
+
@workbook.close
|
29
|
+
File.unlink(@test_file) if FileTest.exist?(@test_file)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_1
|
33
|
+
obj_id = 1
|
34
|
+
dv_count = 1
|
35
|
+
|
36
|
+
caption = " \tData validation: _store_dval(#{obj_id}, #{dv_count})"
|
37
|
+
target = %w(
|
38
|
+
B2 01 12 00 04 00 00 00 00 00 00 00 00 00 01 00
|
39
|
+
00 00 01 00 00 00
|
40
|
+
).join(' ')
|
41
|
+
|
42
|
+
result = unpack_record(@worksheet.store_dval(obj_id, dv_count))
|
43
|
+
assert_equal(target, result, caption)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_2
|
47
|
+
obj_id = -1
|
48
|
+
dv_count = 1
|
49
|
+
|
50
|
+
caption = " \tData validation: _store_dval(#{obj_id}, #{dv_count})"
|
51
|
+
target = %w(
|
52
|
+
B2 01 12 00 04 00 00 00 00 00 00 00 00 00 FF FF
|
53
|
+
FF FF 01 00 00 00
|
54
|
+
).join(' ')
|
55
|
+
|
56
|
+
result = unpack_record(@worksheet.store_dval(obj_id, dv_count))
|
57
|
+
assert_equal(target, result, caption)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_3
|
61
|
+
obj_id = 1
|
62
|
+
dv_count = 2
|
63
|
+
|
64
|
+
caption = " \tData validation: _store_dval(#{obj_id}, #{dv_count})"
|
65
|
+
target = %w(
|
66
|
+
B2 01 12 00 04 00 00 00 00 00 00 00 00 00 01 00
|
67
|
+
00 00 02 00 00 00
|
68
|
+
).join(' ')
|
69
|
+
|
70
|
+
result = unpack_record(@worksheet.store_dval(obj_id, dv_count))
|
71
|
+
assert_equal(target, result, caption)
|
72
|
+
end
|
73
|
+
|
74
|
+
###############################################################################
|
75
|
+
#
|
76
|
+
# Unpack the binary data into a format suitable for printing in tests.
|
77
|
+
#
|
78
|
+
def unpack_record(data)
|
79
|
+
data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -1,131 +1,131 @@
|
|
1
|
-
##########################################################################
|
2
|
-
# test_31_validation_dv_strings.rb
|
3
|
-
#
|
4
|
-
# Tests for the packed caption/message strings used in the Excel DV structure
|
5
|
-
# as part of data validation.
|
6
|
-
#
|
7
|
-
# reverse('©'), September 2005, 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
|
-
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
14
|
-
|
15
|
-
require "test/unit"
|
16
|
-
require 'writeexcel'
|
17
|
-
|
18
|
-
class TC_validation_dv_strings < 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
|
-
@workbook =
|
25
|
-
@worksheet = @workbook.add_worksheet
|
26
|
-
end
|
27
|
-
|
28
|
-
def teardown
|
29
|
-
@workbook.close
|
30
|
-
File.unlink(@test_file) if FileTest.exist?(@test_file)
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_empty_string
|
34
|
-
string = ''
|
35
|
-
max_length = 32
|
36
|
-
|
37
|
-
caption = " \tData validation: _pack_dv_string('', #{max_length})"
|
38
|
-
target = %w(
|
39
|
-
01 00 00 00
|
40
|
-
).join(' ')
|
41
|
-
result = unpack_record(@worksheet.pack_dv_string(string, max_length))
|
42
|
-
assert_equal(target, result, caption)
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_nil
|
46
|
-
string = nil
|
47
|
-
max_length = 32
|
48
|
-
|
49
|
-
caption = " \tData validation: _pack_dv_string('', #{max_length})"
|
50
|
-
target = %w(
|
51
|
-
01 00 00 00
|
52
|
-
).join(' ')
|
53
|
-
result = unpack_record(@worksheet.pack_dv_string(string, max_length))
|
54
|
-
assert_equal(target, result, caption)
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_single_space
|
58
|
-
string = ' '
|
59
|
-
max_length = 32
|
60
|
-
|
61
|
-
caption = " \tData validation: _pack_dv_string('', #{max_length})"
|
62
|
-
target = %w(
|
63
|
-
01 00 00 20
|
64
|
-
).join(' ')
|
65
|
-
result = unpack_record(@worksheet.pack_dv_string(string, max_length))
|
66
|
-
assert_equal(target, result, caption)
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_single_character
|
70
|
-
string = 'A'
|
71
|
-
max_length = 32
|
72
|
-
|
73
|
-
caption = " \tData validation: _pack_dv_string('', #{max_length})"
|
74
|
-
target = %w(
|
75
|
-
01 00 00 41
|
76
|
-
).join(' ')
|
77
|
-
result = unpack_record(@worksheet.pack_dv_string(string, max_length))
|
78
|
-
assert_equal(target, result, caption)
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_string_longer_than_32_characters_for_dialog_captions
|
82
|
-
string = 'This string is longer than 32 characters'
|
83
|
-
max_length = 32
|
84
|
-
|
85
|
-
caption = " \tData validation: _pack_dv_string('', #{max_length})"
|
86
|
-
target = %w(
|
87
|
-
20 00 00 54 68 69 73 20
|
88
|
-
73 74 72 69 6E 67 20 69 73 20 6C 6F 6E 67 65 72
|
89
|
-
20 74 68 61 6E 20 33 32 20 63 68
|
90
|
-
).join(' ')
|
91
|
-
result = unpack_record(@worksheet.pack_dv_string(string, max_length))
|
92
|
-
assert_equal(target, result, caption)
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_string_longer_than_32_characters_for_dialog_messages
|
96
|
-
string = 'ABCD' * 64
|
97
|
-
max_length = 255
|
98
|
-
|
99
|
-
caption = " \tData validation: _pack_dv_string('', #{max_length})"
|
100
|
-
target = %w(
|
101
|
-
FF 00 00 41 42 43 44 41 42 43 44 41 42 43 44 41
|
102
|
-
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
103
|
-
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
104
|
-
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
105
|
-
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
106
|
-
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
107
|
-
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
108
|
-
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
109
|
-
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
110
|
-
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
111
|
-
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
112
|
-
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
113
|
-
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
114
|
-
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
115
|
-
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
116
|
-
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
117
|
-
42 43
|
118
|
-
).join(' ')
|
119
|
-
result = unpack_record(@worksheet.pack_dv_string(string, max_length))
|
120
|
-
assert_equal(target, result, caption)
|
121
|
-
end
|
122
|
-
|
123
|
-
###############################################################################
|
124
|
-
#
|
125
|
-
# Unpack the binary data into a format suitable for printing in tests.
|
126
|
-
#
|
127
|
-
def unpack_record(data)
|
128
|
-
data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
|
129
|
-
end
|
130
|
-
|
131
|
-
end
|
1
|
+
##########################################################################
|
2
|
+
# test_31_validation_dv_strings.rb
|
3
|
+
#
|
4
|
+
# Tests for the packed caption/message strings used in the Excel DV structure
|
5
|
+
# as part of data validation.
|
6
|
+
#
|
7
|
+
# reverse('©'), September 2005, 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
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
14
|
+
|
15
|
+
require "test/unit"
|
16
|
+
require 'writeexcel'
|
17
|
+
|
18
|
+
class TC_validation_dv_strings < 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
|
+
@workbook = WriteExcel.new(@test_file)
|
25
|
+
@worksheet = @workbook.add_worksheet
|
26
|
+
end
|
27
|
+
|
28
|
+
def teardown
|
29
|
+
@workbook.close
|
30
|
+
File.unlink(@test_file) if FileTest.exist?(@test_file)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_empty_string
|
34
|
+
string = ''
|
35
|
+
max_length = 32
|
36
|
+
|
37
|
+
caption = " \tData validation: _pack_dv_string('', #{max_length})"
|
38
|
+
target = %w(
|
39
|
+
01 00 00 00
|
40
|
+
).join(' ')
|
41
|
+
result = unpack_record(@worksheet.pack_dv_string(string, max_length))
|
42
|
+
assert_equal(target, result, caption)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_nil
|
46
|
+
string = nil
|
47
|
+
max_length = 32
|
48
|
+
|
49
|
+
caption = " \tData validation: _pack_dv_string('', #{max_length})"
|
50
|
+
target = %w(
|
51
|
+
01 00 00 00
|
52
|
+
).join(' ')
|
53
|
+
result = unpack_record(@worksheet.pack_dv_string(string, max_length))
|
54
|
+
assert_equal(target, result, caption)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_single_space
|
58
|
+
string = ' '
|
59
|
+
max_length = 32
|
60
|
+
|
61
|
+
caption = " \tData validation: _pack_dv_string('', #{max_length})"
|
62
|
+
target = %w(
|
63
|
+
01 00 00 20
|
64
|
+
).join(' ')
|
65
|
+
result = unpack_record(@worksheet.pack_dv_string(string, max_length))
|
66
|
+
assert_equal(target, result, caption)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_single_character
|
70
|
+
string = 'A'
|
71
|
+
max_length = 32
|
72
|
+
|
73
|
+
caption = " \tData validation: _pack_dv_string('', #{max_length})"
|
74
|
+
target = %w(
|
75
|
+
01 00 00 41
|
76
|
+
).join(' ')
|
77
|
+
result = unpack_record(@worksheet.pack_dv_string(string, max_length))
|
78
|
+
assert_equal(target, result, caption)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_string_longer_than_32_characters_for_dialog_captions
|
82
|
+
string = 'This string is longer than 32 characters'
|
83
|
+
max_length = 32
|
84
|
+
|
85
|
+
caption = " \tData validation: _pack_dv_string('', #{max_length})"
|
86
|
+
target = %w(
|
87
|
+
20 00 00 54 68 69 73 20
|
88
|
+
73 74 72 69 6E 67 20 69 73 20 6C 6F 6E 67 65 72
|
89
|
+
20 74 68 61 6E 20 33 32 20 63 68
|
90
|
+
).join(' ')
|
91
|
+
result = unpack_record(@worksheet.pack_dv_string(string, max_length))
|
92
|
+
assert_equal(target, result, caption)
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_string_longer_than_32_characters_for_dialog_messages
|
96
|
+
string = 'ABCD' * 64
|
97
|
+
max_length = 255
|
98
|
+
|
99
|
+
caption = " \tData validation: _pack_dv_string('', #{max_length})"
|
100
|
+
target = %w(
|
101
|
+
FF 00 00 41 42 43 44 41 42 43 44 41 42 43 44 41
|
102
|
+
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
103
|
+
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
104
|
+
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
105
|
+
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
106
|
+
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
107
|
+
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
108
|
+
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
109
|
+
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
110
|
+
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
111
|
+
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
112
|
+
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
113
|
+
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
114
|
+
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
115
|
+
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
116
|
+
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
117
|
+
42 43
|
118
|
+
).join(' ')
|
119
|
+
result = unpack_record(@worksheet.pack_dv_string(string, max_length))
|
120
|
+
assert_equal(target, result, caption)
|
121
|
+
end
|
122
|
+
|
123
|
+
###############################################################################
|
124
|
+
#
|
125
|
+
# Unpack the binary data into a format suitable for printing in tests.
|
126
|
+
#
|
127
|
+
def unpack_record(data)
|
128
|
+
data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
@@ -1,211 +1,211 @@
|
|
1
|
-
##########################################################################
|
2
|
-
# test_32_validation_dv_formula.rb
|
3
|
-
#
|
4
|
-
# Tests for the Excel DVAL structure used in data validation.
|
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 'writeexcel'
|
16
|
-
|
17
|
-
class TC_validation_dv_formula < Test::Unit::TestCase
|
18
|
-
|
19
|
-
def setup
|
20
|
-
t = Time.now.strftime("%Y%m%d")
|
21
|
-
path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
22
|
-
@test_file = File.join(Dir.tmpdir, path)
|
23
|
-
@workbook =
|
24
|
-
@worksheet = @workbook.add_worksheet
|
25
|
-
@worksheet2 = @workbook.add_worksheet
|
26
|
-
end
|
27
|
-
|
28
|
-
def teardown
|
29
|
-
@workbook.close
|
30
|
-
File.unlink(@test_file) if FileTest.exist?(@test_file)
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_integer_values
|
34
|
-
formula = '10'
|
35
|
-
|
36
|
-
caption = " \tData validation: _pack_dv_formula('#{formula}')"
|
37
|
-
bytes = %w(
|
38
|
-
03 00 00 E0 1E 0A 00
|
39
|
-
)
|
40
|
-
|
41
|
-
# Zero out Excel's random unused word to allow comparison.
|
42
|
-
bytes[2] = '00'
|
43
|
-
bytes[3] = '00'
|
44
|
-
target = bytes.join(" ")
|
45
|
-
|
46
|
-
result = unpack_record(@worksheet.pack_dv_formula(formula))
|
47
|
-
assert_equal(target, result, caption)
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_decimal_values
|
51
|
-
formula = '1.2345'
|
52
|
-
|
53
|
-
caption = " \tData validation: _pack_dv_formula('#{formula}')"
|
54
|
-
bytes = %w(
|
55
|
-
09 00 E0 3F 1F 8D 97 6E 12 83 C0 F3 3F
|
56
|
-
)
|
57
|
-
|
58
|
-
# Zero out Excel's random unused word to allow comparison.
|
59
|
-
bytes[2] = '00'
|
60
|
-
bytes[3] = '00'
|
61
|
-
target = bytes.join(" ")
|
62
|
-
|
63
|
-
result = unpack_record(@worksheet.pack_dv_formula(formula))
|
64
|
-
assert_equal(target, result, caption)
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_date_values
|
68
|
-
formula = @worksheet.convert_date_time('2008-07-24T')
|
69
|
-
|
70
|
-
caption = " \tData validation: _pack_dv_formula('2008-07-24T')"
|
71
|
-
bytes = %w(
|
72
|
-
03 00 E0 3F 1E E5 9A
|
73
|
-
)
|
74
|
-
|
75
|
-
# Zero out Excel's random unused word to allow comparison.
|
76
|
-
bytes[2] = '00'
|
77
|
-
bytes[3] = '00'
|
78
|
-
target = bytes.join(" ")
|
79
|
-
|
80
|
-
result = unpack_record(@worksheet.pack_dv_formula(formula))
|
81
|
-
assert_equal(target, result, caption)
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_time_values
|
85
|
-
formula = @worksheet.convert_date_time('T12:00')
|
86
|
-
|
87
|
-
caption = " \tData validation: _pack_dv_formula('T12:00')"
|
88
|
-
bytes = %w(
|
89
|
-
09 00 E0 3F 1F 00 00 00 00 00 00 E0 3F
|
90
|
-
)
|
91
|
-
|
92
|
-
# Zero out Excel's random unused word to allow comparison.
|
93
|
-
bytes[2] = '00'
|
94
|
-
bytes[3] = '00'
|
95
|
-
target = bytes.join(" ")
|
96
|
-
|
97
|
-
result = unpack_record(@worksheet.pack_dv_formula(formula))
|
98
|
-
assert_equal(target, result, caption)
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_cell_reference_value_C9
|
102
|
-
formula = '=C9'
|
103
|
-
|
104
|
-
caption = " \tData validation: _pack_dv_formula('#{formula}')"
|
105
|
-
bytes = %w(
|
106
|
-
05 00 E0 3F 44 08 00 02 C0
|
107
|
-
)
|
108
|
-
|
109
|
-
# Zero out Excel's random unused word to allow comparison.
|
110
|
-
bytes[2] = '00'
|
111
|
-
bytes[3] = '00'
|
112
|
-
target = bytes.join(" ")
|
113
|
-
|
114
|
-
result = unpack_record(@worksheet.pack_dv_formula(formula))
|
115
|
-
assert_equal(target, result, caption)
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_cell_reference_value_E3_E6
|
119
|
-
formula = '=E3:E6'
|
120
|
-
|
121
|
-
caption = " \tData validation: _pack_dv_formula('#{formula}')"
|
122
|
-
bytes = %w(
|
123
|
-
09 00 0C 00 25 02 00 05 00 04 C0 04 C0
|
124
|
-
)
|
125
|
-
|
126
|
-
# Zero out Excel's random unused word to allow comparison.
|
127
|
-
bytes[2] = '00'
|
128
|
-
bytes[3] = '00'
|
129
|
-
target = bytes.join(" ")
|
130
|
-
|
131
|
-
result = unpack_record(@worksheet.pack_dv_formula(formula))
|
132
|
-
assert_equal(target, result, caption)
|
133
|
-
end
|
134
|
-
|
135
|
-
def test_cell_reference_value_E3_E6_absolute
|
136
|
-
formula = '=$E$3:$E$6'
|
137
|
-
|
138
|
-
caption = " \tData validation: _pack_dv_formula('#{formula}')"
|
139
|
-
bytes = %w(
|
140
|
-
09 00 0C 00 25 02 00 05 00 04 00 04 00
|
141
|
-
)
|
142
|
-
|
143
|
-
# Zero out Excel's random unused word to allow comparison.
|
144
|
-
bytes[2] = '00'
|
145
|
-
bytes[3] = '00'
|
146
|
-
target = bytes.join(" ")
|
147
|
-
|
148
|
-
result = unpack_record(@worksheet.pack_dv_formula(formula))
|
149
|
-
assert_equal(target, result, caption)
|
150
|
-
end
|
151
|
-
|
152
|
-
def test_list_values
|
153
|
-
formula = ['a', 'bb', 'ccc']
|
154
|
-
|
155
|
-
caption = " \tData validation: _pack_dv_formula(['a', 'bb', 'ccc'])"
|
156
|
-
bytes = %w(
|
157
|
-
0B 00 0C 00 17 08 00 61 00 62 62 00 63 63 63
|
158
|
-
)
|
159
|
-
|
160
|
-
# Zero out Excel's random unused word to allow comparison.
|
161
|
-
bytes[2] = '00'
|
162
|
-
bytes[3] = '00'
|
163
|
-
target = bytes.join(" ")
|
164
|
-
|
165
|
-
result = unpack_record(@worksheet.pack_dv_formula(formula))
|
166
|
-
assert_equal(target, result, caption)
|
167
|
-
end
|
168
|
-
|
169
|
-
def test_empty_string
|
170
|
-
formula = ''
|
171
|
-
|
172
|
-
caption = " \tData validation: _pack_dv_formula('')"
|
173
|
-
bytes = %w(
|
174
|
-
00 00 00
|
175
|
-
)
|
176
|
-
|
177
|
-
# Zero out Excel's random unused word to allow comparison.
|
178
|
-
bytes[2] = '00'
|
179
|
-
bytes[3] = '00'
|
180
|
-
target = bytes.join(" ")
|
181
|
-
|
182
|
-
result = unpack_record(@worksheet.pack_dv_formula(formula))
|
183
|
-
assert_equal(target, result, caption)
|
184
|
-
end
|
185
|
-
|
186
|
-
def test_undefined_value
|
187
|
-
formula = nil
|
188
|
-
|
189
|
-
caption = " \tData validation: _pack_dv_formula(nil)"
|
190
|
-
bytes = %w(
|
191
|
-
00 00 00
|
192
|
-
)
|
193
|
-
|
194
|
-
# Zero out Excel's random unused word to allow comparison.
|
195
|
-
bytes[2] = '00'
|
196
|
-
bytes[3] = '00'
|
197
|
-
target = bytes.join(" ")
|
198
|
-
|
199
|
-
result = unpack_record(@worksheet.pack_dv_formula(formula))
|
200
|
-
assert_equal(target, result, caption)
|
201
|
-
end
|
202
|
-
|
203
|
-
###############################################################################
|
204
|
-
#
|
205
|
-
# Unpack the binary data into a format suitable for printing in tests.
|
206
|
-
#
|
207
|
-
def unpack_record(data)
|
208
|
-
data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
|
209
|
-
end
|
210
|
-
|
211
|
-
end
|
1
|
+
##########################################################################
|
2
|
+
# test_32_validation_dv_formula.rb
|
3
|
+
#
|
4
|
+
# Tests for the Excel DVAL structure used in data validation.
|
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 'writeexcel'
|
16
|
+
|
17
|
+
class TC_validation_dv_formula < Test::Unit::TestCase
|
18
|
+
|
19
|
+
def setup
|
20
|
+
t = Time.now.strftime("%Y%m%d")
|
21
|
+
path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
22
|
+
@test_file = File.join(Dir.tmpdir, path)
|
23
|
+
@workbook = WriteExcel.new(@test_file)
|
24
|
+
@worksheet = @workbook.add_worksheet
|
25
|
+
@worksheet2 = @workbook.add_worksheet
|
26
|
+
end
|
27
|
+
|
28
|
+
def teardown
|
29
|
+
@workbook.close
|
30
|
+
File.unlink(@test_file) if FileTest.exist?(@test_file)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_integer_values
|
34
|
+
formula = '10'
|
35
|
+
|
36
|
+
caption = " \tData validation: _pack_dv_formula('#{formula}')"
|
37
|
+
bytes = %w(
|
38
|
+
03 00 00 E0 1E 0A 00
|
39
|
+
)
|
40
|
+
|
41
|
+
# Zero out Excel's random unused word to allow comparison.
|
42
|
+
bytes[2] = '00'
|
43
|
+
bytes[3] = '00'
|
44
|
+
target = bytes.join(" ")
|
45
|
+
|
46
|
+
result = unpack_record(@worksheet.pack_dv_formula(formula))
|
47
|
+
assert_equal(target, result, caption)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_decimal_values
|
51
|
+
formula = '1.2345'
|
52
|
+
|
53
|
+
caption = " \tData validation: _pack_dv_formula('#{formula}')"
|
54
|
+
bytes = %w(
|
55
|
+
09 00 E0 3F 1F 8D 97 6E 12 83 C0 F3 3F
|
56
|
+
)
|
57
|
+
|
58
|
+
# Zero out Excel's random unused word to allow comparison.
|
59
|
+
bytes[2] = '00'
|
60
|
+
bytes[3] = '00'
|
61
|
+
target = bytes.join(" ")
|
62
|
+
|
63
|
+
result = unpack_record(@worksheet.pack_dv_formula(formula))
|
64
|
+
assert_equal(target, result, caption)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_date_values
|
68
|
+
formula = @worksheet.convert_date_time('2008-07-24T')
|
69
|
+
|
70
|
+
caption = " \tData validation: _pack_dv_formula('2008-07-24T')"
|
71
|
+
bytes = %w(
|
72
|
+
03 00 E0 3F 1E E5 9A
|
73
|
+
)
|
74
|
+
|
75
|
+
# Zero out Excel's random unused word to allow comparison.
|
76
|
+
bytes[2] = '00'
|
77
|
+
bytes[3] = '00'
|
78
|
+
target = bytes.join(" ")
|
79
|
+
|
80
|
+
result = unpack_record(@worksheet.pack_dv_formula(formula))
|
81
|
+
assert_equal(target, result, caption)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_time_values
|
85
|
+
formula = @worksheet.convert_date_time('T12:00')
|
86
|
+
|
87
|
+
caption = " \tData validation: _pack_dv_formula('T12:00')"
|
88
|
+
bytes = %w(
|
89
|
+
09 00 E0 3F 1F 00 00 00 00 00 00 E0 3F
|
90
|
+
)
|
91
|
+
|
92
|
+
# Zero out Excel's random unused word to allow comparison.
|
93
|
+
bytes[2] = '00'
|
94
|
+
bytes[3] = '00'
|
95
|
+
target = bytes.join(" ")
|
96
|
+
|
97
|
+
result = unpack_record(@worksheet.pack_dv_formula(formula))
|
98
|
+
assert_equal(target, result, caption)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_cell_reference_value_C9
|
102
|
+
formula = '=C9'
|
103
|
+
|
104
|
+
caption = " \tData validation: _pack_dv_formula('#{formula}')"
|
105
|
+
bytes = %w(
|
106
|
+
05 00 E0 3F 44 08 00 02 C0
|
107
|
+
)
|
108
|
+
|
109
|
+
# Zero out Excel's random unused word to allow comparison.
|
110
|
+
bytes[2] = '00'
|
111
|
+
bytes[3] = '00'
|
112
|
+
target = bytes.join(" ")
|
113
|
+
|
114
|
+
result = unpack_record(@worksheet.pack_dv_formula(formula))
|
115
|
+
assert_equal(target, result, caption)
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_cell_reference_value_E3_E6
|
119
|
+
formula = '=E3:E6'
|
120
|
+
|
121
|
+
caption = " \tData validation: _pack_dv_formula('#{formula}')"
|
122
|
+
bytes = %w(
|
123
|
+
09 00 0C 00 25 02 00 05 00 04 C0 04 C0
|
124
|
+
)
|
125
|
+
|
126
|
+
# Zero out Excel's random unused word to allow comparison.
|
127
|
+
bytes[2] = '00'
|
128
|
+
bytes[3] = '00'
|
129
|
+
target = bytes.join(" ")
|
130
|
+
|
131
|
+
result = unpack_record(@worksheet.pack_dv_formula(formula))
|
132
|
+
assert_equal(target, result, caption)
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_cell_reference_value_E3_E6_absolute
|
136
|
+
formula = '=$E$3:$E$6'
|
137
|
+
|
138
|
+
caption = " \tData validation: _pack_dv_formula('#{formula}')"
|
139
|
+
bytes = %w(
|
140
|
+
09 00 0C 00 25 02 00 05 00 04 00 04 00
|
141
|
+
)
|
142
|
+
|
143
|
+
# Zero out Excel's random unused word to allow comparison.
|
144
|
+
bytes[2] = '00'
|
145
|
+
bytes[3] = '00'
|
146
|
+
target = bytes.join(" ")
|
147
|
+
|
148
|
+
result = unpack_record(@worksheet.pack_dv_formula(formula))
|
149
|
+
assert_equal(target, result, caption)
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_list_values
|
153
|
+
formula = ['a', 'bb', 'ccc']
|
154
|
+
|
155
|
+
caption = " \tData validation: _pack_dv_formula(['a', 'bb', 'ccc'])"
|
156
|
+
bytes = %w(
|
157
|
+
0B 00 0C 00 17 08 00 61 00 62 62 00 63 63 63
|
158
|
+
)
|
159
|
+
|
160
|
+
# Zero out Excel's random unused word to allow comparison.
|
161
|
+
bytes[2] = '00'
|
162
|
+
bytes[3] = '00'
|
163
|
+
target = bytes.join(" ")
|
164
|
+
|
165
|
+
result = unpack_record(@worksheet.pack_dv_formula(formula))
|
166
|
+
assert_equal(target, result, caption)
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_empty_string
|
170
|
+
formula = ''
|
171
|
+
|
172
|
+
caption = " \tData validation: _pack_dv_formula('')"
|
173
|
+
bytes = %w(
|
174
|
+
00 00 00
|
175
|
+
)
|
176
|
+
|
177
|
+
# Zero out Excel's random unused word to allow comparison.
|
178
|
+
bytes[2] = '00'
|
179
|
+
bytes[3] = '00'
|
180
|
+
target = bytes.join(" ")
|
181
|
+
|
182
|
+
result = unpack_record(@worksheet.pack_dv_formula(formula))
|
183
|
+
assert_equal(target, result, caption)
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_undefined_value
|
187
|
+
formula = nil
|
188
|
+
|
189
|
+
caption = " \tData validation: _pack_dv_formula(nil)"
|
190
|
+
bytes = %w(
|
191
|
+
00 00 00
|
192
|
+
)
|
193
|
+
|
194
|
+
# Zero out Excel's random unused word to allow comparison.
|
195
|
+
bytes[2] = '00'
|
196
|
+
bytes[3] = '00'
|
197
|
+
target = bytes.join(" ")
|
198
|
+
|
199
|
+
result = unpack_record(@worksheet.pack_dv_formula(formula))
|
200
|
+
assert_equal(target, result, caption)
|
201
|
+
end
|
202
|
+
|
203
|
+
###############################################################################
|
204
|
+
#
|
205
|
+
# Unpack the binary data into a format suitable for printing in tests.
|
206
|
+
#
|
207
|
+
def unpack_record(data)
|
208
|
+
data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|