writeexcel 0.1.0 → 0.3.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 (143) hide show
  1. data/README +26 -31
  2. data/examples/a_simple.rb +42 -42
  3. data/examples/{autofilters.rb → autofilter.rb} +264 -266
  4. data/examples/bigfile.rb +29 -0
  5. data/examples/chart_area.rb +120 -0
  6. data/examples/chart_bar.rb +119 -0
  7. data/examples/chart_column.rb +119 -0
  8. data/examples/chart_line.rb +119 -0
  9. data/examples/chart_pie.rb +107 -0
  10. data/examples/chart_scatter.rb +120 -0
  11. data/examples/chart_stock.rb +147 -0
  12. data/examples/copyformat.rb +51 -51
  13. data/examples/data_validate.rb +278 -278
  14. data/examples/date_time.rb +86 -86
  15. data/examples/defined_name.rb +31 -0
  16. data/examples/demo.rb +120 -118
  17. data/examples/diag_border.rb +35 -35
  18. data/examples/formats.rb +489 -489
  19. data/examples/header.rb +136 -136
  20. data/examples/hidden.rb +28 -28
  21. data/examples/hyperlink.rb +42 -42
  22. data/examples/images.rb +52 -52
  23. data/examples/merge1.rb +39 -39
  24. data/examples/merge2.rb +44 -44
  25. data/examples/merge3.rb +65 -65
  26. data/examples/merge4.rb +82 -82
  27. data/examples/merge5.rb +79 -79
  28. data/examples/properties.rb +33 -0
  29. data/examples/properties_jp.rb +32 -0
  30. data/examples/protection.rb +46 -46
  31. data/examples/regions.rb +52 -52
  32. data/examples/repeat.rb +42 -42
  33. data/examples/stats.rb +75 -75
  34. data/examples/stocks.rb +80 -80
  35. data/examples/tab_colors.rb +30 -30
  36. data/examples/write_arrays.rb +82 -0
  37. data/lib/writeexcel.rb +1134 -18
  38. data/lib/writeexcel/biffwriter.rb +273 -260
  39. data/lib/writeexcel/chart.rb +2306 -217
  40. data/lib/writeexcel/charts/area.rb +152 -0
  41. data/lib/writeexcel/charts/bar.rb +177 -0
  42. data/lib/writeexcel/charts/column.rb +156 -0
  43. data/lib/writeexcel/charts/external.rb +61 -0
  44. data/lib/writeexcel/charts/line.rb +152 -0
  45. data/lib/writeexcel/charts/pie.rb +169 -0
  46. data/lib/writeexcel/charts/scatter.rb +192 -0
  47. data/lib/writeexcel/charts/stock.rb +211 -0
  48. data/lib/writeexcel/excelformulaparser.rb +208 -195
  49. data/lib/writeexcel/format.rb +1697 -1108
  50. data/lib/writeexcel/formula.rb +1050 -986
  51. data/lib/writeexcel/olewriter.rb +322 -322
  52. data/lib/writeexcel/properties.rb +251 -250
  53. data/lib/writeexcel/storage_lite.rb +968 -0
  54. data/lib/writeexcel/workbook.rb +3294 -2630
  55. data/lib/writeexcel/worksheet.rb +9012 -6377
  56. data/test/excelfile/Chart1.xls +0 -0
  57. data/test/excelfile/Chart2.xls +0 -0
  58. data/test/excelfile/Chart3.xls +0 -0
  59. data/test/excelfile/Chart4.xls +0 -0
  60. data/test/excelfile/Chart5.xls +0 -0
  61. data/test/perl_output/Chart1.xls.data +0 -0
  62. data/test/perl_output/Chart2.xls.data +0 -0
  63. data/test/perl_output/Chart3.xls.data +0 -0
  64. data/test/perl_output/Chart4.xls.data +0 -0
  65. data/test/perl_output/Chart5.xls.data +0 -0
  66. data/test/perl_output/a_simple.xls +0 -0
  67. data/test/perl_output/autofilter.xls +0 -0
  68. data/test/perl_output/chart_area.xls +0 -0
  69. data/test/perl_output/chart_bar.xls +0 -0
  70. data/test/perl_output/chart_column.xls +0 -0
  71. data/test/perl_output/chart_line.xls +0 -0
  72. data/test/perl_output/data_validate.xls +0 -0
  73. data/test/perl_output/date_time.xls +0 -0
  74. data/test/perl_output/demo.xls +0 -0
  75. data/test/perl_output/demo101.bin +0 -0
  76. data/test/perl_output/demo201.bin +0 -0
  77. data/test/perl_output/demo301.bin +0 -0
  78. data/test/perl_output/demo401.bin +0 -0
  79. data/test/perl_output/demo501.bin +0 -0
  80. data/test/perl_output/diag_border.xls +0 -0
  81. data/test/perl_output/headers.xls +0 -0
  82. data/test/perl_output/hyperlink.xls +0 -0
  83. data/test/perl_output/images.xls +0 -0
  84. data/test/perl_output/merge1.xls +0 -0
  85. data/test/perl_output/merge2.xls +0 -0
  86. data/test/perl_output/merge3.xls +0 -0
  87. data/test/perl_output/merge4.xls +0 -0
  88. data/test/perl_output/merge5.xls +0 -0
  89. data/test/perl_output/protection.xls +0 -0
  90. data/test/perl_output/regions.xls +0 -0
  91. data/test/perl_output/stats.xls +0 -0
  92. data/test/perl_output/stocks.xls +0 -0
  93. data/test/perl_output/tab_colors.xls +0 -0
  94. data/test/perl_output/unicode_cyrillic.xls +0 -0
  95. data/test/perl_output/workbook1.xls +0 -0
  96. data/test/perl_output/workbook2.xls +0 -0
  97. data/test/tc_all.rb +32 -31
  98. data/test/tc_biff.rb +104 -104
  99. data/test/tc_chart.rb +22 -22
  100. data/test/tc_example_match.rb +1944 -1280
  101. data/test/tc_format.rb +1254 -1267
  102. data/test/tc_formula.rb +63 -63
  103. data/test/tc_ole.rb +110 -110
  104. data/test/tc_storage_lite.rb +149 -0
  105. data/test/tc_workbook.rb +140 -115
  106. data/test/tc_worksheet.rb +115 -115
  107. data/test/test_00_IEEE_double.rb +14 -14
  108. data/test/test_01_add_worksheet.rb +12 -12
  109. data/test/test_02_merge_formats.rb +58 -58
  110. data/test/test_04_dimensions.rb +397 -397
  111. data/test/test_05_rows.rb +182 -182
  112. data/test/test_06_extsst.rb +80 -80
  113. data/test/test_11_date_time.rb +484 -484
  114. data/test/test_12_date_only.rb +506 -506
  115. data/test/test_13_date_seconds.rb +486 -486
  116. data/test/test_21_escher.rb +642 -629
  117. data/test/test_22_mso_drawing_group.rb +750 -739
  118. data/test/test_23_note.rb +78 -78
  119. data/test/test_24_txo.rb +80 -80
  120. data/test/test_25_position_object.rb +82 -0
  121. data/test/test_26_autofilter.rb +327 -327
  122. data/test/test_27_autofilter.rb +144 -144
  123. data/test/test_28_autofilter.rb +174 -174
  124. data/test/test_29_process_jpg.rb +681 -131
  125. data/test/test_30_validation_dval.rb +82 -82
  126. data/test/test_31_validation_dv_strings.rb +131 -131
  127. data/test/test_32_validation_dv_formula.rb +211 -211
  128. data/test/test_40_property_types.rb +191 -191
  129. data/test/test_41_properties.rb +238 -238
  130. data/test/test_42_set_properties.rb +442 -419
  131. data/test/test_50_name_stored.rb +305 -0
  132. data/test/test_51_name_print_area.rb +363 -0
  133. data/test/test_52_name_print_titles.rb +460 -0
  134. data/test/test_53_autofilter.rb +209 -0
  135. data/test/test_60_chart_generic.rb +576 -0
  136. data/test/test_61_chart_subclasses.rb +97 -0
  137. data/test/test_62_chart_formats.rb +270 -0
  138. data/test/test_63_chart_area_formats.rb +647 -0
  139. data/test/test_chartex.rb +35 -0
  140. data/test/ts_all.rb +46 -34
  141. data/writeexcel.gemspec +18 -0
  142. data/writeexcel.rdoc +583 -0
  143. metadata +162 -108
@@ -0,0 +1,97 @@
1
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
+
3
+ require "test/unit"
4
+ require 'writeexcel'
5
+ require 'stringio'
6
+
7
+ ###############################################################################
8
+ #
9
+ # A test for Chart.
10
+ #
11
+ # Tests for the Excel chart.rb methods.
12
+ #
13
+ # reverse(''), December 2009, John McNamara, jmcnamara@cpan.org
14
+ #
15
+ # original written in Perl by John McNamara
16
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
17
+ #
18
+ class TC_chart_subclasses < Test::Unit::TestCase
19
+ def setup
20
+ io = StringIO.new
21
+ @workbook = WriteExcel.new(io)
22
+ end
23
+
24
+ def test_store_chart_type_of_column
25
+ chart = Chart.factory(Chart::Column, nil, nil, nil, nil, nil, nil,
26
+ nil, nil, nil, nil)
27
+ expected = %w(
28
+ 17 10 06 00 00 00 96 00 00 00
29
+ ).join(' ')
30
+ got = unpack_record(chart.store_chart_type)
31
+ assert_equal(expected, got)
32
+ end
33
+
34
+ def test_store_chart_type_of_bar
35
+ chart = Chart.factory(Chart::Bar, nil, nil, nil, nil, nil, nil,
36
+ nil, nil, nil, nil)
37
+ expected = %w(
38
+ 17 10 06 00 00 00 96 00 01 00
39
+ ).join(' ')
40
+ got = unpack_record(chart.store_chart_type)
41
+ assert_equal(expected, got)
42
+ end
43
+
44
+ def test_store_chart_type_of_line
45
+ chart = Chart.factory(Chart::Line, nil, nil, nil, nil, nil, nil,
46
+ nil, nil, nil, nil)
47
+ expected = %w(
48
+ 18 10 02 00 00 00
49
+ ).join(' ')
50
+ got = unpack_record(chart.store_chart_type)
51
+ assert_equal(expected, got)
52
+ end
53
+
54
+ def test_store_chart_type_of_area
55
+ chart = Chart.factory(Chart::Area, nil, nil, nil, nil, nil, nil,
56
+ nil, nil, nil, nil)
57
+ expected = %w(
58
+ 1A 10 02 00 01 00
59
+ ).join(' ')
60
+ got = unpack_record(chart.store_chart_type)
61
+ assert_equal(expected, got)
62
+ end
63
+
64
+ def test_store_chart_type_of_pie
65
+ chart = Chart.factory(Chart::Pie, nil, nil, nil, nil, nil, nil,
66
+ nil, nil, nil, nil)
67
+ expected = %w(
68
+ 19 10 06 00 00 00 00 00 02 00
69
+ ).join(' ')
70
+ got = unpack_record(chart.store_chart_type)
71
+ assert_equal(expected, got)
72
+ end
73
+
74
+ def test_store_chart_type_of_scatter
75
+ chart = Chart.factory(Chart::Scatter, nil, nil, nil, nil, nil, nil,
76
+ nil, nil, nil, nil)
77
+ expected = %w(
78
+ 1B 10 06 00 64 00 01 00 00 00
79
+ ).join(' ')
80
+ got = unpack_record(chart.store_chart_type)
81
+ assert_equal(expected, got)
82
+ end
83
+
84
+ def test_store_chart_type_of_stock
85
+ chart = Chart.factory(Chart::Stock, nil, nil, nil, nil, nil, nil,
86
+ nil, nil, nil, nil)
87
+ expected = %w(
88
+ 18 10 02 00 00 00
89
+ ).join(' ')
90
+ got = unpack_record(chart.store_chart_type)
91
+ assert_equal(expected, got)
92
+ end
93
+
94
+ def unpack_record(data)
95
+ data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
96
+ end
97
+ end
@@ -0,0 +1,270 @@
1
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
+
3
+ require "test/unit"
4
+ require 'writeexcel'
5
+ require 'stringio'
6
+
7
+ ###############################################################################
8
+ #
9
+ # A test for Spreadsheet::WriteExcel::Chart.
10
+ #
11
+ # Tests for the Excel Chart.pm format conversion methods.
12
+ #
13
+ # reverse('ゥ'), January 2010, John McNamara, jmcnamara@cpan.org
14
+ #
15
+ # original written in Perl by John McNamara
16
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
17
+ #
18
+ class TC_ChartFormats < Test::Unit::TestCase
19
+ def setup
20
+ @io = StringIO.new
21
+ @workbook = WriteExcel.new(@io)
22
+ @chart = @workbook.add_chart(:type => Chart::Column)
23
+ end
24
+
25
+ ###############################################################################
26
+ #
27
+ # Test. User defined colour as string.
28
+ #
29
+ def test_user_defined_color_as_string
30
+ color = 'red'
31
+ caption1 = " \tChart: index = get_color_indices(#{color})"
32
+ caption2 = " \tChart: rgb = get_color_indices(#{color})"
33
+
34
+ expected_index = 0x0A
35
+ expected_rgb = 0x000000FF
36
+
37
+ got_index, got_rgb = @chart.get_color_indices(color)
38
+
39
+ assert_equal(expected_index, got_index, caption1)
40
+ assert_equal(expected_rgb, got_rgb, caption2)
41
+
42
+ color = 'black'
43
+ caption1 = " \tChart: index = get_color_indices(#{color})"
44
+ caption2 = " \tChart: rgb = get_color_indices(#{color})"
45
+
46
+ expected_index = 0x08
47
+ expected_rgb = 0x00000000
48
+
49
+ got_index, got_rgb = @chart.get_color_indices(color)
50
+
51
+ assert_equal(expected_index, got_index, caption1)
52
+ assert_equal(expected_rgb, got_rgb, caption2)
53
+
54
+ color = 'white'
55
+ caption1 = " \tChart: index = get_color_indices(#{color})"
56
+ caption2 = " \tChart: rgb = get_color_indices(#{color})"
57
+
58
+ expected_index = 0x09
59
+ expected_rgb = 0x00FFFFFF
60
+
61
+ got_index, got_rgb = @chart.get_color_indices(color)
62
+
63
+ assert_equal(expected_index, got_index, caption1)
64
+ assert_equal(expected_rgb, got_rgb, caption2)
65
+ end
66
+
67
+ ###############################################################################
68
+ #
69
+ # Test. User defined colour as an index.
70
+ #
71
+ def test_user_defined_color_as_an_index
72
+ color = 0x0A
73
+ caption1 = " \tChart: index = get_color_indices(#{color})"
74
+ caption2 = " \tChart: rgb = get_color_indices(#{color})"
75
+
76
+ expected_index = 0x0A
77
+ expected_rgb = 0x000000FF
78
+
79
+
80
+ got_index, got_rgb = @chart.get_color_indices(color)
81
+
82
+ assert_equal(expected_index, got_index, caption1)
83
+ assert_equal(expected_rgb, got_rgb, caption2)
84
+ end
85
+
86
+ ###############################################################################
87
+ #
88
+ # Test. User defined colour as an out of range index.
89
+ #
90
+ def test_user_defined_color_as_an_out_of_range_index
91
+ color = 7
92
+ caption1 = " \tChart: index = get_color_indices(#{color})"
93
+ caption2 = " \tChart: rgb = get_color_indices(#{color})"
94
+
95
+ expected_index = nil
96
+ expected_rgb = nil
97
+
98
+ got_index, got_rgb = @chart.get_color_indices(color)
99
+
100
+ assert_equal(expected_index, got_index, caption1)
101
+ assert_equal(expected_rgb, got_rgb, caption2)
102
+
103
+ color = 64
104
+ caption1 = " \tChart: index = get_color_indices(#{color})"
105
+ caption2 = " \tChart: rgb = get_color_indices(#{color})"
106
+
107
+ expected_index = nil
108
+ expected_rgb = nil
109
+
110
+ got_index, got_rgb = @chart.get_color_indices(color)
111
+
112
+ assert_equal(expected_index, got_index, caption1)
113
+ assert_equal(expected_rgb, got_rgb, caption2)
114
+ end
115
+
116
+ ###############################################################################
117
+ #
118
+ # Test. User defined colour as an invalid string.
119
+ #
120
+ def test_user_defined_color_as_an_invalid_string
121
+ color = 'plaid'
122
+ caption1 = " \tChart: index = get_color_indices(#{color})"
123
+ caption2 = " \tChart: rgb = get_color_indices(#{color})"
124
+
125
+ expected_index = nil
126
+ expected_rgb = nil
127
+
128
+ got_index, got_rgb = @chart.get_color_indices(color)
129
+
130
+ assert_equal(expected_index, got_index, caption1)
131
+ assert_equal(expected_rgb, got_rgb, caption2)
132
+ end
133
+
134
+ ###############################################################################
135
+ #
136
+ # Test. User defined colour as an undef property.
137
+ #
138
+ def test_user_defined_color_as_an_nil_property
139
+ color = nil
140
+ caption1 = " \tChart: index = get_color_indices(#{color})"
141
+ caption2 = " \tChart: rgb = get_color_indices(#{color})"
142
+
143
+ expected_index = nil
144
+ expected_rgb = nil
145
+
146
+ got_index, got_rgb = @chart.get_color_indices(color)
147
+
148
+ assert_equal(expected_index, got_index, caption1)
149
+ assert_equal(expected_rgb, got_rgb, caption2)
150
+ end
151
+
152
+ ###############################################################################
153
+ #
154
+ # Test. Line patterns with indices.
155
+ #
156
+ def test_line_patterns_with_indices
157
+ caption = " \tChart: pattern = _get_line_pattern()"
158
+
159
+ values = {
160
+ 0 => 5,
161
+ 1 => 0,
162
+ 2 => 1,
163
+ 3 => 2,
164
+ 4 => 3,
165
+ 5 => 4,
166
+ 6 => 7,
167
+ 7 => 6,
168
+ 8 => 8,
169
+ 9 => 0,
170
+ nil => 0
171
+ }
172
+
173
+ expected = []
174
+ got = []
175
+
176
+ values.each do |user, excel|
177
+ got.push(@chart.get_line_pattern(user))
178
+ expected.push(excel)
179
+ end
180
+
181
+ assert_equal(expected, got, caption)
182
+ end
183
+
184
+ ###############################################################################
185
+ #
186
+ # Test. Line patterns with names.
187
+ #
188
+ def test_line_patterns_with_names
189
+ caption = " \tChart: pattern = _get_line_pattern()"
190
+
191
+ values = {
192
+ 'solid' => 0,
193
+ 'dash' => 1,
194
+ 'dot' => 2,
195
+ 'dash-dot' => 3,
196
+ 'dash-dot-dot' => 4,
197
+ 'none' => 5,
198
+ 'dark-gray' => 6,
199
+ 'medium-gray' => 7,
200
+ 'light-gray' => 8,
201
+ 'DASH' => 1,
202
+ 'fictional' => 0
203
+ }
204
+
205
+ expected = []
206
+ got = []
207
+
208
+ values.each do |user, excel|
209
+ got.push(@chart.get_line_pattern(user))
210
+ expected.push(excel)
211
+ end
212
+
213
+ assert_equal(expected, got, caption)
214
+ end
215
+
216
+ ###############################################################################
217
+ #
218
+ # Test. Line weights with indices.
219
+ #
220
+ def test_line_weights_with_indices
221
+ caption = " \tChart: weight = _get_line_weight()"
222
+
223
+ values = {
224
+ 1 => -1,
225
+ 2 => 0,
226
+ 3 => 1,
227
+ 4 => 2,
228
+ 5 => 0,
229
+ 0 => 0,
230
+ nil => 0
231
+ }
232
+
233
+ expected = []
234
+ got = []
235
+
236
+ values.each do |user, excel|
237
+ got.push(@chart.get_line_weight(user))
238
+ expected.push(excel)
239
+ end
240
+
241
+ assert_equal(expected, got, caption)
242
+ end
243
+
244
+ ###############################################################################
245
+ #
246
+ # Test. Line weights with names.
247
+ #
248
+ def test_line_weights_with_names
249
+ caption = " \tChart: weight = _get_line_weight()"
250
+
251
+ values = {
252
+ 'hairline' => -1,
253
+ 'narrow' => 0,
254
+ 'medium' => 1,
255
+ 'wide' => 2,
256
+ 'WIDE' => 2,
257
+ 'Fictional' => 0,
258
+ }
259
+
260
+ expected = []
261
+ got = []
262
+
263
+ values.each do |user, excel|
264
+ got.push(@chart.get_line_weight(user))
265
+ expected.push(excel)
266
+ end
267
+
268
+ assert_equal(expected, got, caption)
269
+ end
270
+ end
@@ -0,0 +1,647 @@
1
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
+
3
+ require "test/unit"
4
+ require 'writeexcel'
5
+ require 'stringio'
6
+
7
+ ###############################################################################
8
+ #
9
+ # A test for Spreadsheet::WriteExcel::Chart.
10
+ #
11
+ # Tests for the Excel Chart.pm format conversion methods.
12
+ #
13
+ # reverse('ゥ'), January 2010, John McNamara, jmcnamara@cpan.org
14
+ #
15
+ # original written in Perl by John McNamara
16
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
17
+ #
18
+ class TC_ChartAreaFormats < Test::Unit::TestCase
19
+ def setup
20
+ @io = StringIO.new
21
+ @workbook = WriteExcel.new(@io)
22
+ @chart = @workbook.add_chart(:type => Chart::Column)
23
+ @chart.using_tmpfile = false
24
+ @caption1 = " \tChart: chartarea format - line";
25
+ @caption2 = " \tChart: chartarea format - area";
26
+ @embed_caption1 = " \tChart: embedded chartarea format - line";
27
+ @embed_caption2 = " \tChart: embedded chartarea format - area";
28
+ @plotarea_caption1 = " \tChart: plotarea format - line";
29
+ @plotarea_caption2 = " \tChart: plotarea format - area";
30
+ end
31
+
32
+ ###############################################################################
33
+ #
34
+ # 1. Test the chartarea format methods. See the set_*area() properties below.
35
+ #
36
+ def test_the_chartarea_format_methods
37
+ reset_chart(@chart)
38
+
39
+ @chart.set_chartarea(
40
+ :color => 'red',
41
+ :line_color => 'black',
42
+ :line_pattern => 2,
43
+ :line_weight => 3
44
+ )
45
+
46
+ expected_line = %w(
47
+ 07 10 0C 00 00 00 00 00 01 00 01 00 00 00 08 00
48
+ ).join(' ')
49
+
50
+ expected_area = %w(
51
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
52
+ 0A 00 08 00
53
+ ).join(' ')
54
+
55
+ got_line, got_area = get_chartarea_formats(@chart)
56
+
57
+ assert_equal(expected_line, got_line, @caption1)
58
+ assert_equal(expected_area, got_area, @caption2)
59
+
60
+
61
+ reset_chart(@chart)
62
+
63
+ @chart.set_chartarea(
64
+ :color => 'red'
65
+ )
66
+
67
+ expected_line = %w(
68
+ 07 10 0C 00 00 00 00 00 05 00 FF FF 08 00 4D 00
69
+ ).join(' ')
70
+
71
+ expected_area = %w(
72
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
73
+ 0A 00 08 00
74
+ ).join(' ')
75
+
76
+ got_line, got_area = get_chartarea_formats(@chart)
77
+
78
+ assert_equal(expected_line, got_line, @caption1)
79
+ assert_equal(expected_area, got_area, @caption2)
80
+
81
+
82
+ reset_chart(@chart)
83
+
84
+ @chart.set_chartarea(
85
+ :line_color => 'red'
86
+ )
87
+
88
+ expected_line = %w(
89
+ 07 10 0C 00 FF 00 00 00 00 00 FF FF 00 00 0A 00
90
+ ).join(' ')
91
+
92
+ expected_area = %w(
93
+ 0A 10 10 00 FF FF FF 00 00 00 00 00 00 00 00 00
94
+ 4E 00 4D 00
95
+ ).join(' ')
96
+
97
+ got_line, got_area = get_chartarea_formats(@chart)
98
+
99
+ assert_equal(expected_line, got_line, @caption1)
100
+ assert_equal(expected_area, got_area, @caption2)
101
+
102
+
103
+ reset_chart(@chart)
104
+
105
+ @chart.set_chartarea(
106
+ :line_pattern => 2
107
+ )
108
+
109
+ expected_line = %w(
110
+ 07 10 0C 00 00 00 00 00 01 00 FF FF 00 00 4F 00
111
+ ).join(' ')
112
+
113
+ expected_area = %w(
114
+ 0A 10 10 00 FF FF FF 00 00 00 00 00 00 00 00 00
115
+ 4E 00 4D 00
116
+ ).join(' ')
117
+
118
+ got_line, got_area = get_chartarea_formats(@chart)
119
+
120
+ assert_equal(expected_line, got_line, @caption1)
121
+ assert_equal(expected_area, got_area, @caption2)
122
+
123
+
124
+ reset_chart(@chart)
125
+
126
+ @chart.set_chartarea(
127
+ :line_weight => 3
128
+ )
129
+
130
+ expected_line = %w(
131
+ 07 10 0C 00 00 00 00 00 00 00 01 00 00 00 4F 00
132
+ ).join(' ')
133
+
134
+ expected_area = %w(
135
+ 0A 10 10 00 FF FF FF 00 00 00 00 00 00 00 00 00
136
+ 4E 00 4D 00
137
+ ).join(' ')
138
+
139
+ got_line, got_area = get_chartarea_formats(@chart)
140
+
141
+ assert_equal(expected_line, got_line, @caption1)
142
+ assert_equal(expected_area, got_area, @caption2)
143
+
144
+
145
+ reset_chart(@chart)
146
+
147
+ @chart.set_chartarea(
148
+ :color => 'red',
149
+ :line_color => 'black'
150
+ )
151
+
152
+ expected_line = %w(
153
+ 07 10 0C 00 00 00 00 00 00 00 FF FF 00 00 08 00
154
+ ).join(' ')
155
+
156
+ expected_area = %w(
157
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
158
+ 0A 00 08 00
159
+ ).join(' ')
160
+
161
+ got_line, got_area = get_chartarea_formats(@chart)
162
+
163
+ assert_equal(expected_line, got_line, @caption1)
164
+ assert_equal(expected_area, got_area, @caption2)
165
+
166
+
167
+ reset_chart(@chart)
168
+
169
+ @chart.set_chartarea(
170
+ :color => 'red',
171
+ :line_pattern => 2
172
+ )
173
+
174
+ expected_line = %w(
175
+ 07 10 0C 00 00 00 00 00 01 00 FF FF 00 00 4F 00
176
+ ).join(' ')
177
+
178
+ expected_area = %w(
179
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
180
+ 0A 00 08 00
181
+ ).join(' ')
182
+
183
+ got_line, got_area = get_chartarea_formats(@chart)
184
+
185
+ assert_equal(expected_line, got_line, @caption1)
186
+ assert_equal(expected_area, got_area, @caption2)
187
+
188
+
189
+ reset_chart(@chart)
190
+
191
+ @chart.set_chartarea(
192
+ :color => 'red',
193
+ :line_weight => 3
194
+ )
195
+
196
+ expected_line = %w(
197
+ 07 10 0C 00 00 00 00 00 00 00 01 00 00 00 4F 00
198
+ ).join(' ')
199
+
200
+ expected_area = %w(
201
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
202
+ 0A 00 08 00
203
+ ).join(' ')
204
+
205
+ got_line, got_area = get_chartarea_formats(@chart)
206
+
207
+ assert_equal(expected_line, got_line, @caption1)
208
+ assert_equal(expected_area, got_area, @caption2)
209
+
210
+
211
+ @chart.embedded = true
212
+
213
+ reset_chart(@chart, true)
214
+
215
+ @chart.set_chartarea(
216
+ )
217
+
218
+ expected_line = %w(
219
+ 07 10 0C 00 00 00 00 00 00 00 00 00 09 00 4D 00
220
+ ).join(' ')
221
+
222
+ expected_area = %w(
223
+ 0A 10 10 00 FF FF FF 00 00 00 00 00 01 00 01 00
224
+ 4E 00 4D 00
225
+ ).join(' ')
226
+
227
+ got_line, got_area = get_chartarea_formats(@chart)
228
+
229
+ assert_equal(expected_line, got_line, @embed_caption1)
230
+ assert_equal(expected_area, got_area, @embed_caption2)
231
+
232
+
233
+ reset_chart(@chart, true)
234
+
235
+ @chart.set_chartarea(
236
+ :color => 'red',
237
+ :line_color => 'black',
238
+ :line_pattern => 2,
239
+ :line_weight => 3
240
+ )
241
+
242
+ expected_line = %w(
243
+ 07 10 0C 00 00 00 00 00 01 00 01 00 00 00 08 00
244
+ ).join(' ')
245
+
246
+ expected_area = %w(
247
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
248
+ 0A 00 08 00
249
+ ).join(' ')
250
+
251
+ got_line, got_area = get_chartarea_formats(@chart)
252
+
253
+ assert_equal(expected_line, got_line, @embed_caption1)
254
+ assert_equal(expected_area, got_area, @embed_caption2)
255
+
256
+
257
+ reset_chart(@chart, true)
258
+
259
+ @chart.set_chartarea(
260
+ :color => 'red'
261
+ )
262
+
263
+ expected_line = %w(
264
+ 07 10 0C 00 00 00 00 00 00 00 FF FF 09 00 4D 00
265
+ ).join(' ')
266
+
267
+ expected_area = %w(
268
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
269
+ 0A 00 08 00
270
+ ).join(' ')
271
+
272
+ got_line, got_area = get_chartarea_formats(@chart)
273
+
274
+ assert_equal(expected_line, got_line, @embed_caption1)
275
+ assert_equal(expected_area, got_area, @embed_caption2)
276
+
277
+
278
+ reset_chart(@chart, true)
279
+
280
+ @chart.set_chartarea(
281
+ :line_color => 'red'
282
+ )
283
+
284
+ expected_line = %w(
285
+ 07 10 0C 00 FF 00 00 00 00 00 FF FF 00 00 0A 00
286
+ ).join(' ')
287
+
288
+ expected_area = %w(
289
+ 0A 10 10 00 FF FF FF 00 00 00 00 00 01 00 01 00
290
+ 4E 00 4D 00
291
+ ).join(' ')
292
+
293
+ got_line, got_area = get_chartarea_formats(@chart)
294
+
295
+ assert_equal(expected_line, got_line, @embed_caption1)
296
+ assert_equal(expected_area, got_area, @embed_caption2)
297
+
298
+
299
+ reset_chart(@chart, true)
300
+
301
+ @chart.set_chartarea(
302
+ :line_pattern => 2
303
+ )
304
+
305
+ expected_line = %w(
306
+ 07 10 0C 00 00 00 00 00 01 00 FF FF 00 00 4F 00
307
+ ).join(' ')
308
+
309
+ expected_area = %w(
310
+ 0A 10 10 00 FF FF FF 00 00 00 00 00 01 00 01 00
311
+ 4E 00 4D 00
312
+ ).join(' ')
313
+
314
+ got_line, got_area = get_chartarea_formats(@chart)
315
+
316
+ assert_equal(expected_line, got_line, @embed_caption1)
317
+ assert_equal(expected_area, got_area, @embed_caption2)
318
+
319
+
320
+ reset_chart(@chart, true)
321
+
322
+ @chart.set_chartarea(
323
+ :line_weight => 3
324
+ )
325
+
326
+ expected_line = %w(
327
+ 07 10 0C 00 00 00 00 00 00 00 01 00 00 00 4F 00
328
+ ).join(' ')
329
+
330
+ expected_area = %w(
331
+ 0A 10 10 00 FF FF FF 00 00 00 00 00 01 00 01 00
332
+ 4E 00 4D 00
333
+ ).join(' ')
334
+
335
+ got_line, got_area = get_chartarea_formats(@chart)
336
+
337
+ assert_equal(expected_line, got_line, @embed_caption1)
338
+ assert_equal(expected_area, got_area, @embed_caption2)
339
+
340
+
341
+ reset_chart(@chart, true)
342
+
343
+ @chart.set_chartarea(
344
+ :color => 'red',
345
+ :line_color => 'black'
346
+ )
347
+
348
+ expected_line = %w(
349
+ 07 10 0C 00 00 00 00 00 00 00 FF FF 00 00 08 00
350
+ ).join(' ')
351
+
352
+ expected_area = %w(
353
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
354
+ 0A 00 08 00
355
+ ).join(' ')
356
+
357
+ got_line, got_area = get_chartarea_formats(@chart)
358
+
359
+ assert_equal(expected_line, got_line, @embed_caption1)
360
+ assert_equal(expected_area, got_area, @embed_caption2)
361
+
362
+
363
+ reset_chart(@chart, true)
364
+
365
+ @chart.set_chartarea(
366
+ :color => 'red',
367
+ :line_pattern => 2
368
+ )
369
+
370
+ expected_line = %w(
371
+ 07 10 0C 00 00 00 00 00 01 00 FF FF 00 00 4F 00
372
+ ).join(' ')
373
+
374
+ expected_area = %w(
375
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
376
+ 0A 00 08 00
377
+ ).join(' ')
378
+
379
+ got_line, got_area = get_chartarea_formats(@chart)
380
+
381
+ assert_equal(expected_line, got_line, @embed_caption1)
382
+ assert_equal(expected_area, got_area, @embed_caption2)
383
+
384
+
385
+ reset_chart(@chart, true)
386
+
387
+ @chart.set_chartarea(
388
+ :color => 'red',
389
+ :line_weight => 3
390
+ )
391
+
392
+ expected_line = %w(
393
+ 07 10 0C 00 00 00 00 00 00 00 01 00 00 00 4F 00
394
+ ).join(' ')
395
+
396
+ expected_area = %w(
397
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
398
+ 0A 00 08 00
399
+ ).join(' ')
400
+
401
+ got_line, got_area = get_chartarea_formats(@chart)
402
+
403
+ assert_equal(expected_line, got_line, @embed_caption1)
404
+ assert_equal(expected_area, got_area, @embed_caption2)
405
+
406
+
407
+ @chart.embedded = false
408
+
409
+ reset_chart(@chart)
410
+
411
+ @chart.set_plotarea(
412
+ )
413
+
414
+ expected_line = %w(
415
+ 07 10 0C 00 80 80 80 00 00 00 00 00 00 00 17 00
416
+ ).join(' ')
417
+
418
+ expected_area = %w(
419
+ 0A 10 10 00 C0 C0 C0 00 00 00 00 00 01 00 00 00
420
+ 16 00 4F 00
421
+ ).join(' ')
422
+
423
+ got_line, got_area = get_plotarea_formats(@chart)
424
+
425
+ assert_equal(expected_line, got_line, @plotarea_caption1)
426
+ assert_equal(expected_area, got_area, @plotarea_caption2)
427
+
428
+
429
+ reset_chart(@chart)
430
+
431
+ @chart.set_plotarea(
432
+ :color => 'red',
433
+ :line_color => 'black',
434
+ :line_pattern => 2,
435
+ :line_weight => 3
436
+ )
437
+
438
+ expected_line = %w(
439
+ 07 10 0C 00 00 00 00 00 01 00 01 00 00 00 08 00
440
+ ).join(' ')
441
+
442
+ expected_area = %w(
443
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
444
+ 0A 00 08 00
445
+ ).join(' ')
446
+
447
+ got_line, got_area = get_plotarea_formats(@chart)
448
+
449
+ assert_equal(expected_line, got_line, @plotarea_caption1)
450
+ assert_equal(expected_area, got_area, @plotarea_caption2)
451
+
452
+
453
+ reset_chart(@chart)
454
+
455
+ @chart.set_plotarea(
456
+ :color => 'red'
457
+ )
458
+
459
+ expected_line = %w(
460
+ 07 10 0C 00 80 80 80 00 00 00 00 00 00 00 17 00
461
+ ).join(' ')
462
+
463
+ expected_area = %w(
464
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
465
+ 0A 00 08 00
466
+ ).join(' ')
467
+
468
+ got_line, got_area = get_plotarea_formats(@chart)
469
+
470
+ assert_equal(expected_line, got_line, @plotarea_caption1)
471
+ assert_equal(expected_area, got_area, @plotarea_caption2)
472
+
473
+
474
+ reset_chart(@chart)
475
+
476
+ @chart.set_plotarea(
477
+ :line_color => 'red'
478
+ )
479
+
480
+ expected_line = %w(
481
+ 07 10 0C 00 FF 00 00 00 00 00 00 00 00 00 0A 00
482
+ ).join(' ')
483
+
484
+ expected_area = %w(
485
+ 0A 10 10 00 C0 C0 C0 00 00 00 00 00 01 00 00 00
486
+ 16 00 08 00
487
+ ).join(' ')
488
+
489
+ got_line, got_area = get_plotarea_formats(@chart)
490
+
491
+ assert_equal(expected_line, got_line, @plotarea_caption1)
492
+ assert_equal(expected_area, got_area, @plotarea_caption2)
493
+
494
+
495
+ reset_chart(@chart)
496
+
497
+ @chart.set_plotarea(
498
+ :line_pattern => 2
499
+ )
500
+
501
+ expected_line = %w(
502
+ 07 10 0C 00 80 80 80 00 01 00 00 00 00 00 17 00
503
+ ).join(' ')
504
+
505
+ expected_area = %w(
506
+ 0A 10 10 00 C0 C0 C0 00 00 00 00 00 01 00 00 00
507
+ 16 00 08 00
508
+ ).join(' ')
509
+
510
+ got_line, got_area = get_plotarea_formats(@chart)
511
+
512
+ assert_equal(expected_line, got_line, @plotarea_caption1)
513
+ assert_equal(expected_area, got_area, @plotarea_caption2)
514
+
515
+
516
+ reset_chart(@chart)
517
+
518
+ @chart.set_plotarea(
519
+ :line_weight => 3
520
+ )
521
+
522
+ expected_line = %w(
523
+ 07 10 0C 00 80 80 80 00 00 00 01 00 00 00 17 00
524
+ ).join(' ')
525
+
526
+ expected_area = %w(
527
+ 0A 10 10 00 C0 C0 C0 00 00 00 00 00 01 00 00 00
528
+ 16 00 08 00
529
+ ).join(' ')
530
+
531
+ got_line, got_area = get_plotarea_formats(@chart)
532
+
533
+ assert_equal(expected_line, got_line, @plotarea_caption1)
534
+ assert_equal(expected_area, got_area, @plotarea_caption2)
535
+
536
+
537
+ reset_chart(@chart)
538
+
539
+ @chart.set_plotarea(
540
+ :color => 'red',
541
+ :line_color => 'black'
542
+ )
543
+
544
+ expected_line = %w(
545
+ 07 10 0C 00 00 00 00 00 00 00 00 00 00 00 08 00
546
+ ).join(' ')
547
+
548
+ expected_area = %w(
549
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
550
+ 0A 00 08 00
551
+ ).join(' ')
552
+
553
+ got_line, got_area = get_plotarea_formats(@chart)
554
+
555
+ assert_equal(expected_line, got_line, @plotarea_caption1)
556
+ assert_equal(expected_area, got_area, @plotarea_caption2)
557
+
558
+
559
+ reset_chart(@chart)
560
+
561
+ @chart.set_plotarea(
562
+ :color => 'red',
563
+ :line_pattern => 2
564
+ )
565
+
566
+ expected_line = %w(
567
+ 07 10 0C 00 80 80 80 00 01 00 00 00 00 00 17 00
568
+ ).join(' ')
569
+
570
+ expected_area = %w(
571
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
572
+ 0A 00 08 00
573
+ ).join(' ')
574
+
575
+ got_line, got_area = get_plotarea_formats(@chart)
576
+
577
+ assert_equal(expected_line, got_line, @plotarea_caption1)
578
+ assert_equal(expected_area, got_area, @plotarea_caption2)
579
+
580
+
581
+ reset_chart(@chart)
582
+
583
+ @chart.set_plotarea(
584
+ :color => 'red',
585
+ :line_weight => 3
586
+ )
587
+
588
+ expected_line = %w(
589
+ 07 10 0C 00 80 80 80 00 00 00 01 00 00 00 17 00
590
+ ).join(' ')
591
+
592
+ expected_area = %w(
593
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
594
+ 0A 00 08 00
595
+ ).join(' ')
596
+
597
+ got_line, got_area = get_plotarea_formats(@chart)
598
+
599
+ assert_equal(expected_line, got_line, @plotarea_caption1)
600
+ assert_equal(expected_area, got_area, @plotarea_caption2)
601
+ end
602
+
603
+
604
+ ###############################################################################
605
+ #
606
+ # Reset the chart data for testing.
607
+ #
608
+ def reset_chart(chart, embedded = nil)
609
+ # Reset the chart data.
610
+ chart.data = ''
611
+ chart.set_default_properties
612
+
613
+ if embedded
614
+ chart.set_embedded_config_data
615
+ end
616
+ end
617
+
618
+ ###############################################################################
619
+ #
620
+ # Extract Line and Area format records from the Chartarea Frame stream.
621
+ #
622
+ def get_chartarea_formats(chart)
623
+ chart.store_chartarea_frame_stream
624
+
625
+ line = unpack_record(chart.data[12, 16])
626
+ area = unpack_record(chart.data[28, 20])
627
+
628
+ [line, area]
629
+ end
630
+
631
+ ###############################################################################
632
+ #
633
+ # Extract Line and Area format records from the Chartarea Frame stream.
634
+ #
635
+ def get_plotarea_formats(chart)
636
+ chart.store_plotarea_frame_stream
637
+
638
+ line = unpack_record(chart.data[12, 16])
639
+ area = unpack_record(chart.data[28, 20])
640
+
641
+ [line, area]
642
+ end
643
+
644
+ def unpack_record(data)
645
+ data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
646
+ end
647
+ end