writeexcel 0.3.5 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
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,156 +1,157 @@
1
- ###############################################################################
2
- #
3
- # Column - A writer class for Excel Column charts.
4
- #
5
- # Used in conjunction with Chart.
6
- #
7
- # See formatting note in 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/chart'
16
-
17
- class Chart
18
-
19
- #
20
- # ==SYNOPSIS
21
- #
22
- # To create a simple Excel file with a Column chart using WriteExcel:
23
- #
24
- # #!/usr/bin/ruby -w
25
- #
26
- # require 'writeexcel'
27
- #
28
- # workbook = WriteExcel.new('chart.xls')
29
- # worksheet = workbook.add_worksheet
30
- #
31
- # chart = workbook.add_chart(:type => Chart::Column)
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 Column charts for WriteExcel. The chart object is
52
- # created via the Workbook add_chart method:
53
- #
54
- # chart = workbook.add_chart(:type => Chart::Column)
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_x_axis
61
- # chart.set_y_axis
62
- # chart.set_title
63
- #
64
- # These methods are explained in detail in Chart section of WriteExcel.
65
- # Class specific methods or settings, if any, are explained below.
66
- #
67
- # ==Column Chart Methods
68
- #
69
- # There aren't currently any column chart specific methods. See the TODO
70
- # section of Chart of Writeexcel.
71
- #
72
- # ==EXAMPLE
73
- #
74
- # Here is a complete example that demonstrates most of the available
75
- # features when creating a chart.
76
- #
77
- # #!/usr/bin/ruby -w
78
- #
79
- # require 'writeexcel'
80
- #
81
- # workbook = WriteExcel.new('chart_column.xls')
82
- # worksheet = workbook.add_worksheet
83
- # bold = workbook.add_format(:bold => 1)
84
- #
85
- # # Add the worksheet data that the charts will refer to.
86
- # headings = [ 'Number', 'Sample 1', 'Sample 2' ]
87
- # data = [
88
- # [ 2, 3, 4, 5, 6, 7 ],
89
- # [ 1, 4, 5, 2, 1, 5 ],
90
- # [ 3, 6, 7, 5, 4, 3 ]
91
- # ]
92
- #
93
- # worksheet.write('A1', headings, bold)
94
- # worksheet.write('A2', data)
95
- #
96
- # # Create a new chart object. In this case an embedded chart.
97
- # chart = workbook.add_chart(:type => Chart::Column, :embedded => 1)
98
- #
99
- # # Configure the first series. (Sample 1)
100
- # chart.add_series(
101
- # :name => 'Sample 1',
102
- # :categories => '=Sheet1!$A$2:$A$7',
103
- # :values => '=Sheet1!$B$2:$B$7',
104
- # )
105
- #
106
- # # Configure the second series. (Sample 2)
107
- # chart.add_series(
108
- # :name => 'Sample 2',
109
- # :categories => '=Sheet1!$A$2:$A$7',
110
- # :values => '=Sheet1!$C$2:$C$7',
111
- # )
112
- #
113
- # # Add a chart title and some axis labels.
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)')
117
- #
118
- # # Insert the chart into the worksheet (with an offset).
119
- # worksheet.insert_chart('D2', chart, 25, 10)
120
- #
121
- # workbook.close
122
- #
123
- class Column < Chart
124
- ###############################################################################
125
- #
126
- # new()
127
- #
128
- #
129
- def initialize(*args) # :nodoc:
130
- super(*args)
131
- end
132
-
133
- ###############################################################################
134
- #
135
- # _store_chart_type()
136
- #
137
- # Implementation of the abstract method from the specific chart class.
138
- #
139
- # Write the BAR chart BIFF record. Defines a bar or column chart type.
140
- #
141
- def store_chart_type # :nodoc:
142
- record = 0x1017 # Record identifier.
143
- length = 0x0006 # Number of bytes to follow.
144
- pcOverlap = 0x0000 # Space between bars.
145
- pcGap = 0x0096 # Space between cats.
146
- grbit = 0x0000 # Option flags.
147
-
148
- header = [record, length].pack('vv')
149
- data = [pcOverlap].pack('v')
150
- data += [pcGap].pack('v')
151
- data += [grbit].pack('v')
152
-
153
- append(header, data)
154
- end
155
- end
156
- end
1
+ # -*- coding: utf-8 -*-
2
+ ###############################################################################
3
+ #
4
+ # Column - A writer class for Excel Column charts.
5
+ #
6
+ # Used in conjunction with Chart.
7
+ #
8
+ # See formatting note in 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/chart'
17
+
18
+ class Chart
19
+
20
+ #
21
+ # ==SYNOPSIS
22
+ #
23
+ # To create a simple Excel file with a Column chart using WriteExcel:
24
+ #
25
+ # #!/usr/bin/ruby -w
26
+ #
27
+ # require 'writeexcel'
28
+ #
29
+ # workbook = WriteExcel.new('chart.xls')
30
+ # worksheet = workbook.add_worksheet
31
+ #
32
+ # chart = workbook.add_chart(:type => Chart::Column)
33
+ #
34
+ # # Configure the chart.
35
+ # chart.add_series(
36
+ # :categories => '=Sheet1!$A$2:$A$7',
37
+ # :values => '=Sheet1!$B$2:$B$7',
38
+ # )
39
+ #
40
+ # # Add the worksheet data the chart refers to.
41
+ # data = [
42
+ # [ 'Category', 2, 3, 4, 5, 6, 7 ],
43
+ # [ 'Value', 1, 4, 5, 2, 1, 5 ]
44
+ # ]
45
+ #
46
+ # worksheet.write('A1', data)
47
+ #
48
+ # workbook.close
49
+ #
50
+ # ==DESCRIPTION
51
+ #
52
+ # This module implements Column charts for WriteExcel. The chart object is
53
+ # created via the Workbook add_chart method:
54
+ #
55
+ # chart = workbook.add_chart(:type => Chart::Column)
56
+ #
57
+ # Once the object is created it can be configured via the following methods
58
+ # that are common to all chart classes:
59
+ #
60
+ # chart.add_series
61
+ # chart.set_x_axis
62
+ # chart.set_y_axis
63
+ # chart.set_title
64
+ #
65
+ # These methods are explained in detail in Chart section of WriteExcel.
66
+ # Class specific methods or settings, if any, are explained below.
67
+ #
68
+ # ==Column Chart Methods
69
+ #
70
+ # There aren't currently any column chart specific methods. See the TODO
71
+ # section of Chart of Writeexcel.
72
+ #
73
+ # ==EXAMPLE
74
+ #
75
+ # Here is a complete example that demonstrates most of the available
76
+ # features when creating a chart.
77
+ #
78
+ # #!/usr/bin/ruby -w
79
+ #
80
+ # require 'writeexcel'
81
+ #
82
+ # workbook = WriteExcel.new('chart_column.xls')
83
+ # worksheet = workbook.add_worksheet
84
+ # bold = workbook.add_format(:bold => 1)
85
+ #
86
+ # # Add the worksheet data that the charts will refer to.
87
+ # headings = [ 'Number', 'Sample 1', 'Sample 2' ]
88
+ # data = [
89
+ # [ 2, 3, 4, 5, 6, 7 ],
90
+ # [ 1, 4, 5, 2, 1, 5 ],
91
+ # [ 3, 6, 7, 5, 4, 3 ]
92
+ # ]
93
+ #
94
+ # worksheet.write('A1', headings, bold)
95
+ # worksheet.write('A2', data)
96
+ #
97
+ # # Create a new chart object. In this case an embedded chart.
98
+ # chart = workbook.add_chart(:type => Chart::Column, :embedded => 1)
99
+ #
100
+ # # Configure the first series. (Sample 1)
101
+ # chart.add_series(
102
+ # :name => 'Sample 1',
103
+ # :categories => '=Sheet1!$A$2:$A$7',
104
+ # :values => '=Sheet1!$B$2:$B$7',
105
+ # )
106
+ #
107
+ # # Configure the second series. (Sample 2)
108
+ # chart.add_series(
109
+ # :name => 'Sample 2',
110
+ # :categories => '=Sheet1!$A$2:$A$7',
111
+ # :values => '=Sheet1!$C$2:$C$7',
112
+ # )
113
+ #
114
+ # # Add a chart title and some axis labels.
115
+ # chart.set_title (:name => 'Results of sample analysis')
116
+ # chart.set_x_axis(:name => 'Test number')
117
+ # chart.set_y_axis(:name => 'Sample length (cm)')
118
+ #
119
+ # # Insert the chart into the worksheet (with an offset).
120
+ # worksheet.insert_chart('D2', chart, 25, 10)
121
+ #
122
+ # workbook.close
123
+ #
124
+ class Column < Chart
125
+ ###############################################################################
126
+ #
127
+ # new()
128
+ #
129
+ #
130
+ def initialize(*args) # :nodoc:
131
+ super(*args)
132
+ end
133
+
134
+ ###############################################################################
135
+ #
136
+ # _store_chart_type()
137
+ #
138
+ # Implementation of the abstract method from the specific chart class.
139
+ #
140
+ # Write the BAR chart BIFF record. Defines a bar or column chart type.
141
+ #
142
+ def store_chart_type # :nodoc:
143
+ record = 0x1017 # Record identifier.
144
+ length = 0x0006 # Number of bytes to follow.
145
+ pcOverlap = 0x0000 # Space between bars.
146
+ pcGap = 0x0096 # Space between cats.
147
+ grbit = 0x0000 # Option flags.
148
+
149
+ header = [record, length].pack('vv')
150
+ data = [pcOverlap].pack('v')
151
+ data += [pcGap].pack('v')
152
+ data += [grbit].pack('v')
153
+
154
+ append(header, data)
155
+ end
156
+ end
157
+ end
@@ -1,61 +1,62 @@
1
- ###############################################################################
2
- #
3
- # External - A writer class for Excel external charts.
4
- #
5
- # Used in conjunction with WriteExcel
6
- #
7
- # perltidy with options: -mbl=2 -pt=0 -nola
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/chart'
16
-
17
- class External < Chart # :nodoc:
18
- ###############################################################################
19
- #
20
- # new()
21
- #
22
- def initialize(external_filename, *args)
23
- super(*args)
24
-
25
- @filename = external_filename
26
- @external_bin = true
27
-
28
- _initialize # Requires overridden initialize().
29
- self
30
- end
31
-
32
- ###############################################################################
33
- #
34
- # _initialize()
35
- #
36
- # Read all the data into memory for the external binary style chart.
37
- #
38
- def _initialize
39
- filename = @filename
40
- filehandle = File.open(filename, 'rb')
41
-
42
- @filehandle = filehandle
43
- @datasize = FileTest.size(filename)
44
- @using_tmpfile = false
45
-
46
- # Read the entire external chart binary into the the data buffer.
47
- # This will be retrieved by _get_data() when the chart is closed().
48
- @data = @filehandle.read(@datasize)
49
- end
50
-
51
- ###############################################################################
52
- #
53
- # _close()
54
- #
55
- # We don't need to create or store Chart data structures when using an
56
- # external binary, so we have a default close method.
57
- #
58
- def close
59
- return nil
60
- end
61
- end
1
+ # -*- coding: utf-8 -*-
2
+ ###############################################################################
3
+ #
4
+ # External - A writer class for Excel external charts.
5
+ #
6
+ # Used in conjunction with WriteExcel
7
+ #
8
+ # perltidy with options: -mbl=2 -pt=0 -nola
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/chart'
17
+
18
+ class External < Chart # :nodoc:
19
+ ###############################################################################
20
+ #
21
+ # new()
22
+ #
23
+ def initialize(external_filename, *args)
24
+ super(*args)
25
+
26
+ @filename = external_filename
27
+ @external_bin = true
28
+
29
+ _initialize # Requires overridden initialize().
30
+ self
31
+ end
32
+
33
+ ###############################################################################
34
+ #
35
+ # _initialize()
36
+ #
37
+ # Read all the data into memory for the external binary style chart.
38
+ #
39
+ def _initialize
40
+ filename = @filename
41
+ filehandle = File.open(filename, 'rb')
42
+
43
+ @filehandle = filehandle
44
+ @datasize = FileTest.size(filename)
45
+ @using_tmpfile = false
46
+
47
+ # Read the entire external chart binary into the the data buffer.
48
+ # This will be retrieved by _get_data() when the chart is closed().
49
+ @data = @filehandle.read(@datasize)
50
+ end
51
+
52
+ ###############################################################################
53
+ #
54
+ # _close()
55
+ #
56
+ # We don't need to create or store Chart data structures when using an
57
+ # external binary, so we have a default close method.
58
+ #
59
+ def close
60
+ nil
61
+ end
62
+ end
@@ -1,152 +1,153 @@
1
- ###############################################################################
2
- #
3
- # Line - A writer class for Excel Line charts.
4
- #
5
- # Used in conjunction with Chart.
6
- #
7
- # See formatting note in 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/chart'
16
-
17
- class Chart
18
-
19
- #
20
- # ==SYNOPSIS
21
- #
22
- # To create a simple Excel file with a Line chart using WriteExcel:
23
- #
24
- # #!/usr/bin/ruby -w
25
- #
26
- # require 'writeexcel'
27
- #
28
- # workbook = WriteExcel.new('chart.xls')
29
- # worksheet = workbook.add_worksheet
30
- #
31
- # chart = workbook.add_chart(:type => Chart::Line)
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 Line charts for WriteExcel. The chart object is
52
- # created via the Workbook add_chart method:
53
- #
54
- # chart = workbook.add_chart(:type => Chart::Line)
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_x_axis
61
- # chart.set_y_axis
62
- # chart.set_title
63
- #
64
- # These methods are explained in detail in Chart section of WriteExcel.
65
- # Class specific methods or settings, if any, are explained below.
66
- #
67
- # ==Line Chart Methods
68
- #
69
- # There aren't currently any Line chart specific methods. See the TODO
70
- # section of Chart of Writeexcel.
71
- #
72
- # ==EXAMPLE
73
- #
74
- # Here is a complete example that demonstrates most of the available
75
- # features when creating a chart.
76
- #
77
- # #!/usr/bin/ruby -w
78
- #
79
- # require 'writeexcel'
80
- #
81
- # workbook = WriteExcel.new('chart_line.xls')
82
- # worksheet = workbook.add_worksheet
83
- # bold = workbook.add_format(:bold => 1)
84
- #
85
- # # Add the worksheet data that the charts will refer to.
86
- # headings = [ 'Number', 'Sample 1', 'Sample 2' ]
87
- # data = [
88
- # [ 2, 3, 4, 5, 6, 7 ],
89
- # [ 1, 4, 5, 2, 1, 5 ],
90
- # [ 3, 6, 7, 5, 4, 3 ]
91
- # ]
92
- #
93
- # worksheet.write('A1', headings, bold)
94
- # worksheet.write('A2', data)
95
- #
96
- # # Create a new chart object. In this case an embedded chart.
97
- # chart = workbook.add_chart(:type => Chart::Line, :embedded => 1)
98
- #
99
- # # Configure the first series. (Sample 1)
100
- # chart.add_series(
101
- # :name => 'Sample 1',
102
- # :categories => '=Sheet1!$A$2:$A$7',
103
- # :values => '=Sheet1!$B$2:$B$7',
104
- # )
105
- #
106
- # # Configure the second series. (Sample 2)
107
- # chart.add_series(
108
- # :name => 'Sample 2',
109
- # :categories => '=Sheet1!$A$2:$A$7',
110
- # :values => '=Sheet1!$C$2:$C$7',
111
- # )
112
- #
113
- # # Add a chart title and some axis labels.
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)')
117
- #
118
- # # Insert the chart into the worksheet (with an offset).
119
- # worksheet.insert_chart('D2', chart, 25, 10)
120
- #
121
- # workbook.close
122
- #
123
- class Line < Chart
124
- ###############################################################################
125
- #
126
- # new()
127
- #
128
- #
129
- def initialize(*args) # :nodoc:
130
- super(*args)
131
- end
132
-
133
- ###############################################################################
134
- #
135
- # _store_chart_type()
136
- #
137
- # Implementation of the abstract method from the specific chart class.
138
- #
139
- # Write the LINE chart BIFF record. Defines a line chart type.
140
- #
141
- def store_chart_type # :nodoc:
142
- record = 0x1018 # Record identifier.
143
- length = 0x0002 # Number of bytes to follow.
144
- grbit = 0x0000 # Option flags.
145
-
146
- header = [record, length].pack('vv')
147
- data = [grbit].pack('v')
148
-
149
- append(header, data)
150
- end
151
- end
152
- end
1
+ # -*- coding: utf-8 -*-
2
+ ###############################################################################
3
+ #
4
+ # Line - A writer class for Excel Line charts.
5
+ #
6
+ # Used in conjunction with Chart.
7
+ #
8
+ # See formatting note in 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/chart'
17
+
18
+ class Chart
19
+
20
+ #
21
+ # ==SYNOPSIS
22
+ #
23
+ # To create a simple Excel file with a Line chart using WriteExcel:
24
+ #
25
+ # #!/usr/bin/ruby -w
26
+ #
27
+ # require 'writeexcel'
28
+ #
29
+ # workbook = WriteExcel.new('chart.xls')
30
+ # worksheet = workbook.add_worksheet
31
+ #
32
+ # chart = workbook.add_chart(:type => Chart::Line)
33
+ #
34
+ # # Configure the chart.
35
+ # chart.add_series(
36
+ # :categories => '=Sheet1!$A$2:$A$7',
37
+ # :values => '=Sheet1!$B$2:$B$7',
38
+ # )
39
+ #
40
+ # # Add the worksheet data the chart refers to.
41
+ # data = [
42
+ # [ 'Category', 2, 3, 4, 5, 6, 7 ],
43
+ # [ 'Value', 1, 4, 5, 2, 1, 5 ]
44
+ # ]
45
+ #
46
+ # worksheet.write('A1', data)
47
+ #
48
+ # workbook.close
49
+ #
50
+ # ==DESCRIPTION
51
+ #
52
+ # This module implements Line charts for WriteExcel. The chart object is
53
+ # created via the Workbook add_chart method:
54
+ #
55
+ # chart = workbook.add_chart(:type => Chart::Line)
56
+ #
57
+ # Once the object is created it can be configured via the following methods
58
+ # that are common to all chart classes:
59
+ #
60
+ # chart.add_series
61
+ # chart.set_x_axis
62
+ # chart.set_y_axis
63
+ # chart.set_title
64
+ #
65
+ # These methods are explained in detail in Chart section of WriteExcel.
66
+ # Class specific methods or settings, if any, are explained below.
67
+ #
68
+ # ==Line Chart Methods
69
+ #
70
+ # There aren't currently any Line chart specific methods. See the TODO
71
+ # section of Chart of Writeexcel.
72
+ #
73
+ # ==EXAMPLE
74
+ #
75
+ # Here is a complete example that demonstrates most of the available
76
+ # features when creating a chart.
77
+ #
78
+ # #!/usr/bin/ruby -w
79
+ #
80
+ # require 'writeexcel'
81
+ #
82
+ # workbook = WriteExcel.new('chart_line.xls')
83
+ # worksheet = workbook.add_worksheet
84
+ # bold = workbook.add_format(:bold => 1)
85
+ #
86
+ # # Add the worksheet data that the charts will refer to.
87
+ # headings = [ 'Number', 'Sample 1', 'Sample 2' ]
88
+ # data = [
89
+ # [ 2, 3, 4, 5, 6, 7 ],
90
+ # [ 1, 4, 5, 2, 1, 5 ],
91
+ # [ 3, 6, 7, 5, 4, 3 ]
92
+ # ]
93
+ #
94
+ # worksheet.write('A1', headings, bold)
95
+ # worksheet.write('A2', data)
96
+ #
97
+ # # Create a new chart object. In this case an embedded chart.
98
+ # chart = workbook.add_chart(:type => Chart::Line, :embedded => 1)
99
+ #
100
+ # # Configure the first series. (Sample 1)
101
+ # chart.add_series(
102
+ # :name => 'Sample 1',
103
+ # :categories => '=Sheet1!$A$2:$A$7',
104
+ # :values => '=Sheet1!$B$2:$B$7',
105
+ # )
106
+ #
107
+ # # Configure the second series. (Sample 2)
108
+ # chart.add_series(
109
+ # :name => 'Sample 2',
110
+ # :categories => '=Sheet1!$A$2:$A$7',
111
+ # :values => '=Sheet1!$C$2:$C$7',
112
+ # )
113
+ #
114
+ # # Add a chart title and some axis labels.
115
+ # chart.set_title (:name => 'Results of sample analysis')
116
+ # chart.set_x_axis(:name => 'Test number')
117
+ # chart.set_y_axis(:name => 'Sample length (cm)')
118
+ #
119
+ # # Insert the chart into the worksheet (with an offset).
120
+ # worksheet.insert_chart('D2', chart, 25, 10)
121
+ #
122
+ # workbook.close
123
+ #
124
+ class Line < Chart
125
+ ###############################################################################
126
+ #
127
+ # new()
128
+ #
129
+ #
130
+ def initialize(*args) # :nodoc:
131
+ super(*args)
132
+ end
133
+
134
+ ###############################################################################
135
+ #
136
+ # _store_chart_type()
137
+ #
138
+ # Implementation of the abstract method from the specific chart class.
139
+ #
140
+ # Write the LINE chart BIFF record. Defines a line chart type.
141
+ #
142
+ def store_chart_type # :nodoc:
143
+ record = 0x1018 # Record identifier.
144
+ length = 0x0002 # Number of bytes to follow.
145
+ grbit = 0x0000 # Option flags.
146
+
147
+ header = [record, length].pack('vv')
148
+ data = [grbit].pack('v')
149
+
150
+ append(header, data)
151
+ end
152
+ end
153
+ end