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_stock.rb
CHANGED
@@ -1,147 +1,148 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
#
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
['2009-08-
|
40
|
-
['2009-08-
|
41
|
-
['2009-08-
|
42
|
-
['2009-08-
|
43
|
-
['2009-08-
|
44
|
-
['2009-08-
|
45
|
-
['2009-08-
|
46
|
-
['2009-08-
|
47
|
-
]
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
row
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
worksheet.write(row, col
|
61
|
-
row
|
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
|
-
chart1.
|
102
|
-
chart1.
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
#
|
107
|
-
#
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
#
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
:
|
117
|
-
:
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
:
|
123
|
-
:
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
:
|
129
|
-
:
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
:
|
135
|
-
:
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
chart2.
|
141
|
-
chart2.
|
142
|
-
|
143
|
-
|
144
|
-
worksheet.
|
145
|
-
|
146
|
-
|
147
|
-
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
#
|
4
|
+
###############################################################################
|
5
|
+
#
|
6
|
+
# A simple demo of Stock charts in Spreadsheet::WriteExcel.
|
7
|
+
#
|
8
|
+
# reverse('©'), January 2010, 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
|
+
workbook = WriteExcel.new('chart_stock.xls')
|
16
|
+
worksheet = workbook.add_worksheet
|
17
|
+
|
18
|
+
###############################################################################
|
19
|
+
#
|
20
|
+
# Set up the data worksheet that the charts will refer to. We read the example
|
21
|
+
# data from the __DATA__ section at the end of the file. This simulates
|
22
|
+
# reading the data from a database or other source.
|
23
|
+
#
|
24
|
+
# The default Excel Stock chart is an Open-High-Low-Close chart. Therefore
|
25
|
+
# we will need data for each of those series.
|
26
|
+
#
|
27
|
+
# The layout of the __DATA__ section is similar to the layout of the worksheet.
|
28
|
+
#
|
29
|
+
|
30
|
+
# Add some formats.
|
31
|
+
bold = workbook.add_format(:bold => 1)
|
32
|
+
date_format = workbook.add_format(:num_format => 'dd/mm/yyyy')
|
33
|
+
|
34
|
+
# Increase the width of the column used for date to make it clearer.
|
35
|
+
worksheet.set_column('A:A', 12)
|
36
|
+
|
37
|
+
stock_data = [
|
38
|
+
%w(Date Open High Low Close),
|
39
|
+
['2009-08-19', 100.00, 104.06, 95.96, 100.34],
|
40
|
+
['2009-08-20', 101.01, 109.08, 100.50, 108.31],
|
41
|
+
['2009-08-23', 110.75, 113.48, 109.05, 109.40],
|
42
|
+
['2009-08-24', 111.24, 111.60, 103.57, 104.87],
|
43
|
+
['2009-08-25', 104.96, 108.00, 103.88, 106.00],
|
44
|
+
['2009-08-26', 104.95, 107.95, 104.66, 107.91],
|
45
|
+
['2009-08-27', 108.10, 108.62, 105.69, 106.15],
|
46
|
+
['2009-08-30', 105.28, 105.49, 102.01, 102.01],
|
47
|
+
['2009-08-31', 102.30, 103.71, 102.16, 102.37]
|
48
|
+
]
|
49
|
+
|
50
|
+
# Write the data to the worksheet.
|
51
|
+
row = 0
|
52
|
+
col = 0
|
53
|
+
|
54
|
+
headers = stock_data.shift
|
55
|
+
worksheet.write(row, col, headers, bold)
|
56
|
+
row += 1
|
57
|
+
|
58
|
+
stock_data.each do |data|
|
59
|
+
date = data.shift
|
60
|
+
worksheet.write(row, col, date, date_format)
|
61
|
+
worksheet.write(row, col + 1, data)
|
62
|
+
row += 1
|
63
|
+
end
|
64
|
+
|
65
|
+
###############################################################################
|
66
|
+
#
|
67
|
+
# Example 1. A default Open-High-Low-Close chart with series names, axes labels
|
68
|
+
# and a title.
|
69
|
+
#
|
70
|
+
|
71
|
+
chart1 = workbook.add_chart(:type => Chart::Stock)
|
72
|
+
|
73
|
+
# Add a series for each of the Open-High-Low-Close columns. The categories are
|
74
|
+
# the dates in the first column.
|
75
|
+
|
76
|
+
chart1.add_series(
|
77
|
+
:categories => '=Sheet1!$A$2:$A$10',
|
78
|
+
:values => '=Sheet1!$B$2:$B$10',
|
79
|
+
:name => 'Open'
|
80
|
+
)
|
81
|
+
|
82
|
+
chart1.add_series(
|
83
|
+
:categories => '=Sheet1!$A$2:$A$10',
|
84
|
+
:values => '=Sheet1!$C$2:$C$10',
|
85
|
+
:name => 'High'
|
86
|
+
)
|
87
|
+
|
88
|
+
chart1.add_series(
|
89
|
+
:categories => '=Sheet1!$A$2:$A$10',
|
90
|
+
:values => '=Sheet1!$D$2:$D$10',
|
91
|
+
:name => 'Low'
|
92
|
+
)
|
93
|
+
|
94
|
+
chart1.add_series(
|
95
|
+
:categories => '=Sheet1!$A$2:$A$10',
|
96
|
+
:values => '=Sheet1!$E$2:$E$10',
|
97
|
+
:name => 'Close'
|
98
|
+
)
|
99
|
+
|
100
|
+
# Add a chart title and axes labels.
|
101
|
+
chart1.set_title(:name => 'Open-High-Low-Close')
|
102
|
+
chart1.set_x_axis(:name => 'Date')
|
103
|
+
chart1.set_y_axis(:name => 'Share price')
|
104
|
+
|
105
|
+
###############################################################################
|
106
|
+
#
|
107
|
+
# Example 2. Same as the previous as an embedded chart.
|
108
|
+
#
|
109
|
+
|
110
|
+
chart2 = workbook.add_chart(:type => Chart::Stock, :embedded => 1)
|
111
|
+
|
112
|
+
# Add a series for each of the Open-High-Low-Close columns. The categories are
|
113
|
+
# the dates in the first column.
|
114
|
+
|
115
|
+
chart2.add_series(
|
116
|
+
:categories => '=Sheet1!$A$2:$A$10',
|
117
|
+
:values => '=Sheet1!$B$2:$B$10',
|
118
|
+
:name => 'Open'
|
119
|
+
)
|
120
|
+
|
121
|
+
chart2.add_series(
|
122
|
+
:categories => '=Sheet1!$A$2:$A$10',
|
123
|
+
:values => '=Sheet1!$C$2:$C$10',
|
124
|
+
:name => 'High'
|
125
|
+
)
|
126
|
+
|
127
|
+
chart2.add_series(
|
128
|
+
:categories => '=Sheet1!$A$2:$A$10',
|
129
|
+
:values => '=Sheet1!$D$2:$D$10',
|
130
|
+
:name => 'Low'
|
131
|
+
)
|
132
|
+
|
133
|
+
chart2.add_series(
|
134
|
+
:categories => '=Sheet1!$A$2:$A$10',
|
135
|
+
:values => '=Sheet1!$E$2:$E$10',
|
136
|
+
:name => 'Close'
|
137
|
+
)
|
138
|
+
|
139
|
+
# Add a chart title and axes labels.
|
140
|
+
chart2.set_title(:name => 'Open-High-Low-Close')
|
141
|
+
chart2.set_x_axis(:name => 'Date')
|
142
|
+
chart2.set_y_axis(:name => 'Share price')
|
143
|
+
|
144
|
+
# Insert the chart into the main worksheet.
|
145
|
+
worksheet.insert_chart('G2', chart2)
|
146
|
+
|
147
|
+
# File save
|
148
|
+
workbook.close
|
data/examples/chess.rb
CHANGED
data/examples/colors.rb
CHANGED
data/examples/comments1.rb
CHANGED
data/examples/comments2.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/ruby -w
|
2
|
+
# -*- coding: utf-8 -*-
|
2
3
|
|
3
4
|
###############################################################################
|
4
5
|
#
|
@@ -59,7 +60,7 @@
|
|
59
60
|
worksheet1.write('C6', cell_text, text_wrap)
|
60
61
|
worksheet1.write_comment('C6', comment, :encoding => 1)
|
61
62
|
|
62
|
-
# UTF-8 string
|
63
|
+
# UTF-8 string.
|
63
64
|
worksheet1.set_row(8, 50)
|
64
65
|
cell_text = 'This is a UTF-8 string.'
|
65
66
|
comment = '☺' # chr 0x263a in perl.
|
@@ -306,7 +307,7 @@
|
|
306
307
|
worksheet7.write_comment(cell, comment, :author => author,
|
307
308
|
:author_encoding => 1)
|
308
309
|
|
309
|
-
# UTF-8 string
|
310
|
+
# UTF-8 string.
|
310
311
|
author = '☺' # smiley
|
311
312
|
cell = 'C12'
|
312
313
|
cell_text = "Move the mouse over this cell and you will see 'Cell commented " +
|
data/examples/copyformat.rb
CHANGED
data/examples/data_validate.rb
CHANGED
data/examples/date_time.rb
CHANGED
data/examples/defined_name.rb
CHANGED
data/examples/demo.rb
CHANGED
data/examples/diag_border.rb
CHANGED
data/examples/formats.rb
CHANGED
data/examples/formula_result.rb
CHANGED
data/examples/header.rb
CHANGED
data/examples/hide_sheet.rb
CHANGED
data/examples/hyperlink.rb
CHANGED
data/examples/images.rb
CHANGED
data/examples/indent.rb
CHANGED
data/examples/merge1.rb
CHANGED
data/examples/merge2.rb
CHANGED