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.
- data/README +26 -31
- data/examples/a_simple.rb +42 -42
- data/examples/{autofilters.rb → autofilter.rb} +264 -266
- data/examples/bigfile.rb +29 -0
- data/examples/chart_area.rb +120 -0
- data/examples/chart_bar.rb +119 -0
- data/examples/chart_column.rb +119 -0
- data/examples/chart_line.rb +119 -0
- data/examples/chart_pie.rb +107 -0
- data/examples/chart_scatter.rb +120 -0
- data/examples/chart_stock.rb +147 -0
- data/examples/copyformat.rb +51 -51
- data/examples/data_validate.rb +278 -278
- data/examples/date_time.rb +86 -86
- data/examples/defined_name.rb +31 -0
- data/examples/demo.rb +120 -118
- data/examples/diag_border.rb +35 -35
- data/examples/formats.rb +489 -489
- data/examples/header.rb +136 -136
- data/examples/hidden.rb +28 -28
- data/examples/hyperlink.rb +42 -42
- data/examples/images.rb +52 -52
- data/examples/merge1.rb +39 -39
- data/examples/merge2.rb +44 -44
- data/examples/merge3.rb +65 -65
- data/examples/merge4.rb +82 -82
- data/examples/merge5.rb +79 -79
- data/examples/properties.rb +33 -0
- data/examples/properties_jp.rb +32 -0
- data/examples/protection.rb +46 -46
- data/examples/regions.rb +52 -52
- data/examples/repeat.rb +42 -42
- data/examples/stats.rb +75 -75
- data/examples/stocks.rb +80 -80
- data/examples/tab_colors.rb +30 -30
- data/examples/write_arrays.rb +82 -0
- data/lib/writeexcel.rb +1134 -18
- data/lib/writeexcel/biffwriter.rb +273 -260
- data/lib/writeexcel/chart.rb +2306 -217
- data/lib/writeexcel/charts/area.rb +152 -0
- data/lib/writeexcel/charts/bar.rb +177 -0
- data/lib/writeexcel/charts/column.rb +156 -0
- data/lib/writeexcel/charts/external.rb +61 -0
- data/lib/writeexcel/charts/line.rb +152 -0
- data/lib/writeexcel/charts/pie.rb +169 -0
- data/lib/writeexcel/charts/scatter.rb +192 -0
- data/lib/writeexcel/charts/stock.rb +211 -0
- data/lib/writeexcel/excelformulaparser.rb +208 -195
- data/lib/writeexcel/format.rb +1697 -1108
- data/lib/writeexcel/formula.rb +1050 -986
- data/lib/writeexcel/olewriter.rb +322 -322
- data/lib/writeexcel/properties.rb +251 -250
- data/lib/writeexcel/storage_lite.rb +968 -0
- data/lib/writeexcel/workbook.rb +3294 -2630
- data/lib/writeexcel/worksheet.rb +9012 -6377
- data/test/excelfile/Chart1.xls +0 -0
- data/test/excelfile/Chart2.xls +0 -0
- data/test/excelfile/Chart3.xls +0 -0
- data/test/excelfile/Chart4.xls +0 -0
- data/test/excelfile/Chart5.xls +0 -0
- data/test/perl_output/Chart1.xls.data +0 -0
- data/test/perl_output/Chart2.xls.data +0 -0
- data/test/perl_output/Chart3.xls.data +0 -0
- data/test/perl_output/Chart4.xls.data +0 -0
- data/test/perl_output/Chart5.xls.data +0 -0
- data/test/perl_output/a_simple.xls +0 -0
- data/test/perl_output/autofilter.xls +0 -0
- data/test/perl_output/chart_area.xls +0 -0
- data/test/perl_output/chart_bar.xls +0 -0
- data/test/perl_output/chart_column.xls +0 -0
- data/test/perl_output/chart_line.xls +0 -0
- data/test/perl_output/data_validate.xls +0 -0
- data/test/perl_output/date_time.xls +0 -0
- data/test/perl_output/demo.xls +0 -0
- data/test/perl_output/demo101.bin +0 -0
- data/test/perl_output/demo201.bin +0 -0
- data/test/perl_output/demo301.bin +0 -0
- data/test/perl_output/demo401.bin +0 -0
- data/test/perl_output/demo501.bin +0 -0
- data/test/perl_output/diag_border.xls +0 -0
- data/test/perl_output/headers.xls +0 -0
- data/test/perl_output/hyperlink.xls +0 -0
- data/test/perl_output/images.xls +0 -0
- data/test/perl_output/merge1.xls +0 -0
- data/test/perl_output/merge2.xls +0 -0
- data/test/perl_output/merge3.xls +0 -0
- data/test/perl_output/merge4.xls +0 -0
- data/test/perl_output/merge5.xls +0 -0
- data/test/perl_output/protection.xls +0 -0
- data/test/perl_output/regions.xls +0 -0
- data/test/perl_output/stats.xls +0 -0
- data/test/perl_output/stocks.xls +0 -0
- data/test/perl_output/tab_colors.xls +0 -0
- data/test/perl_output/unicode_cyrillic.xls +0 -0
- data/test/perl_output/workbook1.xls +0 -0
- data/test/perl_output/workbook2.xls +0 -0
- data/test/tc_all.rb +32 -31
- data/test/tc_biff.rb +104 -104
- data/test/tc_chart.rb +22 -22
- data/test/tc_example_match.rb +1944 -1280
- data/test/tc_format.rb +1254 -1267
- data/test/tc_formula.rb +63 -63
- data/test/tc_ole.rb +110 -110
- data/test/tc_storage_lite.rb +149 -0
- data/test/tc_workbook.rb +140 -115
- data/test/tc_worksheet.rb +115 -115
- data/test/test_00_IEEE_double.rb +14 -14
- data/test/test_01_add_worksheet.rb +12 -12
- data/test/test_02_merge_formats.rb +58 -58
- data/test/test_04_dimensions.rb +397 -397
- data/test/test_05_rows.rb +182 -182
- data/test/test_06_extsst.rb +80 -80
- data/test/test_11_date_time.rb +484 -484
- data/test/test_12_date_only.rb +506 -506
- data/test/test_13_date_seconds.rb +486 -486
- data/test/test_21_escher.rb +642 -629
- data/test/test_22_mso_drawing_group.rb +750 -739
- data/test/test_23_note.rb +78 -78
- data/test/test_24_txo.rb +80 -80
- data/test/test_25_position_object.rb +82 -0
- data/test/test_26_autofilter.rb +327 -327
- data/test/test_27_autofilter.rb +144 -144
- data/test/test_28_autofilter.rb +174 -174
- data/test/test_29_process_jpg.rb +681 -131
- data/test/test_30_validation_dval.rb +82 -82
- data/test/test_31_validation_dv_strings.rb +131 -131
- data/test/test_32_validation_dv_formula.rb +211 -211
- data/test/test_40_property_types.rb +191 -191
- data/test/test_41_properties.rb +238 -238
- data/test/test_42_set_properties.rb +442 -419
- data/test/test_50_name_stored.rb +305 -0
- data/test/test_51_name_print_area.rb +363 -0
- data/test/test_52_name_print_titles.rb +460 -0
- data/test/test_53_autofilter.rb +209 -0
- data/test/test_60_chart_generic.rb +576 -0
- data/test/test_61_chart_subclasses.rb +97 -0
- data/test/test_62_chart_formats.rb +270 -0
- data/test/test_63_chart_area_formats.rb +647 -0
- data/test/test_chartex.rb +35 -0
- data/test/ts_all.rb +46 -34
- data/writeexcel.gemspec +18 -0
- data/writeexcel.rdoc +583 -0
- metadata +162 -108
data/examples/bigfile.rb
ADDED
@@ -0,0 +1,29 @@
|
|
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
|
@@ -0,0 +1,120 @@
|
|
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
|
@@ -0,0 +1,119 @@
|
|
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
|
@@ -0,0 +1,119 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
#
|
3
|
+
###############################################################################
|
4
|
+
#
|
5
|
+
# A simple demo of Column 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_column.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::Column)
|
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::Column)
|
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::Column)
|
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::Column)
|
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::Column, :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
|
@@ -0,0 +1,119 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
#
|
3
|
+
###############################################################################
|
4
|
+
#
|
5
|
+
# A simple demo of Line 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_line.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::Line)
|
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::Line)
|
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::Line)
|
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::Line)
|
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::Line, :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
|