write_xlsx 1.09.5 → 1.10.1
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -1
- data/Changes +8 -0
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/examples/autofilter.rb +39 -10
- data/examples/chart_area.rb +12 -12
- data/examples/chart_bar.rb +12 -12
- data/examples/chart_clustered.rb +12 -12
- data/examples/chart_column.rb +12 -12
- data/examples/chart_combined.rb +25 -25
- data/examples/chart_data_labels.rb +99 -99
- data/examples/chart_data_table.rb +25 -25
- data/examples/chart_data_tools.rb +50 -50
- data/examples/chart_doughnut.rb +29 -29
- data/examples/chart_gauge.rb +18 -18
- data/examples/chart_line.rb +32 -32
- data/examples/chart_pareto.rb +16 -16
- data/examples/chart_pie.rb +17 -17
- data/examples/chart_radar.rb +38 -38
- data/examples/chart_scatter.rb +12 -12
- data/examples/chart_secondary_axis.rb +13 -13
- data/examples/chart_stock.rb +12 -12
- data/examples/chart_styles.rb +5 -5
- data/examples/colors.rb +11 -11
- data/examples/comments2.rb +15 -15
- data/examples/conditional_format.rb +74 -74
- data/examples/data_validate.rb +64 -64
- data/examples/date_time.rb +3 -3
- data/examples/demo.rb +14 -14
- data/examples/diag_border.rb +6 -6
- data/examples/dynamic_arrays.rb +247 -0
- data/examples/formats.rb +10 -10
- data/examples/hyperlink1.rb +4 -4
- data/examples/ignore_errors.rb +2 -2
- data/examples/indent.rb +2 -2
- data/examples/lambda.rb +43 -0
- data/examples/macros.rb +4 -4
- data/examples/merge1.rb +1 -1
- data/examples/merge2.rb +9 -9
- data/examples/merge3.rb +5 -5
- data/examples/merge4.rb +20 -20
- data/examples/merge5.rb +18 -18
- data/examples/merge6.rb +7 -7
- data/examples/outline.rb +1 -1
- data/examples/outline_collapsed.rb +1 -1
- data/examples/panes.rb +4 -4
- data/examples/properties.rb +9 -9
- data/examples/protection.rb +2 -2
- data/examples/rich_strings.rb +6 -6
- data/examples/shape1.rb +7 -7
- data/examples/shape2.rb +16 -16
- data/examples/shape3.rb +5 -5
- data/examples/shape4.rb +7 -7
- data/examples/shape5.rb +7 -7
- data/examples/shape6.rb +7 -7
- data/examples/shape7.rb +10 -10
- data/examples/shape8.rb +10 -10
- data/examples/shape_all.rb +4 -4
- data/examples/sparklines1.rb +11 -11
- data/examples/sparklines2.rb +76 -76
- data/examples/tables.rb +87 -87
- data/examples/watermark.png +0 -0
- data/examples/watermark.rb +26 -0
- data/lib/write_xlsx/chart/bar.rb +4 -4
- data/lib/write_xlsx/chart/line.rb +1 -1
- data/lib/write_xlsx/chart/radar.rb +2 -2
- data/lib/write_xlsx/chart/scatter.rb +4 -4
- data/lib/write_xlsx/chart/series.rb +27 -27
- data/lib/write_xlsx/chart/stock.rb +5 -5
- data/lib/write_xlsx/chart.rb +31 -30
- data/lib/write_xlsx/chartsheet.rb +1 -0
- data/lib/write_xlsx/col_name.rb +1 -0
- data/lib/write_xlsx/colors.rb +20 -19
- data/lib/write_xlsx/compatibility.rb +1 -0
- data/lib/write_xlsx/drawing.rb +20 -10
- data/lib/write_xlsx/format.rb +5 -0
- data/lib/write_xlsx/formats.rb +1 -0
- data/lib/write_xlsx/gradient.rb +2 -0
- data/lib/write_xlsx/package/app.rb +1 -0
- data/lib/write_xlsx/package/button.rb +6 -2
- data/lib/write_xlsx/package/comments.rb +3 -1
- data/lib/write_xlsx/package/conditional_format.rb +4 -3
- data/lib/write_xlsx/package/content_types.rb +1 -0
- data/lib/write_xlsx/package/core.rb +1 -0
- data/lib/write_xlsx/package/custom.rb +1 -0
- data/lib/write_xlsx/package/metadata.rb +1 -0
- data/lib/write_xlsx/package/packager.rb +1 -0
- data/lib/write_xlsx/package/relationships.rb +1 -0
- data/lib/write_xlsx/package/shared_strings.rb +1 -1
- data/lib/write_xlsx/package/styles.rb +1 -0
- data/lib/write_xlsx/package/table.rb +9 -8
- data/lib/write_xlsx/package/theme.rb +1 -0
- data/lib/write_xlsx/package/vml.rb +1 -0
- data/lib/write_xlsx/package/xml_writer_simple.rb +21 -2
- data/lib/write_xlsx/shape.rb +6 -5
- data/lib/write_xlsx/sheets.rb +2 -1
- data/lib/write_xlsx/sparkline.rb +287 -286
- data/lib/write_xlsx/utility.rb +25 -26
- data/lib/write_xlsx/version.rb +3 -1
- data/lib/write_xlsx/workbook.rb +20 -20
- data/lib/write_xlsx/worksheet/cell_data.rb +53 -63
- data/lib/write_xlsx/worksheet/data_validation.rb +1 -0
- data/lib/write_xlsx/worksheet/hyperlink.rb +3 -2
- data/lib/write_xlsx/worksheet/page_setup.rb +1 -0
- data/lib/write_xlsx/worksheet.rb +287 -74
- data/lib/write_xlsx/zip_file_utils.rb +1 -0
- data/lib/write_xlsx.rb +1 -0
- data/write_xlsx.gemspec +1 -0
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66e9354b51872770af7121d5581615b53c0cb3b7e86c221b0ecee60fe54dae4b
|
4
|
+
data.tar.gz: 97d6ae9ed6dee9e57e98981e105da155ef405fd5ea40ea17e8057871f02d90d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a86f539563acd7da100be9fb11e1e3da99c1985200e21eaa91ca9db3f69ea130038f0ecead40ea0ba6efcc5b4f433dcd4acf039006faa65adb60ed88d0d5f005
|
7
|
+
data.tar.gz: f98a3ac1110600e8e2c578127f85a804c1237d44069481f6c0baacc27ff6f21eddbb96f063c544239730ba059a16f7637f39ebfd902f3cc87be4995401bf303b
|
data/.rubocop.yml
CHANGED
@@ -59,6 +59,7 @@ Metrics/MethodLength:
|
|
59
59
|
|
60
60
|
Metrics/ParameterLists:
|
61
61
|
Max: 12
|
62
|
+
MaxOptionalParameters: 6
|
62
63
|
|
63
64
|
Metrics/PerceivedComplexity:
|
64
65
|
Max: 50
|
@@ -89,7 +90,8 @@ Style/FormatStringToken:
|
|
89
90
|
EnforcedStyle: unannotated
|
90
91
|
|
91
92
|
Style/HashSyntax:
|
92
|
-
|
93
|
+
EnforceStyle: ruby19_no_mixed_keys
|
94
|
+
EnforcedShorthandSyntax: either
|
93
95
|
|
94
96
|
Style/NumericLiterals:
|
95
97
|
MinDigits: 10
|
@@ -100,6 +102,9 @@ Style/OptionalBooleanParameter:
|
|
100
102
|
Style/RaiseArgs:
|
101
103
|
Enabled: false
|
102
104
|
|
105
|
+
Style/SlicingWithRange:
|
106
|
+
Enabled: false
|
107
|
+
|
103
108
|
Style/StringLiterals:
|
104
109
|
Enabled: false
|
105
110
|
|
data/Changes
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
Change history of write_xlsx rubygem.
|
2
2
|
|
3
|
+
2023-01-31 v1.10.1
|
4
|
+
Fixed PR #99. Remove range [1..] style to work on Ruby 2.5.
|
5
|
+
|
6
|
+
2023-01-29 v.1.10.0
|
7
|
+
Ruby version 2.5.0 or later are required.
|
8
|
+
|
9
|
+
Added support for new Excel 365 dynamic functions.
|
10
|
+
|
3
11
|
2023-01-18 v1.09.5
|
4
12
|
Fixed issue #92. Worksheet#write raises with Time instance token.
|
5
13
|
|
data/LICENSE.txt
CHANGED
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
|
8
|
+
[Excel::Writer::XLSX](https://github.com/jmcnamara/excel-writer-xlsx)
|
9
9
|
|
10
10
|
## Description
|
11
11
|
|
data/examples/autofilter.rb
CHANGED
@@ -22,8 +22,9 @@ worksheet3 = workbook.add_worksheet
|
|
22
22
|
worksheet4 = workbook.add_worksheet
|
23
23
|
worksheet5 = workbook.add_worksheet
|
24
24
|
worksheet6 = workbook.add_worksheet
|
25
|
+
worksheet7 = workbook.add_worksheet
|
25
26
|
|
26
|
-
bold = workbook.add_format(:
|
27
|
+
bold = workbook.add_format(bold: 1)
|
27
28
|
|
28
29
|
# Extract the data embedded at the end of this file.
|
29
30
|
headings = DATA.gets.split
|
@@ -127,14 +128,12 @@ end
|
|
127
128
|
###############################################################################
|
128
129
|
#
|
129
130
|
#
|
130
|
-
# Example 5. Autofilter with filter
|
131
|
+
# Example 5. Autofilter with filter list condition in one of the columns.
|
131
132
|
#
|
132
133
|
|
133
|
-
# Create a blank cell in our test data.
|
134
|
-
data[5][0] = ''
|
135
|
-
|
136
134
|
worksheet5.autofilter('A1:D51')
|
137
|
-
|
135
|
+
|
136
|
+
worksheet5.filter_column_list('A', %w[East North South])
|
138
137
|
|
139
138
|
#
|
140
139
|
# Hide the rows that don't match the filter criteria.
|
@@ -144,7 +143,7 @@ row = 1
|
|
144
143
|
data.each do |row_data|
|
145
144
|
region = row_data[0]
|
146
145
|
|
147
|
-
worksheet5.set_row(row, nil, nil, 1) unless
|
146
|
+
worksheet5.set_row(row, nil, nil, 1) unless %w[East North South].include?(region)
|
148
147
|
|
149
148
|
worksheet5.write(row, 0, row_data)
|
150
149
|
row += 1
|
@@ -153,11 +152,14 @@ end
|
|
153
152
|
###############################################################################
|
154
153
|
#
|
155
154
|
#
|
156
|
-
# Example 6. Autofilter with filter for
|
155
|
+
# Example 6. Autofilter with filter for blanks.
|
157
156
|
#
|
158
157
|
|
158
|
+
# Create a blank cell in our test data.
|
159
|
+
data[5][0] = ''
|
160
|
+
|
159
161
|
worksheet6.autofilter('A1:D51')
|
160
|
-
worksheet6.filter_column('A', 'x
|
162
|
+
worksheet6.filter_column('A', 'x == Blanks')
|
161
163
|
|
162
164
|
#
|
163
165
|
# Hide the rows that don't match the filter criteria.
|
@@ -167,7 +169,7 @@ row = 1
|
|
167
169
|
data.each do |row_data|
|
168
170
|
region = row_data[0]
|
169
171
|
|
170
|
-
worksheet6.set_row(row, nil, nil, 1) unless region
|
172
|
+
worksheet6.set_row(row, nil, nil, 1) unless region == ''
|
171
173
|
|
172
174
|
worksheet6.write(row, 0, row_data)
|
173
175
|
row += 1
|
@@ -175,6 +177,33 @@ end
|
|
175
177
|
|
176
178
|
workbook.close
|
177
179
|
|
180
|
+
###############################################################################
|
181
|
+
#
|
182
|
+
#
|
183
|
+
# Example 7. Autofilter with filter for non-blanks.
|
184
|
+
#
|
185
|
+
|
186
|
+
worksheet7.autofilter('A1:D51')
|
187
|
+
worksheet7.filter_column('A', 'x == NonBlanks')
|
188
|
+
|
189
|
+
#
|
190
|
+
# Hide the rows that don't match the filter criteria.
|
191
|
+
#
|
192
|
+
row = 1
|
193
|
+
|
194
|
+
data.each do |row_data|
|
195
|
+
region = row_data[0]
|
196
|
+
|
197
|
+
worksheet7.set_row(row, nil, nil, 1) unless region != ''
|
198
|
+
|
199
|
+
worksheet7.write(row, 0, row_data)
|
200
|
+
row += 1
|
201
|
+
end
|
202
|
+
|
203
|
+
workbook.close
|
204
|
+
|
205
|
+
|
206
|
+
|
178
207
|
__END__
|
179
208
|
Region Item Volume Month
|
180
209
|
East Apple 9000 July
|
data/examples/chart_area.rb
CHANGED
@@ -13,7 +13,7 @@ require 'write_xlsx'
|
|
13
13
|
|
14
14
|
workbook = WriteXLSX.new('chart_area.xlsx')
|
15
15
|
worksheet = workbook.add_worksheet
|
16
|
-
bold = workbook.add_format(:
|
16
|
+
bold = workbook.add_format(bold: 1)
|
17
17
|
|
18
18
|
# Add the worksheet data that the charts will refer to.
|
19
19
|
headings = ['Number', 'Batch 1', 'Batch 2']
|
@@ -27,27 +27,27 @@ worksheet.write('A1', headings, bold)
|
|
27
27
|
worksheet.write('A2', data)
|
28
28
|
|
29
29
|
# Create a new chart object. In this case an embedded chart.
|
30
|
-
chart = workbook.add_chart(:
|
30
|
+
chart = workbook.add_chart(type: 'area', 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(:
|
49
|
-
chart.set_x_axis(:
|
50
|
-
chart.set_y_axis(:
|
48
|
+
chart.set_title(name: 'Results of sample analysis')
|
49
|
+
chart.set_x_axis(name: 'Test number')
|
50
|
+
chart.set_y_axis(name: 'Sample length (mm)')
|
51
51
|
|
52
52
|
# Set an Excel chart style. Blue colors with white outline and shadow.
|
53
53
|
chart.set_style(11)
|
@@ -55,7 +55,7 @@ chart.set_style(11)
|
|
55
55
|
# Insert the chart into the worksheet (with an offset).
|
56
56
|
worksheet.insert_chart(
|
57
57
|
'D2', chart,
|
58
|
-
:
|
58
|
+
x_offset: 25, y_offset: 10
|
59
59
|
)
|
60
60
|
|
61
61
|
workbook.close
|
data/examples/chart_bar.rb
CHANGED
@@ -13,7 +13,7 @@ require 'write_xlsx'
|
|
13
13
|
|
14
14
|
workbook = WriteXLSX.new('chart_bar.xlsx')
|
15
15
|
worksheet = workbook.add_worksheet
|
16
|
-
bold = workbook.add_format(:
|
16
|
+
bold = workbook.add_format(bold: 1)
|
17
17
|
|
18
18
|
# Add the worksheet data that the charts will refer to.
|
19
19
|
headings = ['Number', 'Batch 1', 'Batch 2']
|
@@ -27,27 +27,27 @@ worksheet.write('A1', headings, bold)
|
|
27
27
|
worksheet.write('A2', data)
|
28
28
|
|
29
29
|
# Create a new chart object. In this case an embedded chart.
|
30
|
-
chart = workbook.add_chart(:
|
30
|
+
chart = workbook.add_chart(type: 'bar', 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(:
|
49
|
-
chart.set_x_axis(:
|
50
|
-
chart.set_y_axis(:
|
48
|
+
chart.set_title(name: 'Results of sample analysis')
|
49
|
+
chart.set_x_axis(name: 'Test number')
|
50
|
+
chart.set_y_axis(name: 'Sample length (mm)')
|
51
51
|
|
52
52
|
# Set an Excel chart style. Blue colors with white outline and shadow.
|
53
53
|
chart.set_style(11)
|
@@ -55,7 +55,7 @@ chart.set_style(11)
|
|
55
55
|
# Insert the chart into the worksheet (with an offset).
|
56
56
|
worksheet.insert_chart(
|
57
57
|
'D2', chart,
|
58
|
-
:
|
58
|
+
x_offset: 25, y_offset: 10
|
59
59
|
)
|
60
60
|
|
61
61
|
workbook.close
|
data/examples/chart_clustered.rb
CHANGED
@@ -12,7 +12,7 @@ require 'write_xlsx'
|
|
12
12
|
|
13
13
|
workbook = WriteXLSX.new('chart_clustered.xlsx')
|
14
14
|
worksheet = workbook.add_worksheet
|
15
|
-
bold = workbook.add_format(:
|
15
|
+
bold = workbook.add_format(bold: 1)
|
16
16
|
|
17
17
|
# Add the worksheet data that the charts will refer to.
|
18
18
|
headings = ['Types', 'Sub Type', 'Value 1', 'Value 2', 'Value 3']
|
@@ -28,34 +28,34 @@ worksheet.write('A1', headings, bold)
|
|
28
28
|
worksheet.write_col('A2', data)
|
29
29
|
|
30
30
|
# Create a new chart object. In this case an embedded chart.
|
31
|
-
chart = workbook.add_chart(:
|
31
|
+
chart = workbook.add_chart(type: 'column', embedded: 1)
|
32
32
|
|
33
33
|
# Configure the series. Note, that the categories are 2D ranges (from column A
|
34
34
|
# to column B). This creates the clusters. The series are shown as formula
|
35
35
|
# strings for clarity but you can also use the array syntax. See the docs.
|
36
36
|
chart.add_series(
|
37
|
-
:
|
38
|
-
:
|
39
|
-
:
|
37
|
+
name: '=Sheet1!$C$1',
|
38
|
+
categories: '=Sheet1!$A$2:$B$6',
|
39
|
+
values: '=Sheet1!$C$2:$C$6'
|
40
40
|
)
|
41
41
|
|
42
42
|
chart.add_series(
|
43
|
-
:
|
44
|
-
:
|
45
|
-
:
|
43
|
+
name: '=Sheet1!$D$1',
|
44
|
+
categories: '=Sheet1!$A$2:$B$6',
|
45
|
+
values: '=Sheet1!$D$2:$D$6'
|
46
46
|
)
|
47
47
|
|
48
48
|
chart.add_series(
|
49
|
-
:
|
50
|
-
:
|
51
|
-
:
|
49
|
+
name: '=Sheet1!$E$1',
|
50
|
+
categories: '=Sheet1!$A$2:$B$6',
|
51
|
+
values: '=Sheet1!$E$2:$E$6'
|
52
52
|
)
|
53
53
|
|
54
54
|
# Set the Excel chart style.
|
55
55
|
chart.set_style(37)
|
56
56
|
|
57
57
|
# Turn off the legend.
|
58
|
-
chart.set_legend(:
|
58
|
+
chart.set_legend(position: 'none')
|
59
59
|
|
60
60
|
# Insert the chart into the worksheet.
|
61
61
|
worksheet.insert_chart('G3', chart)
|
data/examples/chart_column.rb
CHANGED
@@ -13,7 +13,7 @@ require 'write_xlsx'
|
|
13
13
|
|
14
14
|
workbook = WriteXLSX.new('chart_column.xlsx')
|
15
15
|
worksheet = workbook.add_worksheet
|
16
|
-
bold = workbook.add_format(:
|
16
|
+
bold = workbook.add_format(bold: 1)
|
17
17
|
|
18
18
|
# Add the worksheet data that the charts will refer to.
|
19
19
|
headings = ['Number', 'Batch 1', 'Batch 2']
|
@@ -27,27 +27,27 @@ worksheet.write('A1', headings, bold)
|
|
27
27
|
worksheet.write('A2', data)
|
28
28
|
|
29
29
|
# Create a new chart object. In this case an embedded chart.
|
30
|
-
chart = workbook.add_chart(:
|
30
|
+
chart = workbook.add_chart(type: 'column', 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(:
|
49
|
-
chart.set_x_axis(:
|
50
|
-
chart.set_y_axis(:
|
48
|
+
chart.set_title(name: 'Results of sample analysis')
|
49
|
+
chart.set_x_axis(name: 'Test number')
|
50
|
+
chart.set_y_axis(name: 'Sample length (mm)')
|
51
51
|
|
52
52
|
# Set an Excel chart style. Blue colors with white outline and shadow.
|
53
53
|
chart.set_style(11)
|
@@ -55,7 +55,7 @@ chart.set_style(11)
|
|
55
55
|
# Insert the chart into the worksheet (with an offset).
|
56
56
|
worksheet.insert_chart(
|
57
57
|
'D2', chart,
|
58
|
-
:
|
58
|
+
x_offset: 25, y_offset: 10
|
59
59
|
)
|
60
60
|
|
61
61
|
workbook.close
|
data/examples/chart_combined.rb
CHANGED
@@ -13,7 +13,7 @@ require 'write_xlsx'
|
|
13
13
|
|
14
14
|
workbook = WriteXLSX.new('chart_combined.xlsx')
|
15
15
|
worksheet = workbook.add_worksheet
|
16
|
-
bold = workbook.add_format(:
|
16
|
+
bold = workbook.add_format(bold: 1)
|
17
17
|
|
18
18
|
# Add the worksheet data that the charts will refer to.
|
19
19
|
headings = ['Number', 'Batch 1', 'Batch 2']
|
@@ -32,23 +32,23 @@ worksheet.write('A2', data)
|
|
32
32
|
#
|
33
33
|
|
34
34
|
# Create a new column chart. This will use this as the primary chart.
|
35
|
-
column_chart1 = workbook.add_chart(:
|
35
|
+
column_chart1 = workbook.add_chart(type: 'column', embedded: 1)
|
36
36
|
|
37
37
|
# Configure the data series for the primary chart.
|
38
38
|
column_chart1.add_series(
|
39
|
-
:
|
40
|
-
:
|
41
|
-
:
|
39
|
+
name: '=Sheet1!$B$1',
|
40
|
+
categories: '=Sheet1!$A$2:$A$7',
|
41
|
+
values: '=Sheet1!$B$2:$B$7'
|
42
42
|
)
|
43
43
|
|
44
44
|
# Create a new column chart. This will use this as the secondary chart.
|
45
|
-
line_chart1 = workbook.add_chart(:
|
45
|
+
line_chart1 = workbook.add_chart(type: 'line', embedded: 1)
|
46
46
|
|
47
47
|
# Configure the data series for the secondary chart.
|
48
48
|
line_chart1.add_series(
|
49
|
-
:
|
50
|
-
:
|
51
|
-
:
|
49
|
+
name: '=Sheet1!$C$1',
|
50
|
+
categories: '=Sheet1!$A$2:$A$7',
|
51
|
+
values: '=Sheet1!$C$2:$C$7'
|
52
52
|
)
|
53
53
|
|
54
54
|
# Combine the charts.
|
@@ -56,9 +56,9 @@ column_chart1.combine(line_chart1)
|
|
56
56
|
|
57
57
|
# Add a chart title and some axis labels. Note, this is done via the
|
58
58
|
# primary chart.
|
59
|
-
column_chart1.set_title(:
|
60
|
-
column_chart1.set_x_axis(:
|
61
|
-
column_chart1.set_y_axis(:
|
59
|
+
column_chart1.set_title(name: 'Combined chart - same Y axis')
|
60
|
+
column_chart1.set_x_axis(name: 'Test number')
|
61
|
+
column_chart1.set_y_axis(name: 'Sample length (mm)')
|
62
62
|
|
63
63
|
# Insert the chart into the worksheet
|
64
64
|
worksheet.insert_chart('E2', column_chart1)
|
@@ -69,38 +69,38 @@ worksheet.insert_chart('E2', column_chart1)
|
|
69
69
|
#
|
70
70
|
|
71
71
|
# Create a new column chart. This will use this as the primary chart.
|
72
|
-
column_chart2 = workbook.add_chart(:
|
72
|
+
column_chart2 = workbook.add_chart(type: 'column', embedded: 1)
|
73
73
|
|
74
74
|
# Configure the data series for the primary chart.
|
75
75
|
column_chart2.add_series(
|
76
|
-
:
|
77
|
-
:
|
78
|
-
:
|
76
|
+
name: '=Sheet1!$B$1',
|
77
|
+
categories: '=Sheet1!$A$2:$A$7',
|
78
|
+
values: '=Sheet1!$B$2:$B$7'
|
79
79
|
)
|
80
80
|
|
81
81
|
# Create a new column chart. This will use this as the secondary chart.
|
82
|
-
line_chart2 = workbook.add_chart(:
|
82
|
+
line_chart2 = workbook.add_chart(type: 'line', embedded: 1)
|
83
83
|
|
84
84
|
# Configure the data series for the secondary chart. We also set a
|
85
85
|
# secondary Y axis via (y2_axis). This is the only difference between
|
86
86
|
# this and the first example, apart from the axis label below.
|
87
87
|
line_chart2.add_series(
|
88
|
-
:
|
89
|
-
:
|
90
|
-
:
|
91
|
-
:
|
88
|
+
name: '=Sheet1!$C$1',
|
89
|
+
categories: '=Sheet1!$A$2:$A$7',
|
90
|
+
values: '=Sheet1!$C$2:$C$7',
|
91
|
+
y2_axis: 1
|
92
92
|
)
|
93
93
|
|
94
94
|
# Combine the charts.
|
95
95
|
column_chart2.combine(line_chart2)
|
96
96
|
|
97
97
|
# Add a chart title and some axis labels.
|
98
|
-
column_chart2.set_title(:
|
99
|
-
column_chart2.set_x_axis(:
|
100
|
-
column_chart2.set_y_axis(:
|
98
|
+
column_chart2.set_title(name: 'Combine chart - secondary Y axis')
|
99
|
+
column_chart2.set_x_axis(name: 'Test number')
|
100
|
+
column_chart2.set_y_axis(name: 'Sample length (mm)')
|
101
101
|
|
102
102
|
# NOTE: the y2 properties are on the secondary chart.
|
103
|
-
line_chart2.set_y_axis(:
|
103
|
+
line_chart2.set_y_axis(name: 'Target length (mm)')
|
104
104
|
|
105
105
|
# Insert the chart into the worksheet
|
106
106
|
worksheet.insert_chart('E18', column_chart2)
|