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,47 +1,48 @@
1
- #!/usr/bin/ruby -w
2
-
3
- ###############################################################################
4
- #
5
- # Simple example of how to add an externally created chart to a Spreadsheet::
6
- # WriteExcel file.
7
- #
8
- #
9
- # This example adds a line chart extracted from the file Chart1.xls as follows:
10
- #
11
- # perl chartex.pl -c=demo5 Chart5.xls
12
- #
13
- #
14
- # reverse('ゥ'), September 2004, John McNamara, jmcnamara@cpan.org
15
- #
16
- # original written in Perl by John McNamara
17
- # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
18
- #
19
-
20
- require 'writeexcel'
21
-
22
- workbook = WriteExcel.new("demo5.xls")
23
- worksheet = workbook.add_worksheet
24
-
25
- # Add the chart extracted using the chartex utility
26
- worksheet.embed_chart('D3', 'demo501.bin')
27
-
28
- # Link the chart to the worksheet data using a dummy formula.
29
- worksheet.store_formula('=Sheet1!A1')
30
-
31
-
32
- # Add some extra formats to cover formats used in the charts.
33
- chart_font_1 = workbook.add_format(:font_only => 1)
34
- chart_font_2 = workbook.add_format(:font_only => 1)
35
-
36
- # Add all other formats.
37
-
38
- # Add data to range that the chart refers to.
39
- nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
40
- squares = [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
41
-
42
-
43
-
44
- worksheet.write_col('A1', nums)
45
- worksheet.write_col('B1', squares)
46
-
47
- workbook.close
1
+ #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
3
+
4
+ ###############################################################################
5
+ #
6
+ # Simple example of how to add an externally created chart to a Spreadsheet::
7
+ # WriteExcel file.
8
+ #
9
+ #
10
+ # This example adds a line chart extracted from the file Chart1.xls as follows:
11
+ #
12
+ # perl chartex.pl -c=demo5 Chart5.xls
13
+ #
14
+ #
15
+ # reverse('ゥ'), September 2004, John McNamara, jmcnamara@cpan.org
16
+ #
17
+ # original written in Perl by John McNamara
18
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
19
+ #
20
+
21
+ require 'writeexcel'
22
+
23
+ workbook = WriteExcel.new("demo5.xls")
24
+ worksheet = workbook.add_worksheet
25
+
26
+ # Add the chart extracted using the chartex utility
27
+ worksheet.embed_chart('D3', 'demo501.bin')
28
+
29
+ # Link the chart to the worksheet data using a dummy formula.
30
+ worksheet.store_formula('=Sheet1!A1')
31
+
32
+
33
+ # Add some extra formats to cover formats used in the charts.
34
+ chart_font_1 = workbook.add_format(:font_only => 1)
35
+ chart_font_2 = workbook.add_format(:font_only => 1)
36
+
37
+ # Add all other formats.
38
+
39
+ # Add data to range that the chart refers to.
40
+ nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
41
+ squares = [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
42
+
43
+
44
+
45
+ worksheet.write_col('A1', nums)
46
+ worksheet.write_col('B1', squares)
47
+
48
+ workbook.close
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
  #
3
4
  # Example of how to use the WriteExcel module to write text and numbers
4
5
  # to an Excel binary file.
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  #######################################################################
4
5
  #
@@ -1,29 +1,30 @@
1
- #!/usr/bin/ruby -w
2
-
3
- ###############################################################################
4
- #
5
- # Example of creating a WriteExcel that is larger than the
6
- # default 7MB limit.
7
- #
8
- # It is exactly that same as any other WriteExcel program except
9
- # that is requires that the OLE::Storage module is installed.
10
- #
11
- # reverse('©'), Jan 2007, John McNamara, jmcnamara@cpan.org
12
- #
13
- # original written in Perl by John McNamara
14
- # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
15
- #
16
- require 'writeexcel'
17
-
18
- workbook = WriteExcel.new('bigfile.xls')
19
- worksheet = workbook.add_worksheet
20
-
21
- worksheet.set_column(0, 50, 18)
22
-
23
- 0.upto(50) do |col|
24
- 0.upto(6000) do |row|
25
- worksheet.write(row, col, "Row: #{row} Col: #{col}")
26
- end
27
- end
28
-
29
- workbook.close
1
+ #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
3
+
4
+ ###############################################################################
5
+ #
6
+ # Example of creating a WriteExcel that is larger than the
7
+ # default 7MB limit.
8
+ #
9
+ # It is exactly that same as any other WriteExcel program except
10
+ # that is requires that the OLE::Storage module is installed.
11
+ #
12
+ # reverse('©'), Jan 2007, John McNamara, jmcnamara@cpan.org
13
+ #
14
+ # original written in Perl by John McNamara
15
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
16
+ #
17
+ require 'writeexcel'
18
+
19
+ workbook = WriteExcel.new('bigfile.xls')
20
+ worksheet = workbook.add_worksheet
21
+
22
+ worksheet.set_column(0, 50, 18)
23
+
24
+ 0.upto(50) do |col|
25
+ 0.upto(6000) do |row|
26
+ worksheet.write(row, col, "Row: #{row} Col: #{col}")
27
+ end
28
+ end
29
+
30
+ workbook.close
@@ -1,120 +1,121 @@
1
- #!/usr/bin/ruby -w
2
- #
3
- ###############################################################################
4
- #
5
- # A simple demo of Area chart in Spreadsheet::WriteExcel.
6
- #
7
- # reverse('ゥ'), December 2009, John McNamara, jmcnamara@cpan.org
8
- #
9
- # original written in Perl by John McNamara
10
- # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
11
- #
12
- require 'rubygems'
13
- require 'writeexcel'
14
-
15
- # Create a new workbook called simple.xls and add a worksheet
16
- workbook = WriteExcel.new('chart_area.xls')
17
- worksheet = workbook.add_worksheet
18
- bold = workbook.add_format(:bold => 1)
19
-
20
- # Add the worksheet data that the charts will refer to.
21
- headings = [ 'Category', 'Values 1', 'Values 2' ]
22
- data = [
23
- [ 2, 3, 4, 5, 6, 7 ],
24
- [ 1, 4, 5, 2, 1, 5 ],
25
- [ 3, 6, 7, 5, 4, 3 ]
26
- ]
27
-
28
- worksheet.write('A1', headings, bold)
29
- worksheet.write('A2', data)
30
-
31
-
32
- ###############################################################################
33
- #
34
- # Example 1. A minimal chart.
35
- #
36
- chart1 = workbook.add_chart(:type => Chart::Area)
37
-
38
- # Add values only. Use the default categories.
39
- chart1.add_series( :values => '=Sheet1!$B$2:$B$7' )
40
-
41
- ###############################################################################
42
- #
43
- # Example 2. A minimal chart with user specified categories (X axis)
44
- # and a series name.
45
- #
46
- chart2 = workbook.add_chart(:type => Chart::Area)
47
-
48
- # Configure the series.
49
- chart2.add_series(
50
- :categories => '=Sheet1!$A$2:$A$7',
51
- :values => '=Sheet1!$B$2:$B$7',
52
- :name => 'Test data series 1'
53
- )
54
-
55
- ###############################################################################
56
- #
57
- # Example 3. Same as previous chart but with added title and axes labels.
58
- #
59
- chart3 = workbook.add_chart(:type => Chart::Area)
60
-
61
- # Configure the series.
62
- chart3.add_series(
63
- :categories => '=Sheet1!$A$2:$A$7',
64
- :values => '=Sheet1!$B$2:$B$7',
65
- :name => 'Test data series 1'
66
- )
67
-
68
- # Add some labels.
69
- chart3.set_title( :name => 'Results of sample analysis' )
70
- chart3.set_x_axis( :name => 'Sample number' )
71
- chart3.set_y_axis( :name => 'Sample length (cm)' )
72
-
73
- ###############################################################################
74
- #
75
- # Example 4. Same as previous chart but with an added series
76
- #
77
- chart4 = workbook.add_chart(:name => 'Results Chart', :type => Chart::Area)
78
-
79
- # Configure the series.
80
- chart4.add_series(
81
- :categories => '=Sheet1!$A$2:$A$7',
82
- :values => '=Sheet1!$B$2:$B$7',
83
- :name => 'Test data series 1'
84
- )
85
-
86
- # Add another series.
87
- chart4.add_series(
88
- :categories => '=Sheet1!$A$2:$A$7',
89
- :values => '=Sheet1!$C$2:$C$7',
90
- :name => 'Test data series 2'
91
- )
92
-
93
- # Add some labels.
94
- chart4.set_title( :name => 'Results of sample analysis' )
95
- chart4.set_x_axis( :name => 'Sample number' )
96
- chart4.set_y_axis( :name => 'Sample length (cm)' )
97
-
98
- ###############################################################################
99
- #
100
- # Example 5. Same as Example 3 but as an embedded chart.
101
- #
102
- chart5 = workbook.add_chart(:type => Chart::Area, :embedded => 1)
103
-
104
- # Configure the series.
105
- chart5.add_series(
106
- :categories => '=Sheet1!$A$2:$A$7',
107
- :values => '=Sheet1!$B$2:$B$7',
108
- :name => 'Test data series 1'
109
- )
110
-
111
- # Add some labels.
112
- chart5.set_title(:name => 'Results of sample analysis' )
113
- chart5.set_x_axis(:name => 'Sample number')
114
- chart5.set_y_axis(:name => 'Sample length (cm)')
115
-
116
- # Insert the chart into the main worksheet.
117
- worksheet.insert_chart('E2', chart5)
118
-
119
- # File save
120
- workbook.close
1
+ #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ ###############################################################################
5
+ #
6
+ # A simple demo of Area chart in Spreadsheet::WriteExcel.
7
+ #
8
+ # reverse('ゥ'), December 2009, John McNamara, jmcnamara@cpan.org
9
+ #
10
+ # original written in Perl by John McNamara
11
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
12
+ #
13
+ require 'rubygems'
14
+ require 'writeexcel'
15
+
16
+ # Create a new workbook called simple.xls and add a worksheet
17
+ workbook = WriteExcel.new('chart_area.xls')
18
+ worksheet = workbook.add_worksheet
19
+ bold = workbook.add_format(:bold => 1)
20
+
21
+ # Add the worksheet data that the charts will refer to.
22
+ headings = [ 'Category', 'Values 1', 'Values 2' ]
23
+ data = [
24
+ [ 2, 3, 4, 5, 6, 7 ],
25
+ [ 1, 4, 5, 2, 1, 5 ],
26
+ [ 3, 6, 7, 5, 4, 3 ]
27
+ ]
28
+
29
+ worksheet.write('A1', headings, bold)
30
+ worksheet.write('A2', data)
31
+
32
+
33
+ ###############################################################################
34
+ #
35
+ # Example 1. A minimal chart.
36
+ #
37
+ chart1 = workbook.add_chart(:type => Chart::Area)
38
+
39
+ # Add values only. Use the default categories.
40
+ chart1.add_series( :values => '=Sheet1!$B$2:$B$7' )
41
+
42
+ ###############################################################################
43
+ #
44
+ # Example 2. A minimal chart with user specified categories (X axis)
45
+ # and a series name.
46
+ #
47
+ chart2 = workbook.add_chart(:type => Chart::Area)
48
+
49
+ # Configure the series.
50
+ chart2.add_series(
51
+ :categories => '=Sheet1!$A$2:$A$7',
52
+ :values => '=Sheet1!$B$2:$B$7',
53
+ :name => 'Test data series 1'
54
+ )
55
+
56
+ ###############################################################################
57
+ #
58
+ # Example 3. Same as previous chart but with added title and axes labels.
59
+ #
60
+ chart3 = workbook.add_chart(:type => Chart::Area)
61
+
62
+ # Configure the series.
63
+ chart3.add_series(
64
+ :categories => '=Sheet1!$A$2:$A$7',
65
+ :values => '=Sheet1!$B$2:$B$7',
66
+ :name => 'Test data series 1'
67
+ )
68
+
69
+ # Add some labels.
70
+ chart3.set_title( :name => 'Results of sample analysis' )
71
+ chart3.set_x_axis( :name => 'Sample number' )
72
+ chart3.set_y_axis( :name => 'Sample length (cm)' )
73
+
74
+ ###############################################################################
75
+ #
76
+ # Example 4. Same as previous chart but with an added series
77
+ #
78
+ chart4 = workbook.add_chart(:name => 'Results Chart', :type => Chart::Area)
79
+
80
+ # Configure the series.
81
+ chart4.add_series(
82
+ :categories => '=Sheet1!$A$2:$A$7',
83
+ :values => '=Sheet1!$B$2:$B$7',
84
+ :name => 'Test data series 1'
85
+ )
86
+
87
+ # Add another series.
88
+ chart4.add_series(
89
+ :categories => '=Sheet1!$A$2:$A$7',
90
+ :values => '=Sheet1!$C$2:$C$7',
91
+ :name => 'Test data series 2'
92
+ )
93
+
94
+ # Add some labels.
95
+ chart4.set_title( :name => 'Results of sample analysis' )
96
+ chart4.set_x_axis( :name => 'Sample number' )
97
+ chart4.set_y_axis( :name => 'Sample length (cm)' )
98
+
99
+ ###############################################################################
100
+ #
101
+ # Example 5. Same as Example 3 but as an embedded chart.
102
+ #
103
+ chart5 = workbook.add_chart(:type => Chart::Area, :embedded => 1)
104
+
105
+ # Configure the series.
106
+ chart5.add_series(
107
+ :categories => '=Sheet1!$A$2:$A$7',
108
+ :values => '=Sheet1!$B$2:$B$7',
109
+ :name => 'Test data series 1'
110
+ )
111
+
112
+ # Add some labels.
113
+ chart5.set_title(:name => 'Results of sample analysis' )
114
+ chart5.set_x_axis(:name => 'Sample number')
115
+ chart5.set_y_axis(:name => 'Sample length (cm)')
116
+
117
+ # Insert the chart into the main worksheet.
118
+ worksheet.insert_chart('E2', chart5)
119
+
120
+ # File save
121
+ workbook.close
@@ -1,119 +1,120 @@
1
- #!/usr/bin/ruby -w
2
- #
3
- ###############################################################################
4
- #
5
- # A simple demo of Bar chart in Spreadsheet::WriteExcel.
6
- #
7
- # reverse('・ゥ'), December 2009, John McNamara, jmcnamara@cpan.org
8
- #
9
- # original written in Perl by John McNamara
10
- # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
11
- #
12
- require 'writeexcel'
13
-
14
- # Create a new workbook called simple.xls and add a worksheet
15
- workbook = WriteExcel.new('chart_bar.xls')
16
- worksheet = workbook.add_worksheet
17
- bold = workbook.add_format(:bold => 1)
18
-
19
- # Add the worksheet data that the charts will refer to.
20
- headings = [ 'Category', 'Values 1', 'Values 2' ]
21
- data = [
22
- [ 2, 3, 4, 5, 6, 7 ],
23
- [ 1, 4, 5, 2, 1, 5 ],
24
- [ 3, 6, 7, 5, 4, 3 ]
25
- ]
26
-
27
- worksheet.write('A1', headings, bold)
28
- worksheet.write('A2', data)
29
-
30
-
31
- ###############################################################################
32
- #
33
- # Example 1. A minimal chart.
34
- #
35
- chart1 = workbook.add_chart(:type => Chart::Bar)
36
-
37
- # Add values only. Use the default categories.
38
- chart1.add_series( :values => '=Sheet1!$B$2:$B$7' )
39
-
40
- ###############################################################################
41
- #
42
- # Example 2. A minimal chart with user specified categories (X axis)
43
- # and a series name.
44
- #
45
- chart2 = workbook.add_chart(:type => Chart::Bar)
46
-
47
- # Configure the series.
48
- chart2.add_series(
49
- :categories => '=Sheet1!$A$2:$A$7',
50
- :values => '=Sheet1!$B$2:$B$7',
51
- :name => 'Test data series 1'
52
- )
53
-
54
- ###############################################################################
55
- #
56
- # Example 3. Same as previous chart but with added title and axes labels.
57
- #
58
- chart3 = workbook.add_chart(:type => Chart::Bar)
59
-
60
- # Configure the series.
61
- chart3.add_series(
62
- :categories => '=Sheet1!$A$2:$A$7',
63
- :values => '=Sheet1!$B$2:$B$7',
64
- :name => 'Test data series 1'
65
- )
66
-
67
- # Add some labels.
68
- chart3.set_title( :name => 'Results of sample analysis' )
69
- chart3.set_x_axis( :name => 'Sample number' )
70
- chart3.set_y_axis( :name => 'Sample length (cm)' )
71
-
72
- ###############################################################################
73
- #
74
- # Example 4. Same as previous chart but with an added series
75
- #
76
- chart4 = workbook.add_chart(:name => 'Results Chart', :type => Chart::Bar)
77
-
78
- # Configure the series.
79
- chart4.add_series(
80
- :categories => '=Sheet1!$A$2:$A$7',
81
- :values => '=Sheet1!$B$2:$B$7',
82
- :name => 'Test data series 1'
83
- )
84
-
85
- # Add another series.
86
- chart4.add_series(
87
- :categories => '=Sheet1!$A$2:$A$7',
88
- :values => '=Sheet1!$C$2:$C$7',
89
- :name => 'Test data series 2'
90
- )
91
-
92
- # Add some labels.
93
- chart4.set_title( :name => 'Results of sample analysis' )
94
- chart4.set_x_axis( :name => 'Sample number' )
95
- chart4.set_y_axis( :name => 'Sample length (cm)' )
96
-
97
- ###############################################################################
98
- #
99
- # Example 5. Same as Example 3 but as an embedded chart.
100
- #
101
- chart5 = workbook.add_chart(:type => Chart::Bar, :embedded => 1)
102
-
103
- # Configure the series.
104
- chart5.add_series(
105
- :categories => '=Sheet1!$A$2:$A$7',
106
- :values => '=Sheet1!$B$2:$B$7',
107
- :name => 'Test data series 1'
108
- )
109
-
110
- # Add some labels.
111
- chart5.set_title(:name => 'Results of sample analysis' )
112
- chart5.set_x_axis(:name => 'Sample number')
113
- chart5.set_y_axis(:name => 'Sample length (cm)')
114
-
115
- # Insert the chart into the main worksheet.
116
- worksheet.insert_chart('E2', chart5)
117
-
118
- # File save
119
- workbook.close
1
+ #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ ###############################################################################
5
+ #
6
+ # A simple demo of Bar chart in Spreadsheet::WriteExcel.
7
+ #
8
+ # reverse('・ゥ'), December 2009, John McNamara, jmcnamara@cpan.org
9
+ #
10
+ # original written in Perl by John McNamara
11
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
12
+ #
13
+ require 'writeexcel'
14
+
15
+ # Create a new workbook called simple.xls and add a worksheet
16
+ workbook = WriteExcel.new('chart_bar.xls')
17
+ worksheet = workbook.add_worksheet
18
+ bold = workbook.add_format(:bold => 1)
19
+
20
+ # Add the worksheet data that the charts will refer to.
21
+ headings = [ 'Category', 'Values 1', 'Values 2' ]
22
+ data = [
23
+ [ 2, 3, 4, 5, 6, 7 ],
24
+ [ 1, 4, 5, 2, 1, 5 ],
25
+ [ 3, 6, 7, 5, 4, 3 ]
26
+ ]
27
+
28
+ worksheet.write('A1', headings, bold)
29
+ worksheet.write('A2', data)
30
+
31
+
32
+ ###############################################################################
33
+ #
34
+ # Example 1. A minimal chart.
35
+ #
36
+ chart1 = workbook.add_chart(:type => Chart::Bar)
37
+
38
+ # Add values only. Use the default categories.
39
+ chart1.add_series( :values => '=Sheet1!$B$2:$B$7' )
40
+
41
+ ###############################################################################
42
+ #
43
+ # Example 2. A minimal chart with user specified categories (X axis)
44
+ # and a series name.
45
+ #
46
+ chart2 = workbook.add_chart(:type => Chart::Bar)
47
+
48
+ # Configure the series.
49
+ chart2.add_series(
50
+ :categories => '=Sheet1!$A$2:$A$7',
51
+ :values => '=Sheet1!$B$2:$B$7',
52
+ :name => 'Test data series 1'
53
+ )
54
+
55
+ ###############################################################################
56
+ #
57
+ # Example 3. Same as previous chart but with added title and axes labels.
58
+ #
59
+ chart3 = workbook.add_chart(:type => Chart::Bar)
60
+
61
+ # Configure the series.
62
+ chart3.add_series(
63
+ :categories => '=Sheet1!$A$2:$A$7',
64
+ :values => '=Sheet1!$B$2:$B$7',
65
+ :name => 'Test data series 1'
66
+ )
67
+
68
+ # Add some labels.
69
+ chart3.set_title( :name => 'Results of sample analysis' )
70
+ chart3.set_x_axis( :name => 'Sample number' )
71
+ chart3.set_y_axis( :name => 'Sample length (cm)' )
72
+
73
+ ###############################################################################
74
+ #
75
+ # Example 4. Same as previous chart but with an added series
76
+ #
77
+ chart4 = workbook.add_chart(:name => 'Results Chart', :type => Chart::Bar)
78
+
79
+ # Configure the series.
80
+ chart4.add_series(
81
+ :categories => '=Sheet1!$A$2:$A$7',
82
+ :values => '=Sheet1!$B$2:$B$7',
83
+ :name => 'Test data series 1'
84
+ )
85
+
86
+ # Add another series.
87
+ chart4.add_series(
88
+ :categories => '=Sheet1!$A$2:$A$7',
89
+ :values => '=Sheet1!$C$2:$C$7',
90
+ :name => 'Test data series 2'
91
+ )
92
+
93
+ # Add some labels.
94
+ chart4.set_title( :name => 'Results of sample analysis' )
95
+ chart4.set_x_axis( :name => 'Sample number' )
96
+ chart4.set_y_axis( :name => 'Sample length (cm)' )
97
+
98
+ ###############################################################################
99
+ #
100
+ # Example 5. Same as Example 3 but as an embedded chart.
101
+ #
102
+ chart5 = workbook.add_chart(:type => Chart::Bar, :embedded => 1)
103
+
104
+ # Configure the series.
105
+ chart5.add_series(
106
+ :categories => '=Sheet1!$A$2:$A$7',
107
+ :values => '=Sheet1!$B$2:$B$7',
108
+ :name => 'Test data series 1'
109
+ )
110
+
111
+ # Add some labels.
112
+ chart5.set_title(:name => 'Results of sample analysis' )
113
+ chart5.set_x_axis(:name => 'Sample number')
114
+ chart5.set_y_axis(:name => 'Sample length (cm)')
115
+
116
+ # Insert the chart into the main worksheet.
117
+ worksheet.insert_chart('E2', chart5)
118
+
119
+ # File save
120
+ workbook.close