WriteExcel 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +17 -0
  5. data/Rakefile +47 -0
  6. data/VERSION +1 -0
  7. data/examples/a_simple.rb +42 -0
  8. data/examples/autofilters.rb +266 -0
  9. data/examples/bigfile.rb +30 -0
  10. data/examples/copyformat.rb +51 -0
  11. data/examples/data_validate.rb +278 -0
  12. data/examples/date_time.rb +86 -0
  13. data/examples/demo.rb +118 -0
  14. data/examples/diag_border.rb +35 -0
  15. data/examples/formats.rb +489 -0
  16. data/examples/header.rb +136 -0
  17. data/examples/hidden.rb +28 -0
  18. data/examples/hyperlink.rb +42 -0
  19. data/examples/images.rb +52 -0
  20. data/examples/merge1.rb +39 -0
  21. data/examples/merge2.rb +44 -0
  22. data/examples/merge3.rb +65 -0
  23. data/examples/merge4.rb +82 -0
  24. data/examples/merge5.rb +79 -0
  25. data/examples/protection.rb +46 -0
  26. data/examples/regions.rb +52 -0
  27. data/examples/repeat.rb +42 -0
  28. data/examples/stats.rb +75 -0
  29. data/examples/stocks.rb +80 -0
  30. data/examples/tab_colors.rb +30 -0
  31. data/lib/WriteExcel.rb +30 -0
  32. data/lib/WriteExcel/biffwriter.rb +259 -0
  33. data/lib/WriteExcel/chart.rb +217 -0
  34. data/lib/WriteExcel/excelformula.y +138 -0
  35. data/lib/WriteExcel/excelformulaparser.rb +573 -0
  36. data/lib/WriteExcel/format.rb +1108 -0
  37. data/lib/WriteExcel/formula.rb +986 -0
  38. data/lib/WriteExcel/olewriter.rb +322 -0
  39. data/lib/WriteExcel/properties.rb +250 -0
  40. data/lib/WriteExcel/storage_lite.rb +590 -0
  41. data/lib/WriteExcel/workbook.rb +2602 -0
  42. data/lib/WriteExcel/worksheet.rb +6378 -0
  43. data/spec/WriteExcel_spec.rb +7 -0
  44. data/spec/spec.opts +1 -0
  45. data/spec/spec_helper.rb +9 -0
  46. data/test/tc_all.rb +31 -0
  47. data/test/tc_biff.rb +104 -0
  48. data/test/tc_chart.rb +22 -0
  49. data/test/tc_example_match.rb +1280 -0
  50. data/test/tc_format.rb +1264 -0
  51. data/test/tc_formula.rb +63 -0
  52. data/test/tc_ole.rb +110 -0
  53. data/test/tc_storage_lite.rb +102 -0
  54. data/test/tc_workbook.rb +115 -0
  55. data/test/tc_worksheet.rb +115 -0
  56. data/test/test_00_IEEE_double.rb +14 -0
  57. data/test/test_01_add_worksheet.rb +12 -0
  58. data/test/test_02_merge_formats.rb +58 -0
  59. data/test/test_04_dimensions.rb +397 -0
  60. data/test/test_05_rows.rb +182 -0
  61. data/test/test_06_extsst.rb +80 -0
  62. data/test/test_11_date_time.rb +484 -0
  63. data/test/test_12_date_only.rb +506 -0
  64. data/test/test_13_date_seconds.rb +486 -0
  65. data/test/test_21_escher.rb +629 -0
  66. data/test/test_22_mso_drawing_group.rb +739 -0
  67. data/test/test_23_note.rb +78 -0
  68. data/test/test_24_txo.rb +80 -0
  69. data/test/test_26_autofilter.rb +327 -0
  70. data/test/test_27_autofilter.rb +144 -0
  71. data/test/test_28_autofilter.rb +174 -0
  72. data/test/test_29_process_jpg.rb +131 -0
  73. data/test/test_30_validation_dval.rb +82 -0
  74. data/test/test_31_validation_dv_strings.rb +131 -0
  75. data/test/test_32_validation_dv_formula.rb +211 -0
  76. data/test/test_40_property_types.rb +191 -0
  77. data/test/test_41_properties.rb +238 -0
  78. data/test/test_42_set_properties.rb +430 -0
  79. data/test/ts_all.rb +34 -0
  80. metadata +154 -0
@@ -0,0 +1,144 @@
1
+ ##########################################################################
2
+ # test_27_autofilter.rb
3
+ #
4
+ # Tests for the token extraction method used to parse autofilter expressions.
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_27_autofilter < Test::Unit::TestCase
18
+
19
+ def test_27_autofilter
20
+ @tests.each do |test|
21
+ expression = test[0]
22
+ expected = test[1]
23
+ result = @worksheet.extract_filter_tokens(expression)
24
+
25
+ testname = expression || 'none'
26
+
27
+ assert_equal(expected, result, testname)
28
+ end
29
+ end
30
+
31
+ ###############################################################################
32
+ #
33
+ # Unpack the binary data into a format suitable for printing in tests.
34
+ #
35
+ def unpack_record(data)
36
+ data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
37
+ end
38
+
39
+ def setup
40
+ t = Time.now.strftime("%Y%m%d")
41
+ path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
42
+ @test_file = File.join(Dir.tmpdir, path)
43
+ @workbook = Spreadsheet::WriteExcel.new(@test_file)
44
+ @worksheet = @workbook.add_worksheet
45
+ @tests = [
46
+ [
47
+ nil,
48
+ [],
49
+ ],
50
+
51
+ [
52
+ '',
53
+ [],
54
+ ],
55
+
56
+ [
57
+ '0 < 2000',
58
+ [0, '<', 2000],
59
+ ],
60
+
61
+ [
62
+ 'x < 2000',
63
+ ['x', '<', 2000],
64
+ ],
65
+
66
+ [
67
+ 'x > 2000',
68
+ ['x', '>', 2000],
69
+ ],
70
+
71
+ [
72
+ 'x == 2000',
73
+ ['x', '==', 2000],
74
+ ],
75
+
76
+ [
77
+ 'x > 2000 and x < 5000',
78
+ ['x', '>', 2000, 'and', 'x', '<', 5000],
79
+ ],
80
+
81
+ [
82
+ 'x = "foo"',
83
+ ['x', '=', 'foo'],
84
+ ],
85
+
86
+ [
87
+ 'x = foo',
88
+ ['x', '=', 'foo'],
89
+ ],
90
+
91
+ [
92
+ 'x = "foo bar"',
93
+ ['x', '=', 'foo bar'],
94
+ ],
95
+
96
+ [
97
+ 'x = "foo "" bar"',
98
+ ['x', '=', 'foo " bar'],
99
+ ],
100
+
101
+ [
102
+ 'x = "foo bar" or x = "bar foo"',
103
+ ['x', '=', 'foo bar', 'or', 'x', '=', 'bar foo'],
104
+ ],
105
+
106
+ [
107
+ 'x = "foo "" bar" or x = "bar "" foo"',
108
+ ['x', '=', 'foo " bar', 'or', 'x', '=', 'bar " foo'],
109
+ ],
110
+
111
+ [
112
+ 'x = """"""""',
113
+ ['x', '=', '"""'],
114
+ ],
115
+
116
+ [
117
+ 'x = Blanks',
118
+ ['x', '=', 'Blanks'],
119
+ ],
120
+
121
+ [
122
+ 'x = NonBlanks',
123
+ ['x', '=', 'NonBlanks'],
124
+ ],
125
+
126
+ [
127
+ 'top 10 %',
128
+ ['top', 10, '%'],
129
+ ],
130
+
131
+ [
132
+ 'top 10 items',
133
+ ['top', 10, 'items'],
134
+ ],
135
+
136
+ ]
137
+ end
138
+
139
+ def teardown
140
+ @workbook.close
141
+ File.unlink(@test_file) if FileTest.exist?(@test_file)
142
+ end
143
+
144
+ end
@@ -0,0 +1,174 @@
1
+ ##########################################################################
2
+ # test_28_autofilter.rb
3
+ #
4
+ # Tests for the token parsing methods used to parse autofilter expressions.
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_28_autofilter < Test::Unit::TestCase
18
+
19
+ def test_28_autofilter
20
+ @tests.each do |test|
21
+ expression = test[0]
22
+ expected = test[1]
23
+ tokens = @worksheet.extract_filter_tokens(expression)
24
+ result = @worksheet.parse_filter_expression(expression, tokens)
25
+
26
+ testname = expression || 'none'
27
+
28
+ assert_equal(expected, result, testname)
29
+ end
30
+ end
31
+
32
+ ###############################################################################
33
+ #
34
+ # Unpack the binary data into a format suitable for printing in tests.
35
+ #
36
+ def unpack_record(data)
37
+ data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
38
+ end
39
+
40
+ def setup
41
+ t = Time.now.strftime("%Y%m%d")
42
+ path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
43
+ @test_file = File.join(Dir.tmpdir, path)
44
+ @workbook = Spreadsheet::WriteExcel.new(@test_file)
45
+ @worksheet = @workbook.add_worksheet
46
+ @tests = [
47
+ [
48
+ 'x = 2000',
49
+ [2, 2000],
50
+ ],
51
+
52
+ [
53
+ 'x == 2000',
54
+ [2, 2000],
55
+ ],
56
+
57
+ [
58
+ 'x =~ 2000',
59
+ [2, 2000],
60
+ ],
61
+
62
+ [
63
+ 'x eq 2000',
64
+ [2, 2000],
65
+ ],
66
+
67
+ [
68
+ 'x <> 2000',
69
+ [5, 2000],
70
+ ],
71
+
72
+ [
73
+ 'x != 2000',
74
+ [5, 2000],
75
+ ],
76
+
77
+ [
78
+ 'x ne 2000',
79
+ [5, 2000],
80
+ ],
81
+
82
+ [
83
+ 'x !~ 2000',
84
+ [5, 2000],
85
+ ],
86
+
87
+ [
88
+ 'x > 2000',
89
+ [4, 2000],
90
+ ],
91
+
92
+ [
93
+ 'x < 2000',
94
+ [1, 2000],
95
+ ],
96
+
97
+ [
98
+ 'x >= 2000',
99
+ [6, 2000],
100
+ ],
101
+
102
+ [
103
+ 'x <= 2000',
104
+ [3, 2000],
105
+ ],
106
+
107
+ [
108
+ 'x > 2000 and x < 5000',
109
+ [4, 2000, 0, 1, 5000],
110
+ ],
111
+
112
+ [
113
+ 'x > 2000 && x < 5000',
114
+ [4, 2000, 0, 1, 5000],
115
+ ],
116
+
117
+ [
118
+ 'x > 2000 or x < 5000',
119
+ [4, 2000, 1, 1, 5000],
120
+ ],
121
+
122
+ [
123
+ 'x > 2000 || x < 5000',
124
+ [4, 2000, 1, 1, 5000],
125
+ ],
126
+
127
+ [
128
+ 'x = Blanks',
129
+ [2, 'blanks'],
130
+ ],
131
+
132
+ [
133
+ 'x = NonBlanks',
134
+ [2, 'nonblanks'],
135
+ ],
136
+
137
+ [
138
+ 'x <> Blanks',
139
+ [2, 'nonblanks'],
140
+ ],
141
+
142
+ [
143
+ 'x <> NonBlanks',
144
+ [2, 'blanks'],
145
+ ],
146
+
147
+ [
148
+ 'Top 10 Items',
149
+ [30, 10],
150
+ ],
151
+
152
+ [
153
+ 'Top 20 %',
154
+ [31, 20],
155
+ ],
156
+
157
+ [
158
+ 'Bottom 5 Items',
159
+ [32, 5],
160
+ ],
161
+
162
+ [
163
+ 'Bottom 101 %',
164
+ [33, 101],
165
+ ],
166
+ ]
167
+ end
168
+
169
+ def teardown
170
+ @workbook.close
171
+ File.unlink(@test_file) if FileTest.exist?(@test_file)
172
+ end
173
+
174
+ end
@@ -0,0 +1,131 @@
1
+ ##########################################################################
2
+ # test_29_process_jpg.rb
3
+ #
4
+ # Tests for the JPEG width and height processing.
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_29_process_jpg < 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 = Spreadsheet::WriteExcel.new(@test_file)
24
+ @type = 5 # Excel Blip type (MSOBLIPTYPE).
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_valid_jpg_image_1
33
+ testname = '3w x 5h jpeg image.'
34
+
35
+ data = %w(
36
+ FF D8 FF E0 00 10 4A 46 49 46 00 01 01 01 00 60
37
+ 00 60 00 00 FF DB 00 43 00 06 04 05 06 05 04 06
38
+ 06 05 06 07 07 06 08 0A 10 0A 0A 09 09 0A 14 0E
39
+ 0F 0C 10 17 14 18 18 17 14 16 16 1A 1D 25 1F 1A
40
+ 1B 23 1C 16 16 20 2C 20 23 26 27 29 2A 29 19 1F
41
+ 2D 30 2D 28 30 25 28 29 28 FF DB 00 43 01 07 07
42
+ 07 0A 08 0A 13 0A 0A 13 28 1A 16 1A 28 28 28 28
43
+ 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28
44
+ 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28
45
+ 28 28 28 28 28 28 28 28 28 28 28 28 28 28 FF C0
46
+ 00 11 08 00 05 00 03 03 01 22 00 02 11 01 03 11
47
+ 01 FF C4 00 15 00 01 01 00 00 00 00 00 00 00 00
48
+ 00 00 00 00 00 00 00 07 FF C4 00 14 10 01 00 00
49
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF C4
50
+ 00 15 01 01 01 00 00 00 00 00 00 00 00 00 00 00
51
+ 00 00 00 06 08 FF C4 00 14 11 01 00 00 00 00 00
52
+ 00 00 00 00 00 00 00 00 00 00 00 FF DA 00 0C 03
53
+ 01 00 02 11 03 11 00 3F 00 9D 00 1C A4 5F FF D9
54
+ )
55
+ image = [data.join('')].pack('H*')
56
+
57
+ expected = [@type, 3, 5]
58
+ result = @workbook.process_jpg(image, 'test.jpg')
59
+ assert_equal(expected, result, " \t" + testname)
60
+ end
61
+
62
+ def test_valid_jpg_image_2
63
+ testname = '5w x 3h jpeg image.'
64
+
65
+ data = %w(
66
+ FF D8 FF E0 00 10 4A 46 49 46 00 01 01 01 00 60
67
+ 00 60 00 00 FF DB 00 43 00 06 04 05 06 05 04 06
68
+ 06 05 06 07 07 06 08 0A 10 0A 0A 09 09 0A 14 0E
69
+ 0F 0C 10 17 14 18 18 17 14 16 16 1A 1D 25 1F 1A
70
+ 1B 23 1C 16 16 20 2C 20 23 26 27 29 2A 29 19 1F
71
+ 2D 30 2D 28 30 25 28 29 28 FF DB 00 43 01 07 07
72
+ 07 0A 08 0A 13 0A 0A 13 28 1A 16 1A 28 28 28 28
73
+ 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28
74
+ 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28
75
+ 28 28 28 28 28 28 28 28 28 28 28 28 28 28 FF C0
76
+ 00 11 08 00 03 00 05 03 01 22 00 02 11 01 03 11
77
+ 01 FF C4 00 15 00 01 01 00 00 00 00 00 00 00 00
78
+ 00 00 00 00 00 00 00 07 FF C4 00 14 10 01 00 00
79
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF C4
80
+ 00 15 01 01 01 00 00 00 00 00 00 00 00 00 00 00
81
+ 00 00 00 06 08 FF C4 00 14 11 01 00 00 00 00 00
82
+ 00 00 00 00 00 00 00 00 00 00 00 FF DA 00 0C 03
83
+ 01 00 02 11 03 11 00 3F 00 9D 00 1C A4 5F FF D9
84
+ )
85
+ image = [data.join('')].pack('H*')
86
+
87
+ expected = [@type, 5, 3]
88
+ result = @workbook.process_jpg(image, 'test.jpg')
89
+ assert_equal(expected, result, " \t" + testname)
90
+ end
91
+
92
+ def test_valid_jpg_image_3_ffco_marker_missing
93
+ testname = 'FFCO marker missing in image.'
94
+
95
+ data = %w(
96
+ FF D8 FF E0 00 10 4A 46 49 46 00 01 01 01 00 60
97
+ 00 60 00 00 FF DB 00 43 00 06 04 05 06 05 04 06
98
+ 06 05 06 07 07 06 08 0A 10 0A 0A 09 09 0A 14 0E
99
+ 0F 0C 10 17 14 18 18 17 14 16 16 1A 1D 25 1F 1A
100
+ 1B 23 1C 16 16 20 2C 20 23 26 27 29 2A 29 19 1F
101
+ 2D 30 2D 28 30 25 28 29 28 FF DB 00 43 01 07 07
102
+ 07 0A 08 0A 13 0A 0A 13 28 1A 16 1A 28 28 28 28
103
+ 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28
104
+ 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28
105
+ 28 28 28 28 28 28 28 28 28 28 28 28 28 28 FF C1
106
+ 00 11 08 00 03 00 05 03 01 22 00 02 11 01 03 11
107
+ 01 FF C4 00 15 00 01 01 00 00 00 00 00 00 00 00
108
+ 00 00 00 00 00 00 00 07 FF C4 00 14 10 01 00 00
109
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF C4
110
+ 00 15 01 01 01 00 00 00 00 00 00 00 00 00 00 00
111
+ 00 00 00 06 08 FF C4 00 14 11 01 00 00 00 00 00
112
+ 00 00 00 00 00 00 00 00 00 00 00 FF DA 00 0C 03
113
+ 01 00 02 11 03 11 00 3F 00 9D 00 1C A4 5F FF D9
114
+ )
115
+ image = [data.join('')].pack('H*')
116
+
117
+ assert_raise(RuntimeError, " \t" + testname) {
118
+ @workbook.process_jpg(image, 'test.jpg')
119
+ }
120
+ end
121
+
122
+ def test_invalid_jpeg_image
123
+ testname = 'empty image'
124
+ image = ''
125
+
126
+ assert_raise(RuntimeError, " \t" + testname) {
127
+ @workbook.process_jpg(image, 'test.jpg')
128
+ }
129
+ end
130
+
131
+ end