writeexcel 0.3.5 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitattributes +1 -0
- data/README.rdoc +12 -6
- data/VERSION +1 -1
- data/charts/chartex.rb +316 -315
- data/charts/demo1.rb +1 -0
- data/charts/demo2.rb +1 -0
- data/charts/demo3.rb +117 -116
- data/charts/demo4.rb +119 -118
- data/charts/demo5.rb +48 -47
- data/examples/a_simple.rb +1 -0
- data/examples/autofilter.rb +1 -0
- data/examples/bigfile.rb +30 -29
- data/examples/chart_area.rb +121 -120
- data/examples/chart_bar.rb +120 -119
- data/examples/chart_column.rb +120 -119
- data/examples/chart_line.rb +120 -119
- data/examples/chart_pie.rb +108 -107
- data/examples/chart_scatter.rb +121 -120
- data/examples/chart_stock.rb +148 -147
- data/examples/chess.rb +1 -0
- data/examples/colors.rb +1 -0
- data/examples/comments1.rb +1 -0
- data/examples/comments2.rb +3 -2
- data/examples/copyformat.rb +1 -0
- data/examples/data_validate.rb +1 -0
- data/examples/date_time.rb +1 -0
- data/examples/defined_name.rb +1 -0
- data/examples/demo.rb +1 -0
- data/examples/diag_border.rb +1 -0
- data/examples/formats.rb +1 -0
- data/examples/formula_result.rb +1 -0
- data/examples/header.rb +1 -0
- data/examples/hide_sheet.rb +1 -0
- data/examples/hyperlink.rb +1 -0
- data/examples/images.rb +1 -0
- data/examples/indent.rb +1 -0
- data/examples/merge1.rb +1 -0
- data/examples/merge2.rb +1 -0
- data/examples/merge3.rb +1 -0
- data/examples/merge4.rb +1 -0
- data/examples/merge5.rb +1 -0
- data/examples/merge6.rb +67 -66
- data/examples/outline.rb +1 -0
- data/examples/outline_collapsed.rb +1 -0
- data/examples/panes.rb +1 -0
- data/examples/properties.rb +1 -0
- data/examples/properties_jp.rb +1 -0
- data/examples/protection.rb +1 -0
- data/examples/regions.rb +1 -0
- data/examples/repeat.rb +1 -0
- data/examples/right_to_left.rb +1 -0
- data/examples/row_wrap.rb +1 -0
- data/examples/stats.rb +1 -0
- data/examples/stocks.rb +1 -0
- data/examples/tab_colors.rb +1 -0
- data/examples/write_arrays.rb +1 -0
- data/lib/writeexcel.rb +6 -1
- data/lib/writeexcel/biffwriter.rb +21 -20
- data/lib/writeexcel/chart.rb +25 -12
- data/lib/writeexcel/charts/area.rb +153 -152
- data/lib/writeexcel/charts/bar.rb +178 -177
- data/lib/writeexcel/charts/column.rb +157 -156
- data/lib/writeexcel/charts/external.rb +62 -61
- data/lib/writeexcel/charts/line.rb +153 -152
- data/lib/writeexcel/charts/pie.rb +170 -169
- data/lib/writeexcel/charts/scatter.rb +4 -3
- data/lib/writeexcel/charts/stock.rb +212 -211
- data/lib/writeexcel/compatibility.rb +320 -0
- data/lib/writeexcel/excelformulaparser.rb +587 -586
- data/lib/writeexcel/format.rb +12 -13
- data/lib/writeexcel/formula.rb +30 -28
- data/lib/writeexcel/helper.rb +23 -0
- data/lib/writeexcel/olewriter.rb +5 -16
- data/lib/writeexcel/properties.rb +43 -54
- data/lib/writeexcel/storage_lite.rb +981 -968
- data/lib/writeexcel/workbook.rb +94 -73
- data/lib/writeexcel/worksheet.rb +230 -210
- data/test/helper.rb +19 -0
- data/test/test_00_IEEE_double.rb +1 -0
- data/test/test_01_add_worksheet.rb +1 -0
- data/test/test_02_merge_formats.rb +3 -5
- data/test/test_04_dimensions.rb +3 -5
- data/test/test_05_rows.rb +6 -6
- data/test/test_06_extsst.rb +8 -8
- data/test/test_11_date_time.rb +3 -5
- data/test/test_12_date_only.rb +3 -5
- data/test/test_13_date_seconds.rb +4 -6
- data/test/test_21_escher.rb +3 -5
- data/test/test_22_mso_drawing_group.rb +20 -22
- data/test/test_23_note.rb +5 -7
- data/test/test_24_txo.rb +3 -5
- data/test/test_25_position_object.rb +84 -79
- data/test/test_26_autofilter.rb +3 -13
- data/test/test_27_autofilter.rb +3 -13
- data/test/test_28_autofilter.rb +3 -13
- data/test/test_29_process_jpg.rb +5 -0
- data/test/test_30_validation_dval.rb +3 -5
- data/test/test_31_validation_dv_strings.rb +3 -5
- data/test/test_32_validation_dv_formula.rb +3 -5
- data/test/test_40_property_types.rb +10 -9
- data/test/test_41_properties.rb +1 -0
- data/test/test_42_set_properties.rb +14 -15
- data/test/test_50_name_stored.rb +299 -302
- data/test/test_51_name_print_area.rb +357 -360
- data/test/test_52_name_print_titles.rb +454 -457
- data/test/test_53_autofilter.rb +203 -206
- data/test/test_60_chart_generic.rb +5 -0
- data/test/test_61_chart_subclasses.rb +95 -94
- data/test/test_62_chart_formats.rb +272 -267
- data/test/test_63_chart_area_formats.rb +649 -644
- data/test/test_biff.rb +12 -38
- data/test/test_compatibility.rb +627 -0
- data/test/test_example_match.rb +3 -18
- data/test/test_format.rb +46 -105
- data/test/test_formula.rb +1 -0
- data/test/test_ole.rb +3 -4
- data/test/test_storage_lite.rb +125 -146
- data/test/test_workbook.rb +2 -23
- data/test/test_worksheet.rb +4 -5
- data/utils/add_magic_comment.rb +80 -0
- data/writeexcel.gemspec +8 -2
- metadata +10 -4
data/examples/chart_pie.rb
CHANGED
@@ -1,107 +1,108 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
#
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
workbook
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
[
|
24
|
-
]
|
25
|
-
|
26
|
-
|
27
|
-
worksheet.write('
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
#
|
33
|
-
#
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
#
|
42
|
-
#
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
:
|
49
|
-
:
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
#
|
55
|
-
#
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
:
|
62
|
-
:
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
#
|
71
|
-
#
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
:
|
78
|
-
:
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
#
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
#
|
90
|
-
#
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
:
|
97
|
-
:
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
worksheet.
|
105
|
-
|
106
|
-
|
107
|
-
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
#
|
4
|
+
###############################################################################
|
5
|
+
#
|
6
|
+
# A simple demo of Pie 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_pie.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']
|
22
|
+
data = [
|
23
|
+
[ 'Apple', 'Cherry', 'Pecan' ],
|
24
|
+
[ 60, 30, 10 ]
|
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::Pie)
|
36
|
+
|
37
|
+
# Add values only. Use the default categories.
|
38
|
+
chart1.add_series(:values => '=Sheet1!$B$2:$B$4')
|
39
|
+
|
40
|
+
###############################################################################
|
41
|
+
#
|
42
|
+
# Example 2. A minimal chart with user specified categories and a series name.
|
43
|
+
#
|
44
|
+
chart2 = workbook.add_chart(:type => Chart::Pie)
|
45
|
+
|
46
|
+
# Configure the series.
|
47
|
+
chart2.add_series(
|
48
|
+
:categories => '=Sheet1!$A$2:$A$4',
|
49
|
+
:values => '=Sheet1!$B$2:$B$4',
|
50
|
+
:name => 'Pie sales data'
|
51
|
+
)
|
52
|
+
|
53
|
+
###############################################################################
|
54
|
+
#
|
55
|
+
# Example 3. Same as previous chart but with an added title.
|
56
|
+
#
|
57
|
+
chart3 = workbook.add_chart(:type => Chart::Pie)
|
58
|
+
|
59
|
+
# Configure the series.
|
60
|
+
chart3.add_series(
|
61
|
+
:categories => '=Sheet1!$A$2:$A$4',
|
62
|
+
:values => '=Sheet1!$B$2:$B$4',
|
63
|
+
:name => 'Pie sales data'
|
64
|
+
)
|
65
|
+
|
66
|
+
# Add a title.
|
67
|
+
chart3.set_title(:name => 'Popular Pie Types')
|
68
|
+
|
69
|
+
###############################################################################
|
70
|
+
#
|
71
|
+
# Example 4. Same as previous chart with a user specified chart sheet name.
|
72
|
+
#
|
73
|
+
chart4 = workbook.add_chart(:name => 'Results Chart', :type => Chart::Pie)
|
74
|
+
|
75
|
+
# Configure the series.
|
76
|
+
chart4.add_series(
|
77
|
+
:categories => '=Sheet1!$A$2:$A$4',
|
78
|
+
:values => '=Sheet1!$B$2:$B$4',
|
79
|
+
:name => 'Pie sales data'
|
80
|
+
)
|
81
|
+
|
82
|
+
# The other chart_*.rb examples add a second series in example 4 but additional
|
83
|
+
# series aren't plotted in a pie chart.
|
84
|
+
|
85
|
+
# Add a title.
|
86
|
+
chart4.set_title(:name => 'Popular Pie Types')
|
87
|
+
|
88
|
+
###############################################################################
|
89
|
+
#
|
90
|
+
# Example 5. Same as Example 3 but as an embedded chart.
|
91
|
+
#
|
92
|
+
chart5 = workbook.add_chart(:type => Chart::Pie, :embedded => 1)
|
93
|
+
|
94
|
+
# Configure the series.
|
95
|
+
chart5.add_series(
|
96
|
+
:categories => '=Sheet1!$A$2:$A$4',
|
97
|
+
:values => '=Sheet1!$B$2:$B$4',
|
98
|
+
:name => 'Pie sales data'
|
99
|
+
)
|
100
|
+
|
101
|
+
# Add a title.
|
102
|
+
chart5.set_title(:name => 'Popular Pie Types')
|
103
|
+
|
104
|
+
# Insert the chart into the main worksheet.
|
105
|
+
worksheet.insert_chart('D2', chart5)
|
106
|
+
|
107
|
+
# File save
|
108
|
+
workbook.close
|
data/examples/chart_scatter.rb
CHANGED
@@ -1,120 +1,121 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
#
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
workbook
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
[
|
24
|
-
[
|
25
|
-
]
|
26
|
-
|
27
|
-
|
28
|
-
worksheet.write('
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
#
|
34
|
-
#
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
:
|
51
|
-
:
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
#
|
57
|
-
#
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
:
|
64
|
-
:
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
chart3.
|
70
|
-
chart3.
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
#
|
75
|
-
#
|
76
|
-
#
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
:
|
83
|
-
:
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
:
|
90
|
-
:
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
chart4.
|
96
|
-
chart4.
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
#
|
101
|
-
#
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
:
|
108
|
-
:
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
chart5.
|
114
|
-
chart5.
|
115
|
-
|
116
|
-
|
117
|
-
worksheet.
|
118
|
-
|
119
|
-
|
120
|
-
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
#
|
4
|
+
###############################################################################
|
5
|
+
#
|
6
|
+
# A simple demo of Scatter charts 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_scatter.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::Scatter)
|
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::Scatter)
|
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::Scatter)
|
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 and with a
|
76
|
+
# user specified chart sheet name.
|
77
|
+
#
|
78
|
+
chart4 = workbook.add_chart(:name => 'Results Chart', :type => Chart::Scatter)
|
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::Scatter, :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
|