writeexcel 0.3.5 → 0.4.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 (122) hide show
  1. data/.gitattributes +1 -0
  2. data/README.rdoc +12 -6
  3. data/VERSION +1 -1
  4. data/charts/chartex.rb +316 -315
  5. data/charts/demo1.rb +1 -0
  6. data/charts/demo2.rb +1 -0
  7. data/charts/demo3.rb +117 -116
  8. data/charts/demo4.rb +119 -118
  9. data/charts/demo5.rb +48 -47
  10. data/examples/a_simple.rb +1 -0
  11. data/examples/autofilter.rb +1 -0
  12. data/examples/bigfile.rb +30 -29
  13. data/examples/chart_area.rb +121 -120
  14. data/examples/chart_bar.rb +120 -119
  15. data/examples/chart_column.rb +120 -119
  16. data/examples/chart_line.rb +120 -119
  17. data/examples/chart_pie.rb +108 -107
  18. data/examples/chart_scatter.rb +121 -120
  19. data/examples/chart_stock.rb +148 -147
  20. data/examples/chess.rb +1 -0
  21. data/examples/colors.rb +1 -0
  22. data/examples/comments1.rb +1 -0
  23. data/examples/comments2.rb +3 -2
  24. data/examples/copyformat.rb +1 -0
  25. data/examples/data_validate.rb +1 -0
  26. data/examples/date_time.rb +1 -0
  27. data/examples/defined_name.rb +1 -0
  28. data/examples/demo.rb +1 -0
  29. data/examples/diag_border.rb +1 -0
  30. data/examples/formats.rb +1 -0
  31. data/examples/formula_result.rb +1 -0
  32. data/examples/header.rb +1 -0
  33. data/examples/hide_sheet.rb +1 -0
  34. data/examples/hyperlink.rb +1 -0
  35. data/examples/images.rb +1 -0
  36. data/examples/indent.rb +1 -0
  37. data/examples/merge1.rb +1 -0
  38. data/examples/merge2.rb +1 -0
  39. data/examples/merge3.rb +1 -0
  40. data/examples/merge4.rb +1 -0
  41. data/examples/merge5.rb +1 -0
  42. data/examples/merge6.rb +67 -66
  43. data/examples/outline.rb +1 -0
  44. data/examples/outline_collapsed.rb +1 -0
  45. data/examples/panes.rb +1 -0
  46. data/examples/properties.rb +1 -0
  47. data/examples/properties_jp.rb +1 -0
  48. data/examples/protection.rb +1 -0
  49. data/examples/regions.rb +1 -0
  50. data/examples/repeat.rb +1 -0
  51. data/examples/right_to_left.rb +1 -0
  52. data/examples/row_wrap.rb +1 -0
  53. data/examples/stats.rb +1 -0
  54. data/examples/stocks.rb +1 -0
  55. data/examples/tab_colors.rb +1 -0
  56. data/examples/write_arrays.rb +1 -0
  57. data/lib/writeexcel.rb +6 -1
  58. data/lib/writeexcel/biffwriter.rb +21 -20
  59. data/lib/writeexcel/chart.rb +25 -12
  60. data/lib/writeexcel/charts/area.rb +153 -152
  61. data/lib/writeexcel/charts/bar.rb +178 -177
  62. data/lib/writeexcel/charts/column.rb +157 -156
  63. data/lib/writeexcel/charts/external.rb +62 -61
  64. data/lib/writeexcel/charts/line.rb +153 -152
  65. data/lib/writeexcel/charts/pie.rb +170 -169
  66. data/lib/writeexcel/charts/scatter.rb +4 -3
  67. data/lib/writeexcel/charts/stock.rb +212 -211
  68. data/lib/writeexcel/compatibility.rb +320 -0
  69. data/lib/writeexcel/excelformulaparser.rb +587 -586
  70. data/lib/writeexcel/format.rb +12 -13
  71. data/lib/writeexcel/formula.rb +30 -28
  72. data/lib/writeexcel/helper.rb +23 -0
  73. data/lib/writeexcel/olewriter.rb +5 -16
  74. data/lib/writeexcel/properties.rb +43 -54
  75. data/lib/writeexcel/storage_lite.rb +981 -968
  76. data/lib/writeexcel/workbook.rb +94 -73
  77. data/lib/writeexcel/worksheet.rb +230 -210
  78. data/test/helper.rb +19 -0
  79. data/test/test_00_IEEE_double.rb +1 -0
  80. data/test/test_01_add_worksheet.rb +1 -0
  81. data/test/test_02_merge_formats.rb +3 -5
  82. data/test/test_04_dimensions.rb +3 -5
  83. data/test/test_05_rows.rb +6 -6
  84. data/test/test_06_extsst.rb +8 -8
  85. data/test/test_11_date_time.rb +3 -5
  86. data/test/test_12_date_only.rb +3 -5
  87. data/test/test_13_date_seconds.rb +4 -6
  88. data/test/test_21_escher.rb +3 -5
  89. data/test/test_22_mso_drawing_group.rb +20 -22
  90. data/test/test_23_note.rb +5 -7
  91. data/test/test_24_txo.rb +3 -5
  92. data/test/test_25_position_object.rb +84 -79
  93. data/test/test_26_autofilter.rb +3 -13
  94. data/test/test_27_autofilter.rb +3 -13
  95. data/test/test_28_autofilter.rb +3 -13
  96. data/test/test_29_process_jpg.rb +5 -0
  97. data/test/test_30_validation_dval.rb +3 -5
  98. data/test/test_31_validation_dv_strings.rb +3 -5
  99. data/test/test_32_validation_dv_formula.rb +3 -5
  100. data/test/test_40_property_types.rb +10 -9
  101. data/test/test_41_properties.rb +1 -0
  102. data/test/test_42_set_properties.rb +14 -15
  103. data/test/test_50_name_stored.rb +299 -302
  104. data/test/test_51_name_print_area.rb +357 -360
  105. data/test/test_52_name_print_titles.rb +454 -457
  106. data/test/test_53_autofilter.rb +203 -206
  107. data/test/test_60_chart_generic.rb +5 -0
  108. data/test/test_61_chart_subclasses.rb +95 -94
  109. data/test/test_62_chart_formats.rb +272 -267
  110. data/test/test_63_chart_area_formats.rb +649 -644
  111. data/test/test_biff.rb +12 -38
  112. data/test/test_compatibility.rb +627 -0
  113. data/test/test_example_match.rb +3 -18
  114. data/test/test_format.rb +46 -105
  115. data/test/test_formula.rb +1 -0
  116. data/test/test_ole.rb +3 -4
  117. data/test/test_storage_lite.rb +125 -146
  118. data/test/test_workbook.rb +2 -23
  119. data/test/test_worksheet.rb +4 -5
  120. data/utils/add_magic_comment.rb +80 -0
  121. data/writeexcel.gemspec +8 -2
  122. metadata +10 -4
@@ -1,169 +1,170 @@
1
- ###############################################################################
2
- #
3
- # Pie - A writer class for Excel Pie charts.
4
- #
5
- # Used in conjunction with Spreadsheet::WriteExcel::Chart.
6
- #
7
- # See formatting note in Spreadsheet::WriteExcel::Chart.
8
- #
9
- # Copyright 2000-2010, John McNamara, jmcnamara@cpan.org
10
- #
11
- # original written in Perl by John McNamara
12
- # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
13
- #
14
-
15
- require 'writeexcel'
16
-
17
- class Chart
18
-
19
- # ==SYNOPSIS
20
- #
21
- # To create a simple Excel file with a Pie chart using WriteExcel:
22
- #
23
- # #!/usr/bin/ruby -w
24
- #
25
- # require 'writeexcel'
26
- #
27
- # workbook = Spreadsheet::WriteExcel.new('chart.xls')
28
- # worksheet = workbook.add_worksheet
29
- #
30
- # chart = workbook.add_chart(:type => Chart::Pie)
31
- #
32
- # # Configure the chart.
33
- # chart.add_series(
34
- # :categories => '=Sheet1!$A$2:$A$7',
35
- # :values => '=Sheet1!$B$2:$B$7'
36
- # )
37
- #
38
- # # Add the worksheet data the chart refers to.
39
- # data = [
40
- # [ 'Category', 2, 3, 4, 5, 6, 7 ],
41
- # [ 'Value', 1, 4, 5, 2, 1, 5 ]
42
- # ]
43
- #
44
- # worksheet.write('A1', data)
45
- #
46
- # workbook.close
47
- #
48
- # ==DESCRIPTION
49
- #
50
- # This module implements Pie charts for Spreadsheet::WriteExcel. The chart
51
- # object is created via the Workbook add_chart() method:
52
- #
53
- # chart = workbook.add_chart(:type => Chart::Pie)
54
- #
55
- # Once the object is created it can be configured via the following methods
56
- # that are common to all chart classes:
57
- #
58
- # chart.add_series
59
- # chart.set_title
60
- #
61
- # These methods are explained in detail in Chart section of WriteExcel.
62
- # Class specific methods or settings, if any, are explained below.
63
- #
64
- # ==Pie Chart Methods
65
- #
66
- # There aren't currently any pie chart specific methods. See the TODO
67
- # section of Chart section in WriteExcel.
68
- #
69
- # A Pie chart doesn't have an X or Y axis so the following common chart
70
- # methods are ignored.
71
- #
72
- # chart.set_x_axis
73
- # chart.set_y_axis
74
- #
75
- # ==EXAMPLE
76
- #
77
- # Here is a complete example that demonstrates most of the available
78
- # features when creating a chart.
79
- #
80
- # #!/usr/bin/ruby -w
81
- #
82
- # require 'writeexcel'
83
- #
84
- # workbook = Spreadsheet::WriteExcel.new('chart_pie.xls')
85
- # worksheet = workbook.add_worksheet
86
- # bold = workbook.add_format(:bold => 1)
87
- #
88
- # # Add the worksheet data that the charts will refer to.
89
- # headings = [ 'Category', 'Values' ]
90
- # data = [
91
- # [ 'Apple', 'Cherry', 'Pecan' ],
92
- # [ 60, 30, 10 ],
93
- # ]
94
- #
95
- # worksheet.write('A1', headings, bold)
96
- # worksheet.write('A2', data)
97
- #
98
- # # Create a new chart object. In this case an embedded chart.
99
- # chart = workbook.add_chart(:type => Chart::Pie, :embedded => 1)
100
- #
101
- # # Configure the series.
102
- # chart.add_series(
103
- # :name => 'Pie sales data',
104
- # :categories => '=Sheet1!$A$2:$A$4',
105
- # :values => '=Sheet1!$B$2:$B$4',
106
- # )
107
- #
108
- # # Add a title.
109
- # chart.set_title(name => 'Popular Pie Types')
110
- #
111
- #
112
- # # Insert the chart into the worksheet (with an offset).
113
- # worksheet.insert_chart('C2', chart, 25, 10)
114
- #
115
- # workbook.close
116
- #
117
- class Pie < Chart
118
- ###############################################################################
119
- #
120
- # new()
121
- #
122
- #
123
- def initialize(*args) # :nodoc:
124
- super
125
- @vary_data_color = 1
126
- end
127
-
128
- ###############################################################################
129
- #
130
- # _store_chart_type()
131
- #
132
- # Implementation of the abstract method from the specific chart class.
133
- #
134
- # Write the Pie chart BIFF record.
135
- #
136
- def store_chart_type # :nodoc:
137
- record = 0x1019 # Record identifier.
138
- length = 0x0006 # Number of bytes to follow.
139
- angle = 0x0000 # Angle.
140
- donut = 0x0000 # Donut hole size.
141
- grbit = 0x0002 # Option flags.
142
-
143
- header = [record, length].pack('vv')
144
- data = [angle].pack('v')
145
- data += [donut].pack('v')
146
- data += [grbit].pack('v')
147
-
148
- append(header, data)
149
- end
150
-
151
- ###############################################################################
152
- #
153
- # _store_axisparent_stream(). Overridden.
154
- #
155
- # Write the AXISPARENT chart substream.
156
- #
157
- # A Pie chart has no X or Y axis so we override this method to remove them.
158
- #
159
- def store_axisparent_stream # :nodoc:
160
- store_axisparent(*@config[:axisparent])
161
-
162
- store_begin
163
- store_pos(*@config[:axisparent_pos])
164
-
165
- store_chartformat_stream
166
- store_end
167
- end
168
- end
169
- end
1
+ # -*- coding: utf-8 -*-
2
+ ###############################################################################
3
+ #
4
+ # Pie - A writer class for Excel Pie charts.
5
+ #
6
+ # Used in conjunction with Spreadsheet::WriteExcel::Chart.
7
+ #
8
+ # See formatting note in Spreadsheet::WriteExcel::Chart.
9
+ #
10
+ # Copyright 2000-2010, John McNamara, jmcnamara@cpan.org
11
+ #
12
+ # original written in Perl by John McNamara
13
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
14
+ #
15
+
16
+ require 'writeexcel'
17
+
18
+ class Chart
19
+
20
+ # ==SYNOPSIS
21
+ #
22
+ # To create a simple Excel file with a Pie chart using WriteExcel:
23
+ #
24
+ # #!/usr/bin/ruby -w
25
+ #
26
+ # require 'writeexcel'
27
+ #
28
+ # workbook = Spreadsheet::WriteExcel.new('chart.xls')
29
+ # worksheet = workbook.add_worksheet
30
+ #
31
+ # chart = workbook.add_chart(:type => Chart::Pie)
32
+ #
33
+ # # Configure the chart.
34
+ # chart.add_series(
35
+ # :categories => '=Sheet1!$A$2:$A$7',
36
+ # :values => '=Sheet1!$B$2:$B$7'
37
+ # )
38
+ #
39
+ # # Add the worksheet data the chart refers to.
40
+ # data = [
41
+ # [ 'Category', 2, 3, 4, 5, 6, 7 ],
42
+ # [ 'Value', 1, 4, 5, 2, 1, 5 ]
43
+ # ]
44
+ #
45
+ # worksheet.write('A1', data)
46
+ #
47
+ # workbook.close
48
+ #
49
+ # ==DESCRIPTION
50
+ #
51
+ # This module implements Pie charts for Spreadsheet::WriteExcel. The chart
52
+ # object is created via the Workbook add_chart() method:
53
+ #
54
+ # chart = workbook.add_chart(:type => Chart::Pie)
55
+ #
56
+ # Once the object is created it can be configured via the following methods
57
+ # that are common to all chart classes:
58
+ #
59
+ # chart.add_series
60
+ # chart.set_title
61
+ #
62
+ # These methods are explained in detail in Chart section of WriteExcel.
63
+ # Class specific methods or settings, if any, are explained below.
64
+ #
65
+ # ==Pie Chart Methods
66
+ #
67
+ # There aren't currently any pie chart specific methods. See the TODO
68
+ # section of Chart section in WriteExcel.
69
+ #
70
+ # A Pie chart doesn't have an X or Y axis so the following common chart
71
+ # methods are ignored.
72
+ #
73
+ # chart.set_x_axis
74
+ # chart.set_y_axis
75
+ #
76
+ # ==EXAMPLE
77
+ #
78
+ # Here is a complete example that demonstrates most of the available
79
+ # features when creating a chart.
80
+ #
81
+ # #!/usr/bin/ruby -w
82
+ #
83
+ # require 'writeexcel'
84
+ #
85
+ # workbook = Spreadsheet::WriteExcel.new('chart_pie.xls')
86
+ # worksheet = workbook.add_worksheet
87
+ # bold = workbook.add_format(:bold => 1)
88
+ #
89
+ # # Add the worksheet data that the charts will refer to.
90
+ # headings = [ 'Category', 'Values' ]
91
+ # data = [
92
+ # [ 'Apple', 'Cherry', 'Pecan' ],
93
+ # [ 60, 30, 10 ],
94
+ # ]
95
+ #
96
+ # worksheet.write('A1', headings, bold)
97
+ # worksheet.write('A2', data)
98
+ #
99
+ # # Create a new chart object. In this case an embedded chart.
100
+ # chart = workbook.add_chart(:type => Chart::Pie, :embedded => 1)
101
+ #
102
+ # # Configure the series.
103
+ # chart.add_series(
104
+ # :name => 'Pie sales data',
105
+ # :categories => '=Sheet1!$A$2:$A$4',
106
+ # :values => '=Sheet1!$B$2:$B$4',
107
+ # )
108
+ #
109
+ # # Add a title.
110
+ # chart.set_title(:name => 'Popular Pie Types')
111
+ #
112
+ #
113
+ # # Insert the chart into the worksheet (with an offset).
114
+ # worksheet.insert_chart('C2', chart, 25, 10)
115
+ #
116
+ # workbook.close
117
+ #
118
+ class Pie < Chart
119
+ ###############################################################################
120
+ #
121
+ # new()
122
+ #
123
+ #
124
+ def initialize(*args) # :nodoc:
125
+ super
126
+ @vary_data_color = 1
127
+ end
128
+
129
+ ###############################################################################
130
+ #
131
+ # _store_chart_type()
132
+ #
133
+ # Implementation of the abstract method from the specific chart class.
134
+ #
135
+ # Write the Pie chart BIFF record.
136
+ #
137
+ def store_chart_type # :nodoc:
138
+ record = 0x1019 # Record identifier.
139
+ length = 0x0006 # Number of bytes to follow.
140
+ angle = 0x0000 # Angle.
141
+ donut = 0x0000 # Donut hole size.
142
+ grbit = 0x0002 # Option flags.
143
+
144
+ header = [record, length].pack('vv')
145
+ data = [angle].pack('v')
146
+ data += [donut].pack('v')
147
+ data += [grbit].pack('v')
148
+
149
+ append(header, data)
150
+ end
151
+
152
+ ###############################################################################
153
+ #
154
+ # _store_axisparent_stream(). Overridden.
155
+ #
156
+ # Write the AXISPARENT chart substream.
157
+ #
158
+ # A Pie chart has no X or Y axis so we override this method to remove them.
159
+ #
160
+ def store_axisparent_stream # :nodoc:
161
+ store_axisparent(*@config[:axisparent])
162
+
163
+ store_begin
164
+ store_pos(*@config[:axisparent_pos])
165
+
166
+ store_chartformat_stream
167
+ store_end
168
+ end
169
+ end
170
+ end
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  ###############################################################################
2
3
  #
3
4
  # Scatter - A writer class for Excel Scatter charts.
@@ -110,9 +111,9 @@ class Chart
110
111
  # )
111
112
  #
112
113
  # # Add a chart title and some axis labels.
113
- # chart.set_title (name => 'Results of sample analysis')
114
- # chart.set_x_axis(name => 'Test number')
115
- # chart.set_y_axis(name => 'Sample length (cm)')
114
+ # chart.set_title (:name => 'Results of sample analysis')
115
+ # chart.set_x_axis(:name => 'Test number')
116
+ # chart.set_y_axis(:name => 'Sample length (cm)')
116
117
  #
117
118
  # # Insert the chart into the worksheet (with an offset).
118
119
  # worksheet.insert_chart('D2', chart, 25, 10)
@@ -1,211 +1,212 @@
1
- ###############################################################################
2
- #
3
- # Stock - A writer class for Excel Stock charts.
4
- #
5
- # Used in conjunction with Spreadsheet::WriteExcel::Chart.
6
- #
7
- # See formatting note in Spreadsheet::WriteExcel::Chart.
8
- #
9
- # Copyright 2000-2010, John McNamara, jmcnamara@cpan.org
10
- #
11
- # original written in Perl by John McNamara
12
- # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
13
- #
14
-
15
- require 'writeexcel'
16
-
17
- class Chart
18
-
19
- # ==SYNOPSIS
20
- #
21
- # To create a simple Excel file with a Stock chart using WriteExcel:
22
- #
23
- # #!/usr/bin/ruby -w
24
- #
25
- # require 'writeexcel'
26
- #
27
- # workbook = Spreadsheet::WriteExcel.new('chart.xls')
28
- # worksheet = workbook.add_worksheet
29
- #
30
- # chart = workbook.add_chart(:type => Chart::Stock)
31
- #
32
- # # Add a series for each Open-High-Low-Close.
33
- # chart.add_series(:categories => '=Sheet1!$A$2:$A$6', :values => '=Sheet1!$B$2:$B$6')
34
- # chart.add_series(:categories => '=Sheet1!$A$2:$A$6', :values => '=Sheet1!$C$2:$C$6')
35
- # chart.add_series(:categories => '=Sheet1!$A$2:$A$6', :values => '=Sheet1!$D$2:$D$6')
36
- # chart.add_series(:categories => '=Sheet1!$A$2:$A$6', :values => '=Sheet1!$E$2:$E$6')
37
- #
38
- # # Add the worksheet data the chart refers to.
39
- # # ... See the full example below.
40
- #
41
- # workbook.close
42
- #
43
- # ==DESCRIPTION
44
- #
45
- # This module implements Stock charts for WriteExcel. The chart object
46
- # is created via the Workbook add_chart() method:
47
- #
48
- # chart = workbook.add_chart(:type => Chart::Stock)
49
- #
50
- # Once the object is created it can be configured via the following methods
51
- # that are common to all chart classes:
52
- #
53
- # chart.add_series
54
- # chart.set_x_axis
55
- # chart.set_y_axis
56
- # chart.set_title
57
- #
58
- # These methods are explained in detail in Chart section of WriteExcel.
59
- # Class specific methods or settings, if any, are explained below.
60
- #
61
- # ==Stock Chart Methods
62
- #
63
- # There aren't currently any stock chart specific methods.
64
- # See the TODO section of Chart section in WriteExcel.
65
- #
66
- # The default Stock chart is an Open-High-Low-Close chart.
67
- # A series must be added for each of these data sources.
68
- #
69
- # The default Stock chart is in black and white. User defined colours
70
- # will be added at a later stage.
71
- #
72
- # ==EXAMPLE
73
- #
74
- # Here is a complete example that demonstrates most of the available features
75
- # when creating a Stock chart.
76
- #
77
- # #!/usr/bin/ruby -w
78
- #
79
- # require 'writeexcel'
80
- #
81
- # workbook = Spreadsheet::WriteExcel.new('chart_stock_ex.xls')
82
- # worksheet = workbook.add_worksheet
83
- # bold = workbook.add_format(:bold => 1)
84
- # date_format = workbook.add_format(:num_format => 'dd/mm/yyyy')
85
- #
86
- # # Add the worksheet data that the charts will refer to.
87
- # headings = [ 'Date', 'Open', 'High', 'Low', 'Close' ]
88
- # data = [
89
- # [ '2009-08-23', 110.75, 113.48, 109.05, 109.40 ],
90
- # [ '2009-08-24', 111.24, 111.60, 103.57, 104.87 ],
91
- # [ '2009-08-25', 104.96, 108.00, 103.88, 106.00 ],
92
- # [ '2009-08-26', 104.95, 107.95, 104.66, 107.91 ],
93
- # [ '2009-08-27', 108.10, 108.62, 105.69, 106.15 ]
94
- # ]
95
- #
96
- # worksheet.write('A1', headings, bold)
97
- #
98
- # row = 1
99
- # data.each do |d|
100
- # worksheet.write(row, 0, d[0], date_format)
101
- # worksheet.write(row, 1, d[1])
102
- # worksheet.write(row, 2, d[2])
103
- # worksheet.write(row, 3, d[3])
104
- # worksheet.write(row, 4, d[4])
105
- # row += 1
106
- # end
107
- #
108
- # # Create a new chart object. In this case an embedded chart.
109
- # chart = workbook.add_chart(:type => Chart::Stock, ::embedded => 1)
110
- #
111
- # # Add a series for each of the Open-High-Low-Close columns.
112
- # chart.add_series(
113
- # :categories => '=Sheet1!$A$2:$A$6',
114
- # :values => '=Sheet1!$B$2:$B$6',
115
- # :name => 'Open'
116
- # )
117
- #
118
- # chart.add_series(
119
- # :categories => '=Sheet1!$A$2:$A$6',
120
- # :values => '=Sheet1!$C$2:$C$6',
121
- # :name => 'High'
122
- # )
123
- #
124
- # chart.add_series(
125
- # :categories => '=Sheet1!$A$2:$A$6',
126
- # :values => '=Sheet1!$D$2:$D$6',
127
- # :name => 'Low'
128
- # )
129
- #
130
- # chart.add_series(
131
- # :categories => '=Sheet1!$A$2:$A$6',
132
- # :values => '=Sheet1!$E$2:$E$6',
133
- # :name => 'Close'
134
- # )
135
- #
136
- # # Add a chart title and some axis labels.
137
- # chart.set_title(:name => 'Open-High-Low-Close')
138
- # chart.set_x_axis(:name => 'Date')
139
- # chart.set_y_axis(:name => 'Share price')
140
- #
141
- # # Insert the chart into the worksheet (with an offset).
142
- # worksheet.insert_chart('F2', chart, 25, 10)
143
- #
144
- # workbook.close
145
- #
146
- class Stock < Chart
147
- ###############################################################################
148
- #
149
- # new()
150
- #
151
- #
152
- def initialize(*args) # :nodoc:
153
- super
154
- end
155
-
156
- ###############################################################################
157
- #
158
- # _store_chart_type()
159
- #
160
- # Implementation of the abstract method from the specific chart class.
161
- #
162
- # Write the LINE chart BIFF record. A stock chart uses the same LINE record
163
- # as a line chart but with additional DROPBAR and CHARTLINE records to define
164
- # the stock style.
165
- #
166
- def store_chart_type # :nodoc:
167
- record = 0x1018 # Record identifier.
168
- length = 0x0002 # Number of bytes to follow.
169
- grbit = 0x0000 # Option flags.
170
-
171
- header = [record, length].pack('vv')
172
- data = [grbit].pack('v')
173
-
174
- append(header, data)
175
- end
176
-
177
- ###############################################################################
178
- #
179
- # _store_marker_dataformat_stream(). Overridden.
180
- #
181
- # This is an implementation of the parent abstract method to define
182
- # properties of markers, linetypes, pie formats and other.
183
- #
184
- def store_marker_dataformat_stream # :nodoc:
185
- store_dropbar
186
- store_begin
187
- store_lineformat(0x00000000, 0x0000, 0xFFFF, 0x0001, 0x004F)
188
- store_areaformat(0x00FFFFFF, 0x0000, 0x01, 0x01, 0x09, 0x08)
189
- store_end
190
-
191
- store_dropbar
192
- store_begin
193
- store_lineformat(0x00000000, 0x0000, 0xFFFF, 0x0001, 0x004F)
194
- store_areaformat(0x0000, 0x00FFFFFF, 0x01, 0x01, 0x08, 0x09)
195
- store_end
196
-
197
- store_chartline
198
- store_lineformat(0x00000000, 0x0000, 0xFFFF, 0x0000, 0x004F)
199
-
200
-
201
- store_dataformat(0x0000, 0xFFFD, 0x0000)
202
- store_begin
203
- store_3dbarshape
204
- store_lineformat(0x00000000, 0x0005, 0xFFFF, 0x0000, 0x004F)
205
- store_areaformat(0x00000000, 0x0000, 0x00, 0x01, 0x4D, 0x4D)
206
- store_pieformat
207
- store_markerformat(0x00, 0x00, 0x00, 0x00, 0x4D, 0x4D, 0x3C)
208
- store_end
209
- end
210
- end
211
- end
1
+ # -*- coding: utf-8 -*-
2
+ ###############################################################################
3
+ #
4
+ # Stock - A writer class for Excel Stock charts.
5
+ #
6
+ # Used in conjunction with Spreadsheet::WriteExcel::Chart.
7
+ #
8
+ # See formatting note in Spreadsheet::WriteExcel::Chart.
9
+ #
10
+ # Copyright 2000-2010, John McNamara, jmcnamara@cpan.org
11
+ #
12
+ # original written in Perl by John McNamara
13
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
14
+ #
15
+
16
+ require 'writeexcel'
17
+
18
+ class Chart
19
+
20
+ # ==SYNOPSIS
21
+ #
22
+ # To create a simple Excel file with a Stock chart using WriteExcel:
23
+ #
24
+ # #!/usr/bin/ruby -w
25
+ #
26
+ # require 'writeexcel'
27
+ #
28
+ # workbook = Spreadsheet::WriteExcel.new('chart.xls')
29
+ # worksheet = workbook.add_worksheet
30
+ #
31
+ # chart = workbook.add_chart(:type => Chart::Stock)
32
+ #
33
+ # # Add a series for each Open-High-Low-Close.
34
+ # chart.add_series(:categories => '=Sheet1!$A$2:$A$6', :values => '=Sheet1!$B$2:$B$6')
35
+ # chart.add_series(:categories => '=Sheet1!$A$2:$A$6', :values => '=Sheet1!$C$2:$C$6')
36
+ # chart.add_series(:categories => '=Sheet1!$A$2:$A$6', :values => '=Sheet1!$D$2:$D$6')
37
+ # chart.add_series(:categories => '=Sheet1!$A$2:$A$6', :values => '=Sheet1!$E$2:$E$6')
38
+ #
39
+ # # Add the worksheet data the chart refers to.
40
+ # # ... See the full example below.
41
+ #
42
+ # workbook.close
43
+ #
44
+ # ==DESCRIPTION
45
+ #
46
+ # This module implements Stock charts for WriteExcel. The chart object
47
+ # is created via the Workbook add_chart() method:
48
+ #
49
+ # chart = workbook.add_chart(:type => Chart::Stock)
50
+ #
51
+ # Once the object is created it can be configured via the following methods
52
+ # that are common to all chart classes:
53
+ #
54
+ # chart.add_series
55
+ # chart.set_x_axis
56
+ # chart.set_y_axis
57
+ # chart.set_title
58
+ #
59
+ # These methods are explained in detail in Chart section of WriteExcel.
60
+ # Class specific methods or settings, if any, are explained below.
61
+ #
62
+ # ==Stock Chart Methods
63
+ #
64
+ # There aren't currently any stock chart specific methods.
65
+ # See the TODO section of Chart section in WriteExcel.
66
+ #
67
+ # The default Stock chart is an Open-High-Low-Close chart.
68
+ # A series must be added for each of these data sources.
69
+ #
70
+ # The default Stock chart is in black and white. User defined colours
71
+ # will be added at a later stage.
72
+ #
73
+ # ==EXAMPLE
74
+ #
75
+ # Here is a complete example that demonstrates most of the available features
76
+ # when creating a Stock chart.
77
+ #
78
+ # #!/usr/bin/ruby -w
79
+ #
80
+ # require 'writeexcel'
81
+ #
82
+ # workbook = Spreadsheet::WriteExcel.new('chart_stock_ex.xls')
83
+ # worksheet = workbook.add_worksheet
84
+ # bold = workbook.add_format(:bold => 1)
85
+ # date_format = workbook.add_format(:num_format => 'dd/mm/yyyy')
86
+ #
87
+ # # Add the worksheet data that the charts will refer to.
88
+ # headings = [ 'Date', 'Open', 'High', 'Low', 'Close' ]
89
+ # data = [
90
+ # [ '2009-08-23', 110.75, 113.48, 109.05, 109.40 ],
91
+ # [ '2009-08-24', 111.24, 111.60, 103.57, 104.87 ],
92
+ # [ '2009-08-25', 104.96, 108.00, 103.88, 106.00 ],
93
+ # [ '2009-08-26', 104.95, 107.95, 104.66, 107.91 ],
94
+ # [ '2009-08-27', 108.10, 108.62, 105.69, 106.15 ]
95
+ # ]
96
+ #
97
+ # worksheet.write('A1', headings, bold)
98
+ #
99
+ # row = 1
100
+ # data.each do |d|
101
+ # worksheet.write(row, 0, d[0], date_format)
102
+ # worksheet.write(row, 1, d[1])
103
+ # worksheet.write(row, 2, d[2])
104
+ # worksheet.write(row, 3, d[3])
105
+ # worksheet.write(row, 4, d[4])
106
+ # row += 1
107
+ # end
108
+ #
109
+ # # Create a new chart object. In this case an embedded chart.
110
+ # chart = workbook.add_chart(:type => Chart::Stock, ::embedded => 1)
111
+ #
112
+ # # Add a series for each of the Open-High-Low-Close columns.
113
+ # chart.add_series(
114
+ # :categories => '=Sheet1!$A$2:$A$6',
115
+ # :values => '=Sheet1!$B$2:$B$6',
116
+ # :name => 'Open'
117
+ # )
118
+ #
119
+ # chart.add_series(
120
+ # :categories => '=Sheet1!$A$2:$A$6',
121
+ # :values => '=Sheet1!$C$2:$C$6',
122
+ # :name => 'High'
123
+ # )
124
+ #
125
+ # chart.add_series(
126
+ # :categories => '=Sheet1!$A$2:$A$6',
127
+ # :values => '=Sheet1!$D$2:$D$6',
128
+ # :name => 'Low'
129
+ # )
130
+ #
131
+ # chart.add_series(
132
+ # :categories => '=Sheet1!$A$2:$A$6',
133
+ # :values => '=Sheet1!$E$2:$E$6',
134
+ # :name => 'Close'
135
+ # )
136
+ #
137
+ # # Add a chart title and some axis labels.
138
+ # chart.set_title(:name => 'Open-High-Low-Close')
139
+ # chart.set_x_axis(:name => 'Date')
140
+ # chart.set_y_axis(:name => 'Share price')
141
+ #
142
+ # # Insert the chart into the worksheet (with an offset).
143
+ # worksheet.insert_chart('F2', chart, 25, 10)
144
+ #
145
+ # workbook.close
146
+ #
147
+ class Stock < Chart
148
+ ###############################################################################
149
+ #
150
+ # new()
151
+ #
152
+ #
153
+ def initialize(*args) # :nodoc:
154
+ super
155
+ end
156
+
157
+ ###############################################################################
158
+ #
159
+ # _store_chart_type()
160
+ #
161
+ # Implementation of the abstract method from the specific chart class.
162
+ #
163
+ # Write the LINE chart BIFF record. A stock chart uses the same LINE record
164
+ # as a line chart but with additional DROPBAR and CHARTLINE records to define
165
+ # the stock style.
166
+ #
167
+ def store_chart_type # :nodoc:
168
+ record = 0x1018 # Record identifier.
169
+ length = 0x0002 # Number of bytes to follow.
170
+ grbit = 0x0000 # Option flags.
171
+
172
+ header = [record, length].pack('vv')
173
+ data = [grbit].pack('v')
174
+
175
+ append(header, data)
176
+ end
177
+
178
+ ###############################################################################
179
+ #
180
+ # _store_marker_dataformat_stream(). Overridden.
181
+ #
182
+ # This is an implementation of the parent abstract method to define
183
+ # properties of markers, linetypes, pie formats and other.
184
+ #
185
+ def store_marker_dataformat_stream # :nodoc:
186
+ store_dropbar
187
+ store_begin
188
+ store_lineformat(0x00000000, 0x0000, 0xFFFF, 0x0001, 0x004F)
189
+ store_areaformat(0x00FFFFFF, 0x0000, 0x01, 0x01, 0x09, 0x08)
190
+ store_end
191
+
192
+ store_dropbar
193
+ store_begin
194
+ store_lineformat(0x00000000, 0x0000, 0xFFFF, 0x0001, 0x004F)
195
+ store_areaformat(0x0000, 0x00FFFFFF, 0x01, 0x01, 0x08, 0x09)
196
+ store_end
197
+
198
+ store_chartline
199
+ store_lineformat(0x00000000, 0x0000, 0xFFFF, 0x0000, 0x004F)
200
+
201
+
202
+ store_dataformat(0x0000, 0xFFFD, 0x0000)
203
+ store_begin
204
+ store_3dbarshape
205
+ store_lineformat(0x00000000, 0x0005, 0xFFFF, 0x0000, 0x004F)
206
+ store_areaformat(0x00000000, 0x0000, 0x00, 0x01, 0x4D, 0x4D)
207
+ store_pieformat
208
+ store_markerformat(0x00, 0x00, 0x00, 0x00, 0x4D, 0x4D, 0x3C)
209
+ store_end
210
+ end
211
+ end
212
+ end