write_xlsx 1.02.0 → 1.08.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/Changes +72 -0
- data/README.md +1 -1
- data/examples/chart_data_labels.rb +320 -0
- data/examples/chart_line.rb +85 -10
- data/examples/tables.rb +77 -42
- data/lib/write_xlsx/chart/line.rb +15 -1
- data/lib/write_xlsx/chart/series.rb +100 -0
- data/lib/write_xlsx/chart.rb +155 -33
- data/lib/write_xlsx/drawing.rb +80 -17
- data/lib/write_xlsx/format.rb +5 -5
- data/lib/write_xlsx/package/app.rb +3 -3
- data/lib/write_xlsx/package/comments.rb +4 -4
- data/lib/write_xlsx/package/conditional_format.rb +2 -8
- data/lib/write_xlsx/package/packager.rb +1 -0
- data/lib/write_xlsx/package/relationships.rb +2 -2
- data/lib/write_xlsx/package/styles.rb +42 -11
- data/lib/write_xlsx/package/table.rb +16 -7
- data/lib/write_xlsx/package/vml.rb +20 -19
- data/lib/write_xlsx/sheets.rb +12 -20
- data/lib/write_xlsx/utility.rb +9 -3
- data/lib/write_xlsx/version.rb +1 -1
- data/lib/write_xlsx/workbook.rb +76 -35
- data/lib/write_xlsx/worksheet/data_validation.rb +1 -6
- data/lib/write_xlsx/worksheet.rb +197 -57
- data/test/drawing/{test_write_ext.rb → test_write_xdr_ext.rb} +2 -2
- data/test/perl_output/chart_data_labels.xlsx +0 -0
- data/test/perl_output/chart_line.xlsx +0 -0
- data/test/perl_output/comments2.xlsx +0 -0
- data/test/perl_output/tables.xlsx +0 -0
- data/test/regression/images/red2.png +0 -0
- data/test/regression/test_array_formula04.rb +31 -0
- data/test/regression/test_chart_crossing01.rb +1 -1
- data/test/regression/test_chart_crossing05.rb +46 -0
- data/test/regression/test_chart_crossing06.rb +46 -0
- data/test/regression/test_chart_data_labels26.rb +44 -0
- data/test/regression/test_chart_data_labels27.rb +44 -0
- data/test/regression/test_chart_data_labels28.rb +52 -0
- data/test/regression/test_chart_data_labels29.rb +43 -0
- data/test/regression/test_chart_data_labels30.rb +46 -0
- data/test/regression/test_chart_data_labels31.rb +49 -0
- data/test/regression/test_chart_data_labels32.rb +54 -0
- data/test/regression/test_chart_data_labels33.rb +52 -0
- data/test/regression/test_chart_data_labels34.rb +54 -0
- data/test/regression/test_chart_data_labels35.rb +46 -0
- data/test/regression/test_chart_data_labels36.rb +54 -0
- data/test/regression/test_chart_data_labels37.rb +51 -0
- data/test/regression/test_chart_data_labels38.rb +54 -0
- data/test/regression/test_chart_data_labels39.rb +53 -0
- data/test/regression/test_chart_data_labels40.rb +53 -0
- data/test/regression/test_chart_data_labels41.rb +54 -0
- data/test/regression/test_chart_data_labels42.rb +58 -0
- data/test/regression/test_chart_data_labels43.rb +58 -0
- data/test/regression/test_chart_data_labels44.rb +56 -0
- data/test/regression/test_chart_data_labels45.rb +57 -0
- data/test/regression/test_chart_data_labels46.rb +61 -0
- data/test/regression/test_chart_data_labels47.rb +61 -0
- data/test/regression/test_chart_data_labels48.rb +55 -0
- data/test/regression/test_chart_data_labels49.rb +55 -0
- data/test/regression/test_chart_data_labels50.rb +57 -0
- data/test/regression/test_chart_line05.rb +43 -0
- data/test/regression/test_chart_line06.rb +43 -0
- data/test/regression/test_comment15.rb +28 -0
- data/test/regression/test_comment16.rb +34 -0
- data/test/regression/test_format16.rb +24 -0
- data/test/regression/test_format17.rb +24 -0
- data/test/regression/test_header04.rb +30 -0
- data/test/regression/test_header_image15.rb +36 -0
- data/test/regression/test_header_image16.rb +42 -0
- data/test/regression/test_header_image17.rb +46 -0
- data/test/regression/test_header_image18.rb +48 -0
- data/test/regression/test_header_image19.rb +36 -0
- data/test/regression/test_hyperlink48.rb +31 -0
- data/test/regression/test_hyperlink49.rb +29 -0
- data/test/regression/test_hyperlink50.rb +27 -0
- data/test/regression/test_hyperlink51.rb +27 -0
- data/test/regression/test_ignore_error01.rb +23 -0
- data/test/regression/test_ignore_error02.rb +24 -0
- data/test/regression/test_ignore_error03.rb +26 -0
- data/test/regression/test_ignore_error04.rb +26 -0
- data/test/regression/test_ignore_error05.rb +32 -0
- data/test/regression/test_ignore_error06.rb +32 -0
- data/test/regression/test_image45.rb +2 -1
- data/test/regression/test_image46.rb +1 -1
- data/test/regression/test_image48.rb +32 -0
- data/test/regression/test_image49.rb +38 -0
- data/test/regression/test_image50.rb +24 -0
- data/test/regression/test_image51.rb +30 -0
- data/test/regression/test_image52.rb +26 -0
- data/test/regression/test_image53.rb +26 -0
- data/test/regression/test_image54.rb +26 -0
- data/test/regression/test_image55.rb +27 -0
- data/test/regression/test_object_position12.rb +25 -0
- data/test/regression/test_object_position13.rb +25 -0
- data/test/regression/test_object_position14.rb +25 -0
- data/test/regression/test_object_position15.rb +29 -0
- data/test/regression/test_object_position16.rb +29 -0
- data/test/regression/test_object_position17.rb +29 -0
- data/test/regression/test_object_position18.rb +29 -0
- data/test/regression/test_object_position19.rb +29 -0
- data/test/regression/test_object_position20.rb +29 -0
- data/test/regression/test_protect04.rb +32 -0
- data/test/regression/test_protect05.rb +35 -0
- data/test/regression/test_protect06.rb +35 -0
- data/test/regression/test_protect07.rb +23 -0
- data/test/regression/test_table24.rb +27 -0
- data/test/regression/test_table25.rb +27 -0
- data/test/regression/test_table26.rb +38 -0
- data/test/regression/xlsx_files/array_formula04.xlsx +0 -0
- data/test/regression/xlsx_files/chart_crossing05.xlsx +0 -0
- data/test/regression/xlsx_files/chart_crossing06.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels26.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels27.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels28.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels29.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels30.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels31.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels32.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels33.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels34.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels35.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels36.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels37.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels38.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels39.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels40.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels41.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels42.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels43.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels44.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels45.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels46.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels47.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels48.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels49.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels50.xlsx +0 -0
- data/test/regression/xlsx_files/chart_line05.xlsx +0 -0
- data/test/regression/xlsx_files/chart_line06.xlsx +0 -0
- data/test/regression/xlsx_files/comment15.xlsx +0 -0
- data/test/regression/xlsx_files/comment16.xlsx +0 -0
- data/test/regression/xlsx_files/format16.xlsx +0 -0
- data/test/regression/xlsx_files/format17.xlsx +0 -0
- data/test/regression/xlsx_files/header04.xlsx +0 -0
- data/test/regression/xlsx_files/header_image15.xlsx +0 -0
- data/test/regression/xlsx_files/header_image16.xlsx +0 -0
- data/test/regression/xlsx_files/header_image17.xlsx +0 -0
- data/test/regression/xlsx_files/header_image18.xlsx +0 -0
- data/test/regression/xlsx_files/header_image19.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink46.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink50.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink51.xlsx +0 -0
- data/test/regression/xlsx_files/ignore_error01.xlsx +0 -0
- data/test/regression/xlsx_files/ignore_error02.xlsx +0 -0
- data/test/regression/xlsx_files/ignore_error03.xlsx +0 -0
- data/test/regression/xlsx_files/ignore_error04.xlsx +0 -0
- data/test/regression/xlsx_files/ignore_error05.xlsx +0 -0
- data/test/regression/xlsx_files/ignore_error06.xlsx +0 -0
- data/test/regression/xlsx_files/image45.xlsx +0 -0
- data/test/regression/xlsx_files/image46.xlsx +0 -0
- data/test/regression/xlsx_files/image48.xlsx +0 -0
- data/test/regression/xlsx_files/image49.xlsx +0 -0
- data/test/regression/xlsx_files/image50.xlsx +0 -0
- data/test/regression/xlsx_files/image51.xlsx +0 -0
- data/test/regression/xlsx_files/image52.xlsx +0 -0
- data/test/regression/xlsx_files/image53.xlsx +0 -0
- data/test/regression/xlsx_files/image54.xlsx +0 -0
- data/test/regression/xlsx_files/image55.xlsx +0 -0
- data/test/regression/xlsx_files/object_position12.xlsx +0 -0
- data/test/regression/xlsx_files/object_position13.xlsx +0 -0
- data/test/regression/xlsx_files/object_position14.xlsx +0 -0
- data/test/regression/xlsx_files/object_position15.xlsx +0 -0
- data/test/regression/xlsx_files/object_position16.xlsx +0 -0
- data/test/regression/xlsx_files/object_position17.xlsx +0 -0
- data/test/regression/xlsx_files/object_position18.xlsx +0 -0
- data/test/regression/xlsx_files/object_position19.xlsx +0 -0
- data/test/regression/xlsx_files/object_position20.xlsx +0 -0
- data/test/regression/xlsx_files/protect04.xlsx +0 -0
- data/test/regression/xlsx_files/protect05.xlsx +0 -0
- data/test/regression/xlsx_files/protect06.xlsx +0 -0
- data/test/regression/xlsx_files/protect07.xlsx +0 -0
- data/test/regression/xlsx_files/table24.xlsx +0 -0
- data/test/regression/xlsx_files/table25.xlsx +0 -0
- data/test/regression/xlsx_files/table26.xlsx +0 -0
- data/test/test_example_match.rb +433 -10
- data/test/utility/test_range.rb +20 -0
- data/test/workbook/test_check_sheetname.rb +0 -10
- data/write_xlsx.gemspec +1 -0
- metadata +323 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ab3f33d51239105a5d5c8e0765ada850496c199a370e713353c56d0e0764e4b
|
4
|
+
data.tar.gz: 4b379953050d7a9a5c4151742825c7672c66e60b7c37146531f8d0075d32b634
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 128e52ae31ef667b30e8c6649c1747abf75750e48bd1a7a9a95cedd69ab3699f55755c9ef2686da4252642c662ed871b41ebb90cabe6d23e56f319b958db89b9
|
7
|
+
data.tar.gz: 31b68e29186266b216aaf8dc2035619292999146e79a9388c1d46dcbdd4704d17688586733dc8bb2b6284865340a68d62c7de6cd738a1ed9f6e68c83f388e94e
|
data/.travis.yml
CHANGED
data/Changes
CHANGED
@@ -1,5 +1,77 @@
|
|
1
1
|
Change history of write_xlsx rubygem.
|
2
2
|
|
3
|
+
2021-11-19 v1.08.0
|
4
|
+
|
5
|
+
Added ability to add accessibility options "description" and
|
6
|
+
"decorative" to images via insert_image().
|
7
|
+
|
8
|
+
Added the workbook read_only_recommended() method to set the Excel
|
9
|
+
"Read-only Recommended" option that is available when saving a file.
|
10
|
+
|
11
|
+
Added option to set a chart crossing to 'min' as well as the existing
|
12
|
+
'max' option. The 'min' option isn't available in the Excel interface
|
13
|
+
but can be enabled via VBA.
|
14
|
+
|
15
|
+
Added option to unprotect ranges in protected worksheets.
|
16
|
+
|
17
|
+
Added check, and warning, for worksheet tables with no data row. Either
|
18
|
+
with or without a header row.
|
19
|
+
|
20
|
+
Added ignore_errors() worksheet method to ignore Excel worksheet
|
21
|
+
errors/warnings in user defined ranges.
|
22
|
+
|
23
|
+
Fixed issue where pattern formats without colours where given a default
|
24
|
+
black fill colour.
|
25
|
+
|
26
|
+
Fix issue where custom chart data labels didn't inherit the position for
|
27
|
+
the data labels in the series.
|
28
|
+
|
29
|
+
Fixed issue with relative url links in images.
|
30
|
+
|
31
|
+
Fixed issue where headers/footers were restricted to 254 characters
|
32
|
+
instead of 255.
|
33
|
+
|
34
|
+
2021-02-17 v1.07.0
|
35
|
+
|
36
|
+
Added support for Border, Fill, Pattern and Gradient formatting to chart
|
37
|
+
data labels and chart custom data labels.
|
38
|
+
|
39
|
+
|
40
|
+
2021-02-15 v1.06.0
|
41
|
+
|
42
|
+
Fix for issue where array formulas weren't included in the output file
|
43
|
+
for certain ranges/conditions.
|
44
|
+
|
45
|
+
|
46
|
+
2021-02-15 v1.05.0
|
47
|
+
|
48
|
+
Added support for custom data labels in charts.
|
49
|
+
|
50
|
+
Remove ruby-1.9.3 travil CI check.
|
51
|
+
|
52
|
+
|
53
|
+
2021-02-14 v1.04.0
|
54
|
+
|
55
|
+
Added support for "stacked" and "percent_stacked" Line charts.
|
56
|
+
|
57
|
+
Fix for worksheet objects (charts and images) that are inserted with an
|
58
|
+
offset that starts in a hidden cell.
|
59
|
+
|
60
|
+
Removed error in add_worksheet() for sheet name "History" which is a
|
61
|
+
reserved name in English version of Excel. However, this is an allowed
|
62
|
+
worksheet name in some Excel variants so the warning has been turned into
|
63
|
+
a documentation note instead.
|
64
|
+
|
65
|
+
|
66
|
+
2021-02-13 v1.03.0
|
67
|
+
|
68
|
+
Fix for duplicate images being copied to an Excel::Writer::XLSX
|
69
|
+
file. Excel uses an optimization where it only stores one copy of a
|
70
|
+
repeated/duplicate image in a workbook. WriteXLSX didn't do
|
71
|
+
this which meant that the file size would increase when then was a large
|
72
|
+
number of repeated images. This release fixes that issue and replicates
|
73
|
+
Excel's behaviour.
|
74
|
+
|
3
75
|
2021-02-12 v1.02.0
|
4
76
|
|
5
77
|
Added support for hyperlinks in worksheet images.
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
gem to create a new file in the Excel 2007+ XLSX format, and you can use the
|
7
7
|
same interface as writeexcel gem. write_xlsx is converted from Perl's module
|
8
|
-
[Excel::Writer::XLSX-1.
|
8
|
+
[Excel::Writer::XLSX-1.08](https://github.com/jmcnamara/excel-writer-xlsx/tree/CPAN_1.08)
|
9
9
|
|
10
10
|
## Description
|
11
11
|
|
@@ -0,0 +1,320 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
#######################################################################
|
5
|
+
#
|
6
|
+
# A demo of an various Excel chart data label features that are available
|
7
|
+
# via an WriteXLSX chart.
|
8
|
+
#
|
9
|
+
# Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
|
10
|
+
# convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
|
11
|
+
#
|
12
|
+
|
13
|
+
require 'write_xlsx'
|
14
|
+
|
15
|
+
workbook = WriteXLSX.new('chart_data_labels.xlsx')
|
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 = ['Number', 'Data', 'Text']
|
21
|
+
data = [
|
22
|
+
[ 2, 3, 4, 5, 6, 7 ],
|
23
|
+
[20, 10, 20, 30, 40, 30 ],
|
24
|
+
['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
|
25
|
+
]
|
26
|
+
|
27
|
+
worksheet.write('A1', headings, bold)
|
28
|
+
worksheet.write('A2', data)
|
29
|
+
|
30
|
+
|
31
|
+
#######################################################################
|
32
|
+
#
|
33
|
+
# Example with standard data labels.
|
34
|
+
#
|
35
|
+
|
36
|
+
# Create a Column chart.
|
37
|
+
chart1 = workbook.add_chart(:type => 'column', :embedded => 1)
|
38
|
+
|
39
|
+
# Configure the data series and add the data labels.
|
40
|
+
chart1.add_series(
|
41
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
42
|
+
:values => '=Sheet1!$B$2:$B$7',
|
43
|
+
:data_labels => { :value => 1 }
|
44
|
+
)
|
45
|
+
|
46
|
+
# Add a chart title.
|
47
|
+
chart1.set_title(:name => 'Chart with standard data labels')
|
48
|
+
|
49
|
+
# Turn off the chart legend.
|
50
|
+
chart1.set_legend(:none => 1)
|
51
|
+
|
52
|
+
# Insert the chart into the worksheet (with an offset).
|
53
|
+
worksheet.insert_chart('D2', chart1, { :x_offset => 25, :y_offset => 10 })
|
54
|
+
|
55
|
+
|
56
|
+
#######################################################################
|
57
|
+
#
|
58
|
+
# Example with value and category data labels.
|
59
|
+
#
|
60
|
+
|
61
|
+
# Create a Column chart.
|
62
|
+
chart2 = workbook.add_chart(:type => 'column', :embedded => 1)
|
63
|
+
|
64
|
+
# Configure the data series and add the data labels.
|
65
|
+
chart2.add_series(
|
66
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
67
|
+
:values => '=Sheet1!$B$2:$B$7',
|
68
|
+
:data_labels => { :value => 1, :category => 1 }
|
69
|
+
)
|
70
|
+
|
71
|
+
# Add a chart title.
|
72
|
+
chart2.set_title(:name => 'Category and Value data labels')
|
73
|
+
|
74
|
+
# Turn off the chart legend.
|
75
|
+
chart2.set_legend(:none => 1)
|
76
|
+
|
77
|
+
# Insert the chart into the worksheet (with an offset).
|
78
|
+
worksheet.insert_chart('D18', chart2, { :x_offset => 25, :y_offset => 10 })
|
79
|
+
|
80
|
+
|
81
|
+
#######################################################################
|
82
|
+
#
|
83
|
+
# Example with standard data labels with different font.
|
84
|
+
#
|
85
|
+
|
86
|
+
# Create a Column chart.
|
87
|
+
chart3 = workbook.add_chart(:type => 'column', :embedded => 1)
|
88
|
+
|
89
|
+
# Configure the data series and add the data labels.
|
90
|
+
chart3.add_series(
|
91
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
92
|
+
:values => '=Sheet1!$B$2:$B$7',
|
93
|
+
:data_labels => { :value => 1,
|
94
|
+
:font => {:bold => 1,
|
95
|
+
:color => 'red',
|
96
|
+
:rotation => -30}
|
97
|
+
}
|
98
|
+
)
|
99
|
+
|
100
|
+
# Add a chart title.
|
101
|
+
chart3.set_title(:name => 'Data labels with user defined font')
|
102
|
+
|
103
|
+
# Turn off the chart legend.
|
104
|
+
chart3.set_legend(:none => 1)
|
105
|
+
|
106
|
+
# Insert the chart into the worksheet (with an offset).
|
107
|
+
worksheet.insert_chart('D34', chart3, { :x_offset => 25, :y_offset => 10 })
|
108
|
+
|
109
|
+
|
110
|
+
#######################################################################
|
111
|
+
#
|
112
|
+
# Example with custom string data labels.
|
113
|
+
#
|
114
|
+
|
115
|
+
# Create a Column chart.
|
116
|
+
chart4 = workbook.add_chart(:type => 'column', :embedded => 1)
|
117
|
+
|
118
|
+
# Configure the data series and add the data labels.
|
119
|
+
chart4.add_series(
|
120
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
121
|
+
:values => '=Sheet1!$B$2:$B$7',
|
122
|
+
:data_labels => {
|
123
|
+
:value => 1,
|
124
|
+
:border => {:color => 'red'},
|
125
|
+
:fill => {:color => 'yellow'}
|
126
|
+
}
|
127
|
+
)
|
128
|
+
|
129
|
+
# Add a chart title.
|
130
|
+
chart4.set_title(:name => 'Data labels with formatting')
|
131
|
+
|
132
|
+
# Turn off the chart legend.
|
133
|
+
chart4.set_legend(:none => 1)
|
134
|
+
|
135
|
+
# Insert the chart into the worksheet (with an offset).
|
136
|
+
worksheet.insert_chart('D50', chart4, { :x_offset => 25, :y_offset => 10 })
|
137
|
+
|
138
|
+
|
139
|
+
#######################################################################
|
140
|
+
#
|
141
|
+
# Example with custom string data labels.
|
142
|
+
#
|
143
|
+
|
144
|
+
# Create a Column chart.
|
145
|
+
chart5 = workbook.add_chart( :type => 'column', :embedded => 1 )
|
146
|
+
|
147
|
+
# Some custom labels.
|
148
|
+
custom_labels = [
|
149
|
+
{ :value => 'Amy' },
|
150
|
+
{ :value => 'Bea' },
|
151
|
+
{ :value => 'Eva' },
|
152
|
+
{ :value => 'Fay' },
|
153
|
+
{ :value => 'Liv' },
|
154
|
+
{ :value => 'Una' }
|
155
|
+
]
|
156
|
+
|
157
|
+
# Configure the data series and add the data labels.
|
158
|
+
chart5.add_series(
|
159
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
160
|
+
:values => '=Sheet1!$B$2:$B$7',
|
161
|
+
:data_labels => { :value => 1, :custom => custom_labels }
|
162
|
+
)
|
163
|
+
|
164
|
+
# Add a chart title.
|
165
|
+
chart5.set_title(:name => 'Chart with custom string data labels')
|
166
|
+
|
167
|
+
# Turn off the chart legend.
|
168
|
+
chart5.set_legend(:none => 1)
|
169
|
+
|
170
|
+
# Insert the chart into the worksheet (with an offset).
|
171
|
+
worksheet.insert_chart('D66', chart5, { :x_offset => 25, :y_offset => 10 })
|
172
|
+
|
173
|
+
|
174
|
+
#######################################################################
|
175
|
+
#
|
176
|
+
# Example with custom data labels from cells.
|
177
|
+
#
|
178
|
+
|
179
|
+
# Create a Column chart.
|
180
|
+
chart6 = workbook.add_chart(:type => 'column', :embedded => 1)
|
181
|
+
|
182
|
+
# Some custom labels.
|
183
|
+
custom_labels = [
|
184
|
+
{ :value => '=Sheet1!$C$2' },
|
185
|
+
{ :value => '=Sheet1!$C$3' },
|
186
|
+
{ :value => '=Sheet1!$C$4' },
|
187
|
+
{ :value => '=Sheet1!$C$5' },
|
188
|
+
{ :value => '=Sheet1!$C$6' },
|
189
|
+
{ :value => '=Sheet1!$C$7' }
|
190
|
+
]
|
191
|
+
|
192
|
+
|
193
|
+
# Configure the data series and add the data labels.
|
194
|
+
chart6.add_series(
|
195
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
196
|
+
:values => '=Sheet1!$B$2:$B$7',
|
197
|
+
:data_labels => { :value => 1, :custom => custom_labels }
|
198
|
+
)
|
199
|
+
|
200
|
+
# Add a chart title.
|
201
|
+
chart6.set_title(:name => 'Chart with custom data labels from cells')
|
202
|
+
|
203
|
+
# Turn off the chart legend.
|
204
|
+
chart6.set_legend(:none => 1)
|
205
|
+
|
206
|
+
# Insert the chart into the worksheet (with an offset).
|
207
|
+
worksheet.insert_chart('D82', chart6, { :x_offset => 25, :y_offset => 10 })
|
208
|
+
|
209
|
+
|
210
|
+
#######################################################################
|
211
|
+
#
|
212
|
+
# Example with custom and default data labels.
|
213
|
+
#
|
214
|
+
|
215
|
+
# Create a Column chart.
|
216
|
+
chart7 = workbook.add_chart(:type => 'column', :embedded => 1)
|
217
|
+
|
218
|
+
# Some custom labels. The nil items will get the default value.
|
219
|
+
# We also set a font for the custom items as an extra example.
|
220
|
+
custom_labels = [
|
221
|
+
{ :value => '=Sheet1!$C$2', :font => { :color => 'red' } },
|
222
|
+
nil,
|
223
|
+
{ :value => '=Sheet1!$C$4', :font => { :color => 'red' } },
|
224
|
+
{ :value => '=Sheet1!$C$5', :font => { :color => 'red' } }
|
225
|
+
]
|
226
|
+
|
227
|
+
|
228
|
+
# Configure the data series and add the data labels.
|
229
|
+
chart7.add_series(
|
230
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
231
|
+
:values => '=Sheet1!$B$2:$B$7',
|
232
|
+
:data_labels => { :value => 1, :custom => custom_labels }
|
233
|
+
)
|
234
|
+
|
235
|
+
# Add a chart title.
|
236
|
+
chart7.set_title(:name => 'Mixed custom and default data labels')
|
237
|
+
|
238
|
+
# Turn off the chart legend.
|
239
|
+
chart7.set_legend(:none => 1)
|
240
|
+
|
241
|
+
# Insert the chart into the worksheet (with an offset).
|
242
|
+
worksheet.insert_chart('D98', chart7, { :x_offset => 25, :y_offset => 10 })
|
243
|
+
|
244
|
+
|
245
|
+
#######################################################################
|
246
|
+
#
|
247
|
+
# Example with deleted custom data labels.
|
248
|
+
#
|
249
|
+
|
250
|
+
# Create a Column chart.
|
251
|
+
chart8 = workbook.add_chart(:type => 'column', :embedded => 1)
|
252
|
+
|
253
|
+
# Some deleted custom labels and defaults (nil). This allows us to
|
254
|
+
# highlight certain values such as the minimum and maximum.
|
255
|
+
custom_labels = [
|
256
|
+
{ :delete => 1 },
|
257
|
+
nil,
|
258
|
+
{ :delete => 1 },
|
259
|
+
{ :delete => 1 },
|
260
|
+
nil,
|
261
|
+
{ :delete => 1 }
|
262
|
+
]
|
263
|
+
|
264
|
+
# Configure the data series and add the data labels.
|
265
|
+
chart8.add_series(
|
266
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
267
|
+
:values => '=Sheet1!$B$2:$B$7',
|
268
|
+
:data_labels => { :value => 1, :custom => custom_labels }
|
269
|
+
)
|
270
|
+
|
271
|
+
# Add a chart title.
|
272
|
+
chart8.set_title(:name => 'Chart with deleted data labels')
|
273
|
+
|
274
|
+
# Turn off the chart legend.
|
275
|
+
chart8.set_legend(:none => 1)
|
276
|
+
|
277
|
+
# Insert the chart into the worksheet (with an offset).
|
278
|
+
worksheet.insert_chart('D114', chart8, { :x_offset => 25, :y_offset => 10 })
|
279
|
+
|
280
|
+
#######################################################################
|
281
|
+
#
|
282
|
+
# Example with custom string data labels and formatting.
|
283
|
+
#
|
284
|
+
|
285
|
+
# Create a Column chart.
|
286
|
+
chart9 = workbook.add_chart( :type => 'column', :embedded => 1 )
|
287
|
+
|
288
|
+
# Some custom labels.
|
289
|
+
custom_labels = [
|
290
|
+
{ :value => 'Amy', :border => {:color => 'blue'} },
|
291
|
+
{ :value => 'Bea' },
|
292
|
+
{ :value => 'Eva' },
|
293
|
+
{ :value => 'Fay' },
|
294
|
+
{ :value => 'Liv' },
|
295
|
+
{ :value => 'Una', :fill => {:color => 'green'} }
|
296
|
+
]
|
297
|
+
|
298
|
+
|
299
|
+
# Configure the data series and add the data labels.
|
300
|
+
chart9.add_series(
|
301
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
302
|
+
:values => '=Sheet1!$B$2:$B$7',
|
303
|
+
:data_labels => {
|
304
|
+
:value => 1,
|
305
|
+
:custom => custom_labels,
|
306
|
+
:border => {:color => 'red'},
|
307
|
+
:fill => {:color => 'yellow'}
|
308
|
+
}
|
309
|
+
)
|
310
|
+
|
311
|
+
# Add a chart title.
|
312
|
+
chart9.set_title( :name => 'Chart with custom labels and formatting' )
|
313
|
+
|
314
|
+
# Turn off the chart legend.
|
315
|
+
chart9.set_legend( :none => 1 )
|
316
|
+
|
317
|
+
# Insert the chart into the worksheet (with an offset).
|
318
|
+
worksheet.insert_chart( 'D130', chart9, { :x_offset => 25, :y_offset => 10 } )
|
319
|
+
|
320
|
+
workbook.close
|
data/examples/chart_line.rb
CHANGED
@@ -18,9 +18,9 @@ bold = workbook.add_format(:bold => 1)
|
|
18
18
|
# Add the worksheet data that the charts will refer to.
|
19
19
|
headings = [ 'Number', 'Batch 1', 'Batch 2' ]
|
20
20
|
data = [
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
[ 2, 3, 4, 5, 6, 7 ],
|
22
|
+
[ 10, 40, 50, 20, 10, 50 ],
|
23
|
+
[ 30, 60, 70, 50, 40, 30 ]
|
24
24
|
]
|
25
25
|
|
26
26
|
worksheet.write('A1', headings, bold)
|
@@ -31,21 +31,21 @@ chart = workbook.add_chart(:type => 'line', :embedded => 1)
|
|
31
31
|
|
32
32
|
# Configure the first series.
|
33
33
|
chart.add_series(
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
:name => '=Sheet1!$B$1',
|
35
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
36
|
+
:values => '=Sheet1!$B$2:$B$7'
|
37
37
|
)
|
38
38
|
|
39
39
|
# Configure second series. Note alternative use of array ref to define
|
40
40
|
# ranges: [ sheetname, row_start, row_end, col_start, col_end ].
|
41
41
|
chart.add_series(
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
:name => '=Sheet1!$C$1',
|
43
|
+
:categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
44
|
+
:values => [ 'Sheet1', 1, 6, 2, 2 ]
|
45
45
|
)
|
46
46
|
|
47
47
|
# Add a chart title and some axis labels.
|
48
|
-
chart.set_title(:name
|
48
|
+
chart.set_title(:name => 'Results of sample analysis')
|
49
49
|
chart.set_x_axis(:name => 'Test number')
|
50
50
|
chart.set_y_axis(:name => 'Sample length (mm)')
|
51
51
|
|
@@ -58,4 +58,79 @@ worksheet.insert_chart(
|
|
58
58
|
:x_offset => 25, :y_offset => 10
|
59
59
|
)
|
60
60
|
|
61
|
+
#
|
62
|
+
# Create a stacked chart sub-type
|
63
|
+
#
|
64
|
+
chart2 = workbook.add_chart(
|
65
|
+
:type => 'line',
|
66
|
+
:embedded => 1,
|
67
|
+
:subtype => 'stacked'
|
68
|
+
)
|
69
|
+
|
70
|
+
# Configure the first series.
|
71
|
+
chart2.add_series(
|
72
|
+
:name => '=Sheet1!$B$1',
|
73
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
74
|
+
:values => '=Sheet1!$B$2:$B$7'
|
75
|
+
)
|
76
|
+
|
77
|
+
# Configure second series.
|
78
|
+
chart2.add_series(
|
79
|
+
:name => '=Sheet1!$C$1',
|
80
|
+
:categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
81
|
+
:values => [ 'Sheet1', 1, 6, 2, 2 ]
|
82
|
+
)
|
83
|
+
|
84
|
+
# Add a chart title and some axis labels.
|
85
|
+
chart2.set_title ( :name => 'Stacked Chart' )
|
86
|
+
chart2.set_x_axis( :name => 'Test number' )
|
87
|
+
chart2.set_y_axis( :name => 'Sample length (mm)' )
|
88
|
+
|
89
|
+
# Set an Excel chart style. Blue colors with white outline and shadow.
|
90
|
+
chart2.set_style( 12 )
|
91
|
+
|
92
|
+
# Insert the chart into the worksheet (with an offset).
|
93
|
+
worksheet.insert_chart(
|
94
|
+
'D18', chart2,
|
95
|
+
{ :x_offset => 25, :y_offset => 10 }
|
96
|
+
)
|
97
|
+
|
98
|
+
|
99
|
+
#
|
100
|
+
# Create a percent stacked chart sub-type
|
101
|
+
#
|
102
|
+
chart3 = workbook.add_chart(
|
103
|
+
:type => 'line',
|
104
|
+
:embedded => 1,
|
105
|
+
:subtype => 'percent_stacked'
|
106
|
+
)
|
107
|
+
|
108
|
+
# Configure the first series.
|
109
|
+
chart3.add_series(
|
110
|
+
:name => '=Sheet1!$B$1',
|
111
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
112
|
+
:values => '=Sheet1!$B$2:$B$7'
|
113
|
+
)
|
114
|
+
|
115
|
+
# Configure second series.
|
116
|
+
chart3.add_series(
|
117
|
+
:name => '=Sheet1!$C$1',
|
118
|
+
:categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
119
|
+
:values => [ 'Sheet1', 1, 6, 2, 2 ]
|
120
|
+
)
|
121
|
+
|
122
|
+
# Add a chart title and some axis labels.
|
123
|
+
chart3.set_title ( :name => 'Percent Stacked Chart' )
|
124
|
+
chart3.set_x_axis( :name => 'Test number' )
|
125
|
+
chart3.set_y_axis( :name => 'Sample length (mm)' )
|
126
|
+
|
127
|
+
# Set an Excel chart style. Blue colors with white outline and shadow.
|
128
|
+
chart3.set_style( 13 )
|
129
|
+
|
130
|
+
# Insert the chart into the worksheet (with an offset).
|
131
|
+
worksheet.insert_chart(
|
132
|
+
'D34', chart3,
|
133
|
+
{ :x_offset => 25, :y_offset => 10 }
|
134
|
+
)
|
135
|
+
|
61
136
|
workbook.close
|