write_xlsx 1.00.0 → 1.01.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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Changes +15 -0
- data/examples/a_simple.rb +1 -1
- data/examples/add_vba_project.rb +1 -1
- data/examples/array_formula.rb +1 -1
- data/examples/chart_area.rb +5 -2
- data/examples/chart_bar.rb +5 -2
- data/examples/chart_clustered.rb +1 -1
- data/examples/chart_column.rb +5 -2
- data/examples/chart_combined.rb +1 -1
- data/examples/chart_data_table.rb +9 -3
- data/examples/chart_data_tools.rb +25 -7
- data/examples/chart_doughnut.rb +17 -5
- data/examples/chart_gauge.rb +73 -0
- data/examples/chart_line.rb +5 -2
- data/examples/chart_pareto.rb +1 -1
- data/examples/chart_pie.rb +9 -3
- data/examples/chart_radar.rb +13 -4
- data/examples/chart_scatter.rb +5 -2
- data/examples/chart_secondary_axis.rb +5 -2
- data/examples/chart_stock.rb +1 -1
- data/examples/chart_styles.rb +1 -1
- data/examples/colors.rb +1 -1
- data/examples/data_validate.rb +1 -1
- data/examples/date_time.rb +1 -1
- data/examples/demo.rb +4 -1
- data/examples/formats.rb +1 -1
- data/examples/headers.rb +1 -1
- data/examples/hide_row_col.rb +1 -1
- data/examples/hide_sheet.rb +1 -1
- data/examples/hyperlink1.rb +1 -1
- data/examples/indent.rb +1 -1
- data/examples/macros.rb +1 -1
- data/examples/merge1.rb +1 -1
- data/examples/merge2.rb +1 -1
- data/examples/merge3.rb +1 -1
- data/examples/merge4.rb +1 -1
- data/examples/merge5.rb +1 -1
- data/examples/merge6.rb +1 -1
- data/examples/outline.rb +1 -1
- data/examples/outline_collapsed.rb +1 -1
- data/examples/panes.rb +1 -1
- data/examples/properties.rb +1 -1
- data/examples/regions.rb +1 -1
- data/examples/rich_strings.rb +1 -1
- data/examples/right_to_left.rb +1 -1
- data/examples/shape1.rb +1 -1
- data/examples/shape2.rb +1 -1
- data/examples/shape3.rb +1 -1
- data/examples/shape4.rb +1 -1
- data/examples/shape5.rb +1 -1
- data/examples/shape6.rb +1 -1
- data/examples/shape7.rb +1 -1
- data/examples/shape8.rb +1 -1
- data/examples/shape_all.rb +1 -1
- data/examples/sparklines1.rb +1 -1
- data/examples/sparklines2.rb +1 -1
- data/examples/stats.rb +1 -1
- data/examples/stats_ext.rb +1 -1
- data/examples/stocks.rb +1 -1
- data/examples/tab_colors.rb +1 -1
- data/examples/tables.rb +1 -1
- data/lib/write_xlsx/chart.rb +18 -13
- data/lib/write_xlsx/chart/area.rb +1 -1
- data/lib/write_xlsx/chart/bar.rb +1 -1
- data/lib/write_xlsx/chart/column.rb +1 -1
- data/lib/write_xlsx/chart/doughnut.rb +1 -1
- data/lib/write_xlsx/chart/line.rb +1 -1
- data/lib/write_xlsx/chart/pie.rb +21 -8
- data/lib/write_xlsx/chart/radar.rb +1 -1
- data/lib/write_xlsx/chart/scatter.rb +1 -1
- data/lib/write_xlsx/chart/stock.rb +1 -1
- data/lib/write_xlsx/chartsheet.rb +5 -5
- data/lib/write_xlsx/drawing.rb +28 -8
- data/lib/write_xlsx/package/comments.rb +7 -7
- data/lib/write_xlsx/shape.rb +4 -3
- data/lib/write_xlsx/sheets.rb +11 -1
- data/lib/write_xlsx/sparkline.rb +1 -1
- data/lib/write_xlsx/utility.rb +18 -6
- data/lib/write_xlsx/version.rb +1 -1
- data/lib/write_xlsx/workbook.rb +5 -5
- data/lib/write_xlsx/worksheet.rb +113 -125
- data/test/drawing/test_drawing_chart_01.rb +6 -2
- data/test/drawing/test_drawing_image_01.rb +12 -3
- data/test/drawing/test_drawing_shape_01.rb +8 -5
- data/test/drawing/test_drawing_shape_02.rb +12 -5
- data/test/drawing/test_drawing_shape_03.rb +8 -5
- data/test/drawing/test_drawing_shape_04.rb +8 -24
- data/test/drawing/test_drawing_shape_05.rb +8 -5
- data/test/drawing/test_drawing_shape_06.rb +11 -6
- data/test/drawing/test_drawing_shape_07.rb +11 -6
- data/test/drawing/test_write_a_graphic_frame_locks.rb +1 -1
- data/test/drawing/test_write_c_chart.rb +1 -1
- data/test/drawing/test_write_c_nv_graphic_frame_pr.rb +1 -1
- data/test/drawing/test_write_c_nv_pr.rb +1 -1
- data/test/drawing/test_write_col.rb +1 -1
- data/test/drawing/test_write_col_off.rb +1 -1
- data/test/drawing/test_write_ext.rb +1 -1
- data/test/drawing/test_write_pos.rb +1 -1
- data/test/drawing/test_write_row.rb +1 -1
- data/test/drawing/test_write_row_off.rb +1 -1
- data/test/drawing/test_write_xfrm_extension.rb +1 -1
- data/test/drawing/test_write_xfrm_offset.rb +1 -1
- data/test/perl_output/chart_gauge.xlsx +0 -0
- data/test/regression/test_chart_axis26.rb +10 -8
- data/test/regression/test_chart_axis27.rb +1 -1
- data/test/regression/test_chart_axis28.rb +1 -1
- data/test/regression/test_chart_axis29.rb +1 -1
- data/test/regression/test_chart_axis33.rb +1 -1
- data/test/regression/test_chart_axis44.rb +54 -0
- data/test/regression/test_chart_axis45.rb +54 -0
- data/test/regression/test_chart_axis46.rb +54 -0
- data/test/regression/test_chart_combined10.rb +43 -0
- data/test/regression/test_chart_combined11.rb +63 -0
- data/test/regression/test_chart_data_labels25.rb +1 -1
- data/test/regression/test_chart_doughnut07.rb +37 -0
- data/test/regression/test_chart_font09.rb +1 -1
- data/test/regression/test_chart_size03.rb +4 -1
- data/test/regression/test_comment14.rb +29 -0
- data/test/regression/test_image08.rb +5 -4
- data/test/regression/test_image15.rb +4 -2
- data/test/regression/test_image28.rb +1 -1
- data/test/regression/test_object_position01.rb +26 -0
- data/test/regression/test_object_position02.rb +26 -0
- data/test/regression/test_object_position03.rb +26 -0
- data/test/regression/test_object_position04.rb +44 -0
- data/test/regression/test_object_position06.rb +28 -0
- data/test/regression/test_object_position07.rb +28 -0
- data/test/regression/test_object_position08.rb +47 -0
- data/test/regression/test_object_position09.rb +50 -0
- data/test/regression/test_object_position10.rb +28 -0
- data/test/regression/test_shape_connect01.rb +4 -2
- data/test/regression/xlsx_files/chart_axis26.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis27.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis28.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis29.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis33.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis44.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis45.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis46.xlsx +0 -0
- data/test/regression/xlsx_files/chart_combined10.xlsx +0 -0
- data/test/regression/xlsx_files/chart_combined11.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels25.xlsx +0 -0
- data/test/regression/xlsx_files/chart_doughnut07.xlsx +0 -0
- data/test/regression/xlsx_files/chart_font09.xlsx +0 -0
- data/test/regression/xlsx_files/comment14.xlsx +0 -0
- data/test/regression/xlsx_files/object_position01.xlsx +0 -0
- data/test/regression/xlsx_files/object_position02.xlsx +0 -0
- data/test/regression/xlsx_files/object_position03.xlsx +0 -0
- data/test/regression/xlsx_files/object_position04.xlsx +0 -0
- data/test/regression/xlsx_files/object_position06.xlsx +0 -0
- data/test/regression/xlsx_files/object_position07.xlsx +0 -0
- data/test/regression/xlsx_files/object_position08.xlsx +0 -0
- data/test/regression/xlsx_files/object_position09.xlsx +0 -0
- data/test/regression/xlsx_files/object_position10.xlsx +0 -0
- data/test/test_example_match.rb +836 -771
- data/test/workbook/test_check_sheetname.rb +61 -0
- metadata +75 -6
@@ -0,0 +1,44 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestRegressionObjectPosition04 < Minitest::Test
|
5
|
+
def setup
|
6
|
+
setup_dir_var
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
@tempfile.close(true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_object_position04
|
14
|
+
@xlsx = 'object_position04.xlsx'
|
15
|
+
workbook = WriteXLSX.new(@io)
|
16
|
+
worksheet = workbook.add_worksheet
|
17
|
+
chart = workbook.add_chart(:type => 'column', :embedded => 1)
|
18
|
+
|
19
|
+
# For testing, copy the randomly generated axis ids in the target xlsx file.
|
20
|
+
chart.instance_variable_set(:@axis_ids, [59106432, 60702720])
|
21
|
+
|
22
|
+
data = [
|
23
|
+
[1, 2, 3, 4, 5],
|
24
|
+
[2, 4, 6, 8, 10],
|
25
|
+
[3, 6, 9, 12, 15]
|
26
|
+
]
|
27
|
+
|
28
|
+
worksheet.write('A1', data)
|
29
|
+
|
30
|
+
chart.add_series(:values => '=Sheet1!$A$1:$A$5')
|
31
|
+
chart.add_series(:values => '=Sheet1!$B$1:$B$5')
|
32
|
+
chart.add_series(:values => '=Sheet1!$C$1:$C$5')
|
33
|
+
|
34
|
+
worksheet.insert_chart(
|
35
|
+
'E9', chart,
|
36
|
+
:x_offset => 0, :y_offset => 0,
|
37
|
+
:x_scale => 1, :y_scale => 1,
|
38
|
+
:object_position => 2
|
39
|
+
)
|
40
|
+
|
41
|
+
workbook.close
|
42
|
+
compare_for_regression
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestRegressionObjectPosition06 < Minitest::Test
|
5
|
+
def setup
|
6
|
+
setup_dir_var
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
@tempfile.close(true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_object_position06
|
14
|
+
@xlsx = 'object_position06.xlsx'
|
15
|
+
workbook = WriteXLSX.new(@io)
|
16
|
+
worksheet = workbook.add_worksheet
|
17
|
+
|
18
|
+
worksheet.insert_image(
|
19
|
+
'E9', 'test/regression/images/red.png',
|
20
|
+
0, 0, 1, 1, 4
|
21
|
+
)
|
22
|
+
|
23
|
+
worksheet.set_row(8, nil, nil, 1)
|
24
|
+
|
25
|
+
workbook.close
|
26
|
+
compare_for_regression
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestRegressionObjectPosition07 < Minitest::Test
|
5
|
+
def setup
|
6
|
+
setup_dir_var
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
@tempfile.close(true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_object_position07
|
14
|
+
@xlsx = 'object_position07.xlsx'
|
15
|
+
workbook = WriteXLSX.new(@io)
|
16
|
+
worksheet = workbook.add_worksheet
|
17
|
+
|
18
|
+
worksheet.insert_image(
|
19
|
+
'E9', 'test/regression/images/red.png',
|
20
|
+
0, 0, 1, 1, 4
|
21
|
+
)
|
22
|
+
|
23
|
+
worksheet.set_row(8, 30, nil, 1)
|
24
|
+
|
25
|
+
workbook.close
|
26
|
+
compare_for_regression
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestRegressionObjectPosition08 < Minitest::Test
|
5
|
+
def setup
|
6
|
+
setup_dir_var
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
@tempfile.close(true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_object_position08
|
14
|
+
@xlsx = 'object_position08.xlsx'
|
15
|
+
workbook = WriteXLSX.new(@io)
|
16
|
+
worksheet = workbook.add_worksheet
|
17
|
+
chart = workbook.add_chart(:type => 'line', :embedded => 1)
|
18
|
+
|
19
|
+
bold = workbook.add_format(:bold => 1)
|
20
|
+
italic = workbook.add_format(:italic => 1)
|
21
|
+
|
22
|
+
# For testing, copy the randomly generated axis ids in the target xlsx file.
|
23
|
+
chart.instance_variable_set(:@axis_ids, [60888960, 79670656])
|
24
|
+
|
25
|
+
data = [
|
26
|
+
[1, 2, 3, 4, 5],
|
27
|
+
[2, 4, 6, 8, 10],
|
28
|
+
[3, 6, 9, 12, 15]
|
29
|
+
]
|
30
|
+
|
31
|
+
worksheet.write('A1', 'Foo', bold)
|
32
|
+
worksheet.write('B1', 'Bar', italic)
|
33
|
+
worksheet.write('A2', data)
|
34
|
+
|
35
|
+
worksheet.set_row(12, nil, nil, 1)
|
36
|
+
worksheet.set_column('F:F', nil, nil, 1)
|
37
|
+
|
38
|
+
chart.add_series(:values => '=Sheet1!$A$2:$A$6')
|
39
|
+
chart.add_series(:values => '=Sheet1!$B$2:$B$6')
|
40
|
+
chart.add_series(:values => '=Sheet1!$C$2:$C$6')
|
41
|
+
|
42
|
+
worksheet.insert_chart('E9', chart, 0, 0, 1, 1, 2)
|
43
|
+
|
44
|
+
workbook.close
|
45
|
+
compare_for_regression
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestRegressionObjectPosition09 < Minitest::Test
|
5
|
+
def setup
|
6
|
+
setup_dir_var
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
@tempfile.close(true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_object_position09
|
14
|
+
@xlsx = 'object_position09.xlsx'
|
15
|
+
workbook = WriteXLSX.new(@io)
|
16
|
+
worksheet = workbook.add_worksheet
|
17
|
+
chart = workbook.add_chart(:type => 'line', :embedded => 1)
|
18
|
+
|
19
|
+
bold = workbook.add_format(:bold => 1)
|
20
|
+
italic = workbook.add_format(:italic => 1)
|
21
|
+
|
22
|
+
# For testing, copy the randomly generated axis ids in the target xlsx file.
|
23
|
+
chart.instance_variable_set(:@axis_ids, [60910208, 69231360])
|
24
|
+
|
25
|
+
data = [
|
26
|
+
[1, 2, 3, 4, 5],
|
27
|
+
[2, 4, 6, 8, 10],
|
28
|
+
[3, 6, 9, 12, 15]
|
29
|
+
]
|
30
|
+
|
31
|
+
worksheet.write('A1', 'Foo', bold)
|
32
|
+
worksheet.write('B1', 'Bar', italic)
|
33
|
+
worksheet.write('A2', data)
|
34
|
+
|
35
|
+
worksheet.set_row(12, nil, nil, 1)
|
36
|
+
worksheet.set_column('F:F', 9, nil, 1)
|
37
|
+
|
38
|
+
chart.add_series(:values => '=Sheet1!$A$2:$A$6')
|
39
|
+
chart.add_series(:values => '=Sheet1!$B$2:$B$6')
|
40
|
+
chart.add_series(:values => '=Sheet1!$C$2:$C$6')
|
41
|
+
|
42
|
+
worksheet.insert_chart(
|
43
|
+
'E9', chart,
|
44
|
+
:object_position => 4
|
45
|
+
)
|
46
|
+
|
47
|
+
workbook.close
|
48
|
+
compare_for_regression
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestRegressionObjectPosition10 < Minitest::Test
|
5
|
+
def setup
|
6
|
+
setup_dir_var
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
@tempfile.close(true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_object_position10
|
14
|
+
@xlsx = 'object_position10.xlsx'
|
15
|
+
workbook = WriteXLSX.new(@io)
|
16
|
+
worksheet = workbook.add_worksheet
|
17
|
+
|
18
|
+
worksheet.insert_image(
|
19
|
+
'E9', 'test/regression/images/red.png',
|
20
|
+
0, 0, 1, 1, 4
|
21
|
+
)
|
22
|
+
|
23
|
+
worksheet.set_column('E:E', nil, nil, 1)
|
24
|
+
|
25
|
+
workbook.close
|
26
|
+
compare_for_regression
|
27
|
+
end
|
28
|
+
end
|
@@ -17,8 +17,10 @@ def test_shape_connect01
|
|
17
17
|
format = workbook.add_format(:font => 'Arial', :size => 8)
|
18
18
|
|
19
19
|
# Add a circle, with centered text
|
20
|
-
ellipse = workbook.add_shape(
|
21
|
-
|
20
|
+
ellipse = workbook.add_shape(
|
21
|
+
:type => 'ellipse', :text => "Hello\nWorld",
|
22
|
+
:width => 60, :height => 60, :format => format
|
23
|
+
)
|
22
24
|
worksheet.insert_shape('A1', ellipse, 50, 50)
|
23
25
|
|
24
26
|
# Add a plus
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/test/test_example_match.rb
CHANGED
@@ -36,9 +36,9 @@ def test_a_simple
|
|
36
36
|
|
37
37
|
# Write a hyperlink
|
38
38
|
hyperlink_format = workbook.add_format(
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
:color => 'blue',
|
40
|
+
:underline => 1
|
41
|
+
)
|
42
42
|
|
43
43
|
worksheet.write(10, 0, 'http://www.ruby-lang.org/', hyperlink_format)
|
44
44
|
|
@@ -242,6 +242,68 @@ def test_autofilter
|
|
242
242
|
compare_xlsx(File.join(@perl_output, @xlsx), @tempfile.path)
|
243
243
|
end
|
244
244
|
|
245
|
+
def test_chart_gauge
|
246
|
+
@xlsx = 'chart_gauge.xlsx'
|
247
|
+
workbook = WriteXLSX.new(@io)
|
248
|
+
worksheet = workbook.add_worksheet
|
249
|
+
|
250
|
+
chart_doughnut = workbook.add_chart(:type => 'doughnut', :embedded => 1)
|
251
|
+
chart_pie = workbook.add_chart(:type => 'pie', :embedded => 1)
|
252
|
+
|
253
|
+
# Add some data for the Doughnut and Pie charts. This is set up so the
|
254
|
+
# gauge goes from 0-100. It is initially set at 75%.
|
255
|
+
worksheet.write_col('H2', ['Donut', 25, 50, 25, 100])
|
256
|
+
worksheet.write_col('I2', ['Pie', 75, 1, '=200-I4-I3'])
|
257
|
+
|
258
|
+
# Configure the doughnut chart as the background for the gauge.
|
259
|
+
chart_doughnut.add_series(
|
260
|
+
:name => '=Sheet1!$H$2',
|
261
|
+
:values => '=Sheet1!$H$3:$H$6',
|
262
|
+
:points => [
|
263
|
+
{ :fill => { :color => 'green' } },
|
264
|
+
{ :fill => { :color => 'yellow' } },
|
265
|
+
{ :fill => { :color => 'red' } },
|
266
|
+
{ :fill => { :none => 1 } }
|
267
|
+
]
|
268
|
+
)
|
269
|
+
|
270
|
+
# Rotate chart so the gauge parts are above the horizontal.
|
271
|
+
chart_doughnut.set_rotation(270)
|
272
|
+
|
273
|
+
# Turn off the chart legend.
|
274
|
+
chart_doughnut.set_legend(:none => 1)
|
275
|
+
|
276
|
+
# Turn off the chart fill and border.
|
277
|
+
chart_doughnut.set_chartarea(
|
278
|
+
:border => { :none => 1 },
|
279
|
+
:fill => { :none => 1 }
|
280
|
+
)
|
281
|
+
|
282
|
+
# Configure the pie chart as the needle for the gauge.
|
283
|
+
chart_pie.add_series(
|
284
|
+
:name => '=Sheet1!$I$2',
|
285
|
+
:values => '=Sheet1!$I$3:$I$6',
|
286
|
+
:points => [
|
287
|
+
{ :fill => { :none => 1 } },
|
288
|
+
{ :fill => { :color => 'black' } },
|
289
|
+
{ :fill => { :none => 1 } }
|
290
|
+
]
|
291
|
+
)
|
292
|
+
|
293
|
+
# Rotate the pie chart/needle to align with the doughnut/gauge.
|
294
|
+
chart_pie.set_rotation(270)
|
295
|
+
|
296
|
+
# Combine the pie and doughnut charts.
|
297
|
+
chart_doughnut.combine(chart_pie)
|
298
|
+
|
299
|
+
# Insert the chart into the worksheet.
|
300
|
+
worksheet.insert_chart('A1', chart_doughnut)
|
301
|
+
|
302
|
+
workbook.close
|
303
|
+
store_to_tempfile
|
304
|
+
compare_xlsx(File.join(@perl_output, @xlsx), @tempfile.path)
|
305
|
+
end
|
306
|
+
|
245
307
|
def test_chart_scatter06
|
246
308
|
@xlsx = 'chart_scatter06.xlsx'
|
247
309
|
workbook = WriteXLSX.new(@io)
|
@@ -252,23 +314,23 @@ def test_chart_scatter06
|
|
252
314
|
chart.instance_variable_set(:@axis_ids, [57708544, 44297600])
|
253
315
|
|
254
316
|
data = [
|
255
|
-
|
256
|
-
|
257
|
-
|
317
|
+
[ 1, 2, 3, 4, 5 ],
|
318
|
+
[ 2, 4, 6, 8, 10 ],
|
319
|
+
[ 3, 6, 9, 12, 15 ]
|
258
320
|
|
259
|
-
|
321
|
+
]
|
260
322
|
|
261
323
|
worksheet.write('A1', data)
|
262
324
|
|
263
325
|
chart.add_series(
|
264
|
-
|
265
|
-
|
266
|
-
|
326
|
+
:categories => '=Sheet1!$A$1:$A$5',
|
327
|
+
:values => '=Sheet1!$B$1:$B$5'
|
328
|
+
)
|
267
329
|
|
268
330
|
chart.add_series(
|
269
|
-
|
270
|
-
|
271
|
-
|
331
|
+
:categories => '=Sheet1!$A$1:$A$5',
|
332
|
+
:values => '=Sheet1!$C$1:$C$5'
|
333
|
+
)
|
272
334
|
|
273
335
|
chart.set_x_axis(:minor_unit => 1, :major_unit => 3)
|
274
336
|
chart.set_y_axis(:minor_unit => 2, :major_unit => 4)
|
@@ -281,7 +343,7 @@ def test_chart_scatter06
|
|
281
343
|
end
|
282
344
|
|
283
345
|
def autofilter_data
|
284
|
-
<<EOS
|
346
|
+
<<EOS
|
285
347
|
Region Item Volume Month
|
286
348
|
East Apple 9000 July
|
287
349
|
East Apple 5000 July
|
@@ -345,10 +407,10 @@ def test_chart_area
|
|
345
407
|
# Add the worksheet data that the charts will refer to.
|
346
408
|
headings = [ 'Number', 'Batch 1', 'Batch 2' ]
|
347
409
|
data = [
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
410
|
+
[ 2, 3, 4, 5, 6, 7 ],
|
411
|
+
[ 40, 40, 50, 30, 25, 50 ],
|
412
|
+
[ 30, 25, 30, 10, 5, 10 ]
|
413
|
+
]
|
352
414
|
|
353
415
|
worksheet.write('A1', headings, bold)
|
354
416
|
worksheet.write('A2', data)
|
@@ -358,18 +420,18 @@ def test_chart_area
|
|
358
420
|
|
359
421
|
# Configure the first series.
|
360
422
|
chart.add_series(
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
423
|
+
:name => '=Sheet1!$B$1',
|
424
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
425
|
+
:values => '=Sheet1!$B$2:$B$7'
|
426
|
+
)
|
365
427
|
|
366
428
|
# Configure second series. Note alternative use of array ref to define
|
367
429
|
# ranges: [ sheetname, row_start, row_end, col_start, col_end ].
|
368
430
|
chart.add_series(
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
431
|
+
:name => '=Sheet1!$C$1',
|
432
|
+
:categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
433
|
+
:values => [ 'Sheet1', 1, 6, 2, 2 ]
|
434
|
+
)
|
373
435
|
|
374
436
|
# Add a chart title and some axis labels.
|
375
437
|
chart.set_title(:name => 'Results of sample analysis')
|
@@ -396,9 +458,9 @@ def test_chart_bar
|
|
396
458
|
# Add the worksheet data that the charts will refer to.
|
397
459
|
headings = [ 'Number', 'Batch 1', 'Batch 2' ]
|
398
460
|
data = [
|
399
|
-
|
400
|
-
|
401
|
-
|
461
|
+
[ 2, 3, 4, 5, 6, 7 ],
|
462
|
+
[ 10, 40, 50, 20, 10, 50 ],
|
463
|
+
[ 30, 60, 70, 50, 40, 30 ]
|
402
464
|
]
|
403
465
|
|
404
466
|
worksheet.write('A1', headings, bold)
|
@@ -409,17 +471,17 @@ def test_chart_bar
|
|
409
471
|
|
410
472
|
# Configure the first series.
|
411
473
|
chart.add_series(
|
412
|
-
|
413
|
-
|
414
|
-
|
474
|
+
:name => '=Sheet1!$B$1',
|
475
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
476
|
+
:values => '=Sheet1!$B$2:$B$7'
|
415
477
|
)
|
416
478
|
|
417
479
|
# Configure second series. Note alternative use of array ref to define
|
418
480
|
# ranges: [ sheetname, row_start, row_end, col_start, col_end ].
|
419
481
|
chart.add_series(
|
420
|
-
|
421
|
-
|
422
|
-
|
482
|
+
:name => '=Sheet1!$C$1',
|
483
|
+
:categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
484
|
+
:values => [ 'Sheet1', 1, 6, 2, 2 ]
|
423
485
|
)
|
424
486
|
|
425
487
|
# Add a chart title and some axis labels.
|
@@ -447,9 +509,9 @@ def test_chart_column
|
|
447
509
|
# Add the worksheet data that the charts will refer to.
|
448
510
|
headings = [ 'Number', 'Batch 1', 'Batch 2' ]
|
449
511
|
data = [
|
450
|
-
|
451
|
-
|
452
|
-
|
512
|
+
[ 2, 3, 4, 5, 6, 7 ],
|
513
|
+
[ 10, 40, 50, 20, 10, 50 ],
|
514
|
+
[ 30, 60, 70, 50, 40, 30 ]
|
453
515
|
]
|
454
516
|
|
455
517
|
worksheet.write('A1', headings, bold)
|
@@ -460,17 +522,17 @@ def test_chart_column
|
|
460
522
|
|
461
523
|
# Configure the first series.
|
462
524
|
chart.add_series(
|
463
|
-
|
464
|
-
|
465
|
-
|
525
|
+
:name => '=Sheet1!$B$1',
|
526
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
527
|
+
:values => '=Sheet1!$B$2:$B$7'
|
466
528
|
)
|
467
529
|
|
468
530
|
# Configure second series. Note alternative use of array ref to define
|
469
531
|
# ranges: [ sheetname, row_start, row_end, col_start, col_end ].
|
470
532
|
chart.add_series(
|
471
|
-
|
472
|
-
|
473
|
-
|
533
|
+
:name => '=Sheet1!$C$1',
|
534
|
+
:categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
535
|
+
:values => [ 'Sheet1', 1, 6, 2, 2 ]
|
474
536
|
)
|
475
537
|
|
476
538
|
# Add a chart title and some axis labels.
|
@@ -498,9 +560,9 @@ def test_chart_doughnut
|
|
498
560
|
# Add the worksheet data that the charts will refer to.
|
499
561
|
headings = [ 'Category', 'Values' ]
|
500
562
|
data = [
|
501
|
-
|
502
|
-
|
503
|
-
|
563
|
+
[ 'Glazed', 'Chocolate', 'Cream' ],
|
564
|
+
[ 50, 35, 15 ]
|
565
|
+
]
|
504
566
|
|
505
567
|
worksheet.write('A1', headings, bold)
|
506
568
|
worksheet.write('A2', data)
|
@@ -512,10 +574,10 @@ def test_chart_doughnut
|
|
512
574
|
# [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
|
513
575
|
# See below for an alternative syntax.
|
514
576
|
chart1.add_series(
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
577
|
+
:name => 'Doughnut sales data',
|
578
|
+
:categories => [ 'Sheet1', 1, 3, 0, 0 ],
|
579
|
+
:values => [ 'Sheet1', 1, 3, 1, 1 ]
|
580
|
+
);
|
519
581
|
|
520
582
|
# Add a title.
|
521
583
|
chart1.set_title(:name => 'Popular Doughnut Types')
|
@@ -536,15 +598,15 @@ def test_chart_doughnut
|
|
536
598
|
|
537
599
|
# Configure the series and add user defined segment colours.
|
538
600
|
chart2.add_series(
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
601
|
+
:name => 'Doughnut sales data',
|
602
|
+
:categories => '=Sheet1!$A$2:$A$4',
|
603
|
+
:values => '=Sheet1!$B$2:$B$4',
|
604
|
+
:points => [
|
605
|
+
{ :fill => { :color => '#FA58D0' } },
|
606
|
+
{ :fill => { :color => '#61210B' } },
|
607
|
+
{ :fill => { :color => '#F5F6CE' } }
|
608
|
+
]
|
609
|
+
)
|
548
610
|
|
549
611
|
# Add a title.
|
550
612
|
chart2.set_title(:name => 'Doughnut Chart with user defined colors')
|
@@ -563,10 +625,10 @@ def test_chart_doughnut
|
|
563
625
|
|
564
626
|
# Configure the series.
|
565
627
|
chart3.add_series(
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
628
|
+
:name => 'Doughnut sales data',
|
629
|
+
:categories => '=Sheet1!$A$2:$A$4',
|
630
|
+
:values => '=Sheet1!$B$2:$B$4'
|
631
|
+
)
|
570
632
|
|
571
633
|
# Add a title.
|
572
634
|
chart3.set_title(:name => 'Doughnut Chart with segment rotation')
|
@@ -587,10 +649,10 @@ def test_chart_doughnut
|
|
587
649
|
|
588
650
|
# Configure the series.
|
589
651
|
chart4.add_series(
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
652
|
+
:name => 'Doughnut sales data',
|
653
|
+
:categories => '=Sheet1!$A$2:$A$4',
|
654
|
+
:values => '=Sheet1!$B$2:$B$4'
|
655
|
+
)
|
594
656
|
|
595
657
|
# Add a title.
|
596
658
|
chart4.set_title(:name => 'Doughnut Chart with user defined hole size')
|
@@ -615,9 +677,9 @@ def test_chart_line
|
|
615
677
|
# Add the worksheet data that the charts will refer to.
|
616
678
|
headings = [ 'Number', 'Batch 1', 'Batch 2' ]
|
617
679
|
data = [
|
618
|
-
|
619
|
-
|
620
|
-
|
680
|
+
[ 2, 3, 4, 5, 6, 7 ],
|
681
|
+
[ 10, 40, 50, 20, 10, 50 ],
|
682
|
+
[ 30, 60, 70, 50, 40, 30 ]
|
621
683
|
]
|
622
684
|
|
623
685
|
worksheet.write('A1', headings, bold)
|
@@ -628,17 +690,17 @@ def test_chart_line
|
|
628
690
|
|
629
691
|
# Configure the first series.
|
630
692
|
chart.add_series(
|
631
|
-
|
632
|
-
|
633
|
-
|
693
|
+
:name => '=Sheet1!$B$1',
|
694
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
695
|
+
:values => '=Sheet1!$B$2:$B$7'
|
634
696
|
)
|
635
697
|
|
636
698
|
# Configure second series. Note alternative use of array ref to define
|
637
699
|
# ranges: [ sheetname, row_start, row_end, col_start, col_end ].
|
638
700
|
chart.add_series(
|
639
|
-
|
640
|
-
|
641
|
-
|
701
|
+
:name => '=Sheet1!$C$1',
|
702
|
+
:categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
703
|
+
:values => [ 'Sheet1', 1, 6, 2, 2 ]
|
642
704
|
)
|
643
705
|
|
644
706
|
# Add a chart title and some axis labels.
|
@@ -666,9 +728,9 @@ def test_chart_pie
|
|
666
728
|
# Add the worksheet data that the charts will refer to.
|
667
729
|
headings = [ 'Category', 'Values' ]
|
668
730
|
data = [
|
669
|
-
|
670
|
-
|
671
|
-
|
731
|
+
[ 'Apple', 'Cherry', 'Pecan' ],
|
732
|
+
[ 60, 30, 10 ]
|
733
|
+
]
|
672
734
|
|
673
735
|
worksheet.write('A1', headings, bold)
|
674
736
|
worksheet.write('A2', data)
|
@@ -680,10 +742,10 @@ def test_chart_pie
|
|
680
742
|
# [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
|
681
743
|
# See below for an alternative syntax.
|
682
744
|
chart1.add_series(
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
745
|
+
:name => 'Pie sales data',
|
746
|
+
:categories => [ 'Sheet1', 1, 3, 0, 0 ],
|
747
|
+
:values => [ 'Sheet1', 1, 3, 1, 1 ]
|
748
|
+
)
|
687
749
|
|
688
750
|
# Add a title.
|
689
751
|
chart1.set_title(:name => 'Popular Pie Types')
|
@@ -703,15 +765,15 @@ def test_chart_pie
|
|
703
765
|
|
704
766
|
# Configure the series and add user defined segment colours.
|
705
767
|
chart2.add_series(
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
768
|
+
:name => 'Pie sales data',
|
769
|
+
:categories => '=Sheet1!$A$2:$A$4',
|
770
|
+
:values => '=Sheet1!$B$2:$B$4',
|
771
|
+
:points => [
|
772
|
+
{ :fill => { :color => '#5ABA10' } },
|
773
|
+
{ :fill => { :color => '#FE110E' } },
|
774
|
+
{ :fill => { :color => '#CA5C05' } }
|
775
|
+
]
|
776
|
+
)
|
715
777
|
|
716
778
|
# Add a title.
|
717
779
|
chart2.set_title(:name => 'Pie Chart with user defined colors')
|
@@ -733,10 +795,10 @@ def test_chart_radar
|
|
733
795
|
# Add the worksheet data that the charts will refer to.
|
734
796
|
headings = [ 'Number', 'Batch 1', 'Batch 2' ]
|
735
797
|
data = [
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
798
|
+
[ 2, 3, 4, 5, 6, 7 ],
|
799
|
+
[ 30, 60, 70, 50, 40, 30 ],
|
800
|
+
[ 25, 40, 50, 30, 50, 40 ]
|
801
|
+
]
|
740
802
|
|
741
803
|
worksheet.write('A1', headings, bold)
|
742
804
|
worksheet.write('A2', data)
|
@@ -746,18 +808,18 @@ def test_chart_radar
|
|
746
808
|
|
747
809
|
# Configure the first series.
|
748
810
|
chart1.add_series(
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
811
|
+
:name => '=Sheet1!$B$1',
|
812
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
813
|
+
:values => '=Sheet1!$B$2:$B$7'
|
814
|
+
)
|
753
815
|
|
754
816
|
# Configure second series. Note alternative use of array ref to define
|
755
817
|
# ranges: [ sheetname, row_start, row_end, col_start, col_end ].
|
756
818
|
chart1.add_series(
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
819
|
+
:name => '=Sheet1!$C$1',
|
820
|
+
:categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
821
|
+
:values => [ 'Sheet1', 1, 6, 2, 2 ]
|
822
|
+
)
|
761
823
|
|
762
824
|
# Add a chart title and some axis labels.
|
763
825
|
chart1.set_title(:name => 'Results of sample analysis')
|
@@ -774,24 +836,24 @@ def test_chart_radar
|
|
774
836
|
# Create a with_markers chart sub-type
|
775
837
|
#
|
776
838
|
chart2 = workbook.add_chart(
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
839
|
+
:type => 'radar',
|
840
|
+
:embedded => 1,
|
841
|
+
:subtype => 'with_markers'
|
842
|
+
)
|
781
843
|
|
782
844
|
# Configure the first series.
|
783
845
|
chart2.add_series(
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
846
|
+
:name => '=Sheet1!$B$1',
|
847
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
848
|
+
:values => '=Sheet1!$B$2:$B$7'
|
849
|
+
)
|
788
850
|
|
789
851
|
# Configure second series.
|
790
852
|
chart2.add_series(
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
853
|
+
:name => '=Sheet1!$C$1',
|
854
|
+
:categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
855
|
+
:values => [ 'Sheet1', 1, 6, 2, 2 ]
|
856
|
+
)
|
795
857
|
|
796
858
|
# Add a chart title and some axis labels.
|
797
859
|
chart2.set_title(:name => 'Stacked Chart')
|
@@ -808,24 +870,24 @@ def test_chart_radar
|
|
808
870
|
# Create a filled chart sub-type
|
809
871
|
#
|
810
872
|
chart3 = workbook.add_chart(
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
873
|
+
:type => 'radar',
|
874
|
+
:embedded => 1,
|
875
|
+
:subtype => 'filled'
|
876
|
+
)
|
815
877
|
|
816
878
|
# Configure the first series.
|
817
879
|
chart3.add_series(
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
880
|
+
:name => '=Sheet1!$B$1',
|
881
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
882
|
+
:values => '=Sheet1!$B$2:$B$7'
|
883
|
+
)
|
822
884
|
|
823
885
|
# Configure second series.
|
824
886
|
chart3.add_series(
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
887
|
+
:name => '=Sheet1!$C$1',
|
888
|
+
:categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
889
|
+
:values => [ 'Sheet1', 1, 6, 2, 2 ]
|
890
|
+
)
|
829
891
|
|
830
892
|
# Add a chart title and some axis labels.
|
831
893
|
chart3.set_title(:name => 'Percent Stacked Chart')
|
@@ -852,9 +914,9 @@ def test_chart_scatter
|
|
852
914
|
# Add the worksheet data that the charts will refer to.
|
853
915
|
headings = [ 'Number', 'Batch 1', 'Batch 2' ]
|
854
916
|
data = [
|
855
|
-
|
856
|
-
|
857
|
-
|
917
|
+
[ 2, 3, 4, 5, 6, 7 ],
|
918
|
+
[ 10, 40, 50, 20, 10, 50 ],
|
919
|
+
[ 30, 60, 70, 50, 40, 30 ]
|
858
920
|
]
|
859
921
|
|
860
922
|
worksheet.write('A1', headings, bold)
|
@@ -865,17 +927,17 @@ def test_chart_scatter
|
|
865
927
|
|
866
928
|
# Configure the first series.
|
867
929
|
chart.add_series(
|
868
|
-
|
869
|
-
|
870
|
-
|
930
|
+
:name => '=Sheet1!$B$1',
|
931
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
932
|
+
:values => '=Sheet1!$B$2:$B$7'
|
871
933
|
)
|
872
934
|
|
873
935
|
# Configure second series. Note alternative use of array ref to define
|
874
936
|
# ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].$chart->add_series(
|
875
937
|
chart.add_series(
|
876
|
-
|
877
|
-
|
878
|
-
|
938
|
+
:name => '=Sheet1!$C$1',
|
939
|
+
:categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
940
|
+
:values => [ 'Sheet1', 1, 6, 2, 2 ]
|
879
941
|
)
|
880
942
|
|
881
943
|
# Add a chart title and some axis labels.
|
@@ -906,19 +968,19 @@ def test_chart_stock
|
|
906
968
|
# Add the worksheet data that the charts will refer to.
|
907
969
|
headings = [ 'Date', 'High', 'Low', 'Close' ]
|
908
970
|
data = [
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
971
|
+
[ '2007-01-01T', '2007-01-02T', '2007-01-03T', '2007-01-04T', '2007-01-05T' ],
|
972
|
+
[ 27.2, 25.03, 19.05, 20.34, 18.5 ],
|
973
|
+
[ 23.49, 19.55, 15.12, 17.84, 16.34 ],
|
974
|
+
[ 25.45, 23.05, 17.32, 20.45, 17.34 ]
|
913
975
|
]
|
914
976
|
|
915
977
|
worksheet.write('A1', headings, bold)
|
916
978
|
|
917
979
|
(0 .. 4).each do |row|
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
980
|
+
worksheet.write_date_time(row + 1, 0, data[0][row], date_format)
|
981
|
+
worksheet.write(row + 1, 1, data[1][row])
|
982
|
+
worksheet.write(row + 1, 2, data[2][row])
|
983
|
+
worksheet.write(row + 1, 3, data[3][row])
|
922
984
|
end
|
923
985
|
|
924
986
|
worksheet.set_column('A:D', 11)
|
@@ -960,9 +1022,9 @@ def test_chart_secondary_axis
|
|
960
1022
|
# Add the worksheet data that the charts will refer to.
|
961
1023
|
headings = [ 'Aliens', 'Humans']
|
962
1024
|
data = [
|
963
|
-
|
964
|
-
|
965
|
-
|
1025
|
+
[ 2, 3, 4, 5, 6, 7 ],
|
1026
|
+
[ 10, 40, 50, 20, 10, 50 ]
|
1027
|
+
]
|
966
1028
|
|
967
1029
|
worksheet.write('A1', headings, bold)
|
968
1030
|
worksheet.write('A2', data)
|
@@ -972,15 +1034,15 @@ def test_chart_secondary_axis
|
|
972
1034
|
|
973
1035
|
# Configure the first series.
|
974
1036
|
chart.add_series(
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
1037
|
+
:name => '=Sheet1!$A$1',
|
1038
|
+
:values => '=Sheet1!$A$2:$A$7',
|
1039
|
+
:y2_axis => 1
|
1040
|
+
)
|
979
1041
|
|
980
1042
|
chart.add_series(
|
981
|
-
|
982
|
-
|
983
|
-
|
1043
|
+
:name => '=Sheet1!$B$1',
|
1044
|
+
:values => '=Sheet1!$B$2:$B$7'
|
1045
|
+
)
|
984
1046
|
|
985
1047
|
chart.set_legend(:position => 'right')
|
986
1048
|
|
@@ -1275,7 +1337,7 @@ def test_comments2
|
|
1275
1337
|
cell = 'C3'
|
1276
1338
|
|
1277
1339
|
cell_text = "Move the mouse over this cell and you will see 'Cell commented " +
|
1278
|
-
|
1340
|
+
"by #{author}' (blank) in the status bar at the bottom"
|
1279
1341
|
|
1280
1342
|
comment = 'Hello.'
|
1281
1343
|
|
@@ -1286,7 +1348,7 @@ def test_comments2
|
|
1286
1348
|
author = 'Ruby'
|
1287
1349
|
cell = 'C6'
|
1288
1350
|
cell_text = "Move the mouse over this cell and you will see 'Cell commented " +
|
1289
|
-
|
1351
|
+
"by #{author}' in the status bar at the bottom"
|
1290
1352
|
|
1291
1353
|
comment = 'Hello.'
|
1292
1354
|
|
@@ -1297,7 +1359,7 @@ def test_comments2
|
|
1297
1359
|
author = '€'
|
1298
1360
|
cell = 'C9'
|
1299
1361
|
cell_text = "Move the mouse over this cell and you will see 'Cell commented " +
|
1300
|
-
|
1362
|
+
"by #{author}' in the status bar at the bottom"
|
1301
1363
|
comment = 'Hello.'
|
1302
1364
|
|
1303
1365
|
worksheet7.write( cell, cell_text, text_wrap )
|
@@ -1361,36 +1423,36 @@ def test_conditional_format
|
|
1361
1423
|
|
1362
1424
|
# Light red fill with dark red text.
|
1363
1425
|
format1 = workbook.add_format(
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1426
|
+
:bg_color => '#FFC7CE',
|
1427
|
+
:color => '#9C0006'
|
1428
|
+
)
|
1367
1429
|
|
1368
1430
|
# Green fill with dark green text.
|
1369
1431
|
format2 = workbook.add_format(
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1432
|
+
:bg_color => '#C6EFCE',
|
1433
|
+
:color => '#006100'
|
1434
|
+
)
|
1373
1435
|
|
1374
1436
|
# Some sample data to run the conditional formatting against.
|
1375
1437
|
data = [
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1438
|
+
[ 34, 72, 38, 30, 75, 48, 75, 66, 84, 86 ],
|
1439
|
+
[ 6, 24, 1, 84, 54, 62, 60, 3, 26, 59 ],
|
1440
|
+
[ 28, 79, 97, 13, 85, 93, 93, 22, 5, 14 ],
|
1441
|
+
[ 27, 71, 40, 17, 18, 79, 90, 93, 29, 47 ],
|
1442
|
+
[ 88, 25, 33, 23, 67, 1, 59, 79, 47, 36 ],
|
1443
|
+
[ 24, 100, 20, 88, 29, 33, 38, 54, 54, 88 ],
|
1444
|
+
[ 6, 57, 88, 28, 10, 26, 37, 7, 41, 48 ],
|
1445
|
+
[ 52, 78, 1, 96, 26, 45, 47, 33, 96, 36 ],
|
1446
|
+
[ 60, 54, 81, 66, 81, 90, 80, 93, 12, 55 ],
|
1447
|
+
[ 70, 5, 46, 14, 71, 19, 66, 36, 41, 21 ]
|
1448
|
+
]
|
1387
1449
|
|
1388
1450
|
###############################################################################
|
1389
1451
|
#
|
1390
1452
|
# Example 1.
|
1391
1453
|
#
|
1392
1454
|
caption = 'Cells with values >= 50 are in light red. ' +
|
1393
|
-
|
1455
|
+
'Values < 50 are in light green.'
|
1394
1456
|
|
1395
1457
|
# Write the data.
|
1396
1458
|
worksheet1.write('A1', caption)
|
@@ -1404,7 +1466,7 @@ def test_conditional_format
|
|
1404
1466
|
:value => 50,
|
1405
1467
|
:format => format1
|
1406
1468
|
}
|
1407
|
-
|
1469
|
+
)
|
1408
1470
|
|
1409
1471
|
# Write another conditional format over the same range.
|
1410
1472
|
worksheet1.conditional_formatting('B3:K12',
|
@@ -1414,7 +1476,7 @@ def test_conditional_format
|
|
1414
1476
|
:value => 50,
|
1415
1477
|
:format => format2
|
1416
1478
|
}
|
1417
|
-
|
1479
|
+
)
|
1418
1480
|
|
1419
1481
|
|
1420
1482
|
###############################################################################
|
@@ -1422,7 +1484,7 @@ def test_conditional_format
|
|
1422
1484
|
# Example 2.
|
1423
1485
|
#
|
1424
1486
|
caption = 'Values between 30 and 70 are in light red. ' +
|
1425
|
-
|
1487
|
+
'Values outside that range are in light green.'
|
1426
1488
|
|
1427
1489
|
worksheet2.write('A1', caption)
|
1428
1490
|
worksheet2.write_col('B3', data)
|
@@ -1435,7 +1497,7 @@ def test_conditional_format
|
|
1435
1497
|
:maximum => 70,
|
1436
1498
|
:format => format1
|
1437
1499
|
}
|
1438
|
-
|
1500
|
+
)
|
1439
1501
|
|
1440
1502
|
worksheet2.conditional_formatting('B3:K12',
|
1441
1503
|
{
|
@@ -1445,7 +1507,7 @@ def test_conditional_format
|
|
1445
1507
|
:maximum => 70,
|
1446
1508
|
:format => format2
|
1447
1509
|
}
|
1448
|
-
|
1510
|
+
)
|
1449
1511
|
|
1450
1512
|
|
1451
1513
|
###############################################################################
|
@@ -1453,7 +1515,7 @@ def test_conditional_format
|
|
1453
1515
|
# Example 3.
|
1454
1516
|
#
|
1455
1517
|
caption = 'Duplicate values are in light red. ' +
|
1456
|
-
|
1518
|
+
'Unique values are in light green.'
|
1457
1519
|
|
1458
1520
|
worksheet3.write('A1', caption)
|
1459
1521
|
worksheet3.write_col('B3', data)
|
@@ -1463,14 +1525,14 @@ def test_conditional_format
|
|
1463
1525
|
:type => 'duplicate',
|
1464
1526
|
:format => format1,
|
1465
1527
|
}
|
1466
|
-
|
1528
|
+
)
|
1467
1529
|
|
1468
1530
|
worksheet3.conditional_formatting('B3:K12',
|
1469
1531
|
{
|
1470
1532
|
:type => 'unique',
|
1471
1533
|
:format => format2,
|
1472
1534
|
}
|
1473
|
-
|
1535
|
+
)
|
1474
1536
|
|
1475
1537
|
|
1476
1538
|
###############################################################################
|
@@ -1478,7 +1540,7 @@ def test_conditional_format
|
|
1478
1540
|
# Example 4.
|
1479
1541
|
#
|
1480
1542
|
caption = 'Above average values are in light red. ' +
|
1481
|
-
|
1543
|
+
'Below average values are in light green.'
|
1482
1544
|
|
1483
1545
|
worksheet4.write('A1', caption)
|
1484
1546
|
worksheet4.write_col('B3', data)
|
@@ -1489,7 +1551,7 @@ def test_conditional_format
|
|
1489
1551
|
:criteria => 'above',
|
1490
1552
|
:format => format1
|
1491
1553
|
}
|
1492
|
-
|
1554
|
+
)
|
1493
1555
|
|
1494
1556
|
worksheet4.conditional_formatting('B3:K12',
|
1495
1557
|
{
|
@@ -1497,7 +1559,7 @@ def test_conditional_format
|
|
1497
1559
|
:criteria => 'below',
|
1498
1560
|
:format => format2
|
1499
1561
|
}
|
1500
|
-
|
1562
|
+
)
|
1501
1563
|
|
1502
1564
|
|
1503
1565
|
###############################################################################
|
@@ -1505,7 +1567,7 @@ def test_conditional_format
|
|
1505
1567
|
# Example 5.
|
1506
1568
|
#
|
1507
1569
|
caption = 'Top 10 values are in light red. ' +
|
1508
|
-
|
1570
|
+
'Bottom 10 values are in light green.'
|
1509
1571
|
|
1510
1572
|
worksheet5.write('A1', caption)
|
1511
1573
|
worksheet5.write_col('B3', data)
|
@@ -1516,7 +1578,7 @@ def test_conditional_format
|
|
1516
1578
|
:value => '10',
|
1517
1579
|
:format => format1
|
1518
1580
|
}
|
1519
|
-
|
1581
|
+
)
|
1520
1582
|
|
1521
1583
|
worksheet5.conditional_formatting('B3:K12',
|
1522
1584
|
{
|
@@ -1524,7 +1586,7 @@ def test_conditional_format
|
|
1524
1586
|
:value => '10',
|
1525
1587
|
:format => format2
|
1526
1588
|
}
|
1527
|
-
|
1589
|
+
)
|
1528
1590
|
|
1529
1591
|
|
1530
1592
|
###############################################################################
|
@@ -1532,7 +1594,7 @@ def test_conditional_format
|
|
1532
1594
|
# Example 6.
|
1533
1595
|
#
|
1534
1596
|
caption = 'Cells with values >= 50 are in light red. ' +
|
1535
|
-
|
1597
|
+
'Values < 50 are in light green. Non-contiguous ranges.'
|
1536
1598
|
|
1537
1599
|
# Write the data.
|
1538
1600
|
worksheet6.write('A1', caption)
|
@@ -1546,7 +1608,7 @@ def test_conditional_format
|
|
1546
1608
|
:value => 50,
|
1547
1609
|
:format => format1
|
1548
1610
|
}
|
1549
|
-
|
1611
|
+
)
|
1550
1612
|
|
1551
1613
|
# Write another conditional format over the same range.
|
1552
1614
|
worksheet6.conditional_formatting('B3:K6,B9:K12',
|
@@ -1556,7 +1618,7 @@ def test_conditional_format
|
|
1556
1618
|
:value => 50,
|
1557
1619
|
:format => format2
|
1558
1620
|
}
|
1559
|
-
|
1621
|
+
)
|
1560
1622
|
|
1561
1623
|
|
1562
1624
|
###############################################################################
|
@@ -1583,19 +1645,19 @@ def test_conditional_format
|
|
1583
1645
|
{
|
1584
1646
|
:type => '2_color_scale'
|
1585
1647
|
}
|
1586
|
-
|
1648
|
+
)
|
1587
1649
|
|
1588
1650
|
worksheet7.conditional_formatting('D3:D14',
|
1589
1651
|
{
|
1590
1652
|
:type => '3_color_scale'
|
1591
1653
|
}
|
1592
|
-
|
1654
|
+
)
|
1593
1655
|
|
1594
1656
|
worksheet7.conditional_formatting('F3:F14',
|
1595
1657
|
{
|
1596
1658
|
:type => 'data_bar'
|
1597
1659
|
}
|
1598
|
-
|
1660
|
+
)
|
1599
1661
|
|
1600
1662
|
|
1601
1663
|
###############################################################################
|
@@ -1624,7 +1686,7 @@ def test_conditional_format
|
|
1624
1686
|
:min_color => "#FF0000",
|
1625
1687
|
:max_color => "#00FF00"
|
1626
1688
|
}
|
1627
|
-
|
1689
|
+
)
|
1628
1690
|
|
1629
1691
|
worksheet8.conditional_formatting('D3:D14',
|
1630
1692
|
{
|
@@ -1633,14 +1695,14 @@ def test_conditional_format
|
|
1633
1695
|
:mid_color => "#8DB4E3",
|
1634
1696
|
:max_color => "#538ED5"
|
1635
1697
|
}
|
1636
|
-
|
1698
|
+
)
|
1637
1699
|
|
1638
1700
|
worksheet8.conditional_formatting('F3:F14',
|
1639
1701
|
{
|
1640
1702
|
:type => 'data_bar',
|
1641
1703
|
:bar_color => '#63C384'
|
1642
1704
|
}
|
1643
|
-
|
1705
|
+
)
|
1644
1706
|
|
1645
1707
|
workbook.close
|
1646
1708
|
store_to_tempfile
|
@@ -1654,13 +1716,13 @@ def test_data_validate
|
|
1654
1716
|
|
1655
1717
|
# Add a format for the header cells.
|
1656
1718
|
header_format = workbook.add_format(
|
1657
|
-
|
1658
|
-
|
1659
|
-
|
1660
|
-
|
1661
|
-
|
1662
|
-
|
1663
|
-
|
1719
|
+
:border => 1,
|
1720
|
+
:bg_color => 43,
|
1721
|
+
:bold => 1,
|
1722
|
+
:text_wrap => 1,
|
1723
|
+
:valign => 'vcenter',
|
1724
|
+
:indent => 1
|
1725
|
+
)
|
1664
1726
|
|
1665
1727
|
# Set up layout of the worksheet.
|
1666
1728
|
worksheet.set_column('A:A', 68)
|
@@ -1932,32 +1994,32 @@ def test_date_time
|
|
1932
1994
|
# the format codes change the appearance of the date.
|
1933
1995
|
#
|
1934
1996
|
date_formats = [
|
1935
|
-
|
1936
|
-
|
1937
|
-
|
1938
|
-
|
1939
|
-
|
1940
|
-
|
1941
|
-
|
1942
|
-
|
1943
|
-
|
1944
|
-
|
1945
|
-
|
1946
|
-
|
1947
|
-
|
1948
|
-
|
1949
|
-
|
1950
|
-
|
1951
|
-
|
1952
|
-
|
1953
|
-
|
1954
|
-
|
1955
|
-
|
1956
|
-
|
1957
|
-
|
1958
|
-
|
1959
|
-
|
1960
|
-
|
1997
|
+
'dd/mm/yy',
|
1998
|
+
'mm/dd/yy',
|
1999
|
+
'',
|
2000
|
+
'd mm yy',
|
2001
|
+
'dd mm yy',
|
2002
|
+
'',
|
2003
|
+
'dd m yy',
|
2004
|
+
'dd mm yy',
|
2005
|
+
'dd mmm yy',
|
2006
|
+
'dd mmmm yy',
|
2007
|
+
'',
|
2008
|
+
'dd mm y',
|
2009
|
+
'dd mm yyy',
|
2010
|
+
'dd mm yyyy',
|
2011
|
+
'',
|
2012
|
+
'd mmmm yyyy',
|
2013
|
+
'',
|
2014
|
+
'dd/mm/yy',
|
2015
|
+
'dd/mm/yy hh:mm',
|
2016
|
+
'dd/mm/yy hh:mm:ss',
|
2017
|
+
'dd/mm/yy hh:mm:ss.000',
|
2018
|
+
'',
|
2019
|
+
'hh:mm',
|
2020
|
+
'hh:mm:ss',
|
2021
|
+
'hh:mm:ss.000'
|
2022
|
+
]
|
1961
2023
|
|
1962
2024
|
# Write the same date and time using each of the above formats. The empty
|
1963
2025
|
# string formats create a blank line to make the example clearer.
|
@@ -1969,9 +2031,9 @@ def test_date_time
|
|
1969
2031
|
|
1970
2032
|
# Create a format for the date or time.
|
1971
2033
|
format = workbook.add_format(
|
1972
|
-
|
1973
|
-
|
1974
|
-
|
2034
|
+
:num_format => date_format,
|
2035
|
+
:align => 'left'
|
2036
|
+
)
|
1975
2037
|
|
1976
2038
|
# Write the same date using different formats.
|
1977
2039
|
worksheet.write_date_time(row, 0, '2004-08-01T12:30:45.123', format)
|
@@ -2036,17 +2098,17 @@ def test_demo
|
|
2036
2098
|
worksheet.set_row(0, 40)
|
2037
2099
|
|
2038
2100
|
heading = workbook.add_format(
|
2039
|
-
|
2040
|
-
|
2041
|
-
|
2042
|
-
|
2043
|
-
|
2044
|
-
|
2101
|
+
:bold => 1,
|
2102
|
+
:color => 'blue',
|
2103
|
+
:size => 16,
|
2104
|
+
:merge => 1,
|
2105
|
+
:align => 'vcenter'
|
2106
|
+
)
|
2045
2107
|
|
2046
2108
|
hyperlink_format = workbook.add_format(
|
2047
|
-
|
2048
|
-
|
2049
|
-
|
2109
|
+
:color => 'blue',
|
2110
|
+
:underline => 1
|
2111
|
+
)
|
2050
2112
|
|
2051
2113
|
headings = ['Features of WriteXLSX', '']
|
2052
2114
|
worksheet.write_row('A1', headings, heading)
|
@@ -2056,12 +2118,12 @@ def test_demo
|
|
2056
2118
|
# Some text examples
|
2057
2119
|
#
|
2058
2120
|
text_format = workbook.add_format(
|
2059
|
-
|
2060
|
-
|
2061
|
-
|
2062
|
-
|
2063
|
-
|
2064
|
-
|
2121
|
+
:bold => 1,
|
2122
|
+
:italic => 1,
|
2123
|
+
:color => 'red',
|
2124
|
+
:size => 18,
|
2125
|
+
:font => 'Lucida Calligraphy'
|
2126
|
+
)
|
2065
2127
|
|
2066
2128
|
worksheet.write('A2', "Text")
|
2067
2129
|
worksheet.write('B2', "Hello Excel")
|
@@ -2104,7 +2166,10 @@ def test_demo
|
|
2104
2166
|
# Images
|
2105
2167
|
#
|
2106
2168
|
worksheet.write('A10', "Images")
|
2107
|
-
worksheet.insert_image(
|
2169
|
+
worksheet.insert_image(
|
2170
|
+
'B10', File.join(@test_dir, 'republic.png'),
|
2171
|
+
:x_offset => 16, :y_offset => 8
|
2172
|
+
)
|
2108
2173
|
|
2109
2174
|
#######################################################################
|
2110
2175
|
#
|
@@ -2129,10 +2194,10 @@ def test_diag_border
|
|
2129
2194
|
format3 = workbook.add_format(:diag_type => 3)
|
2130
2195
|
|
2131
2196
|
format4 = workbook.add_format(
|
2132
|
-
|
2133
|
-
|
2134
|
-
|
2135
|
-
|
2197
|
+
:diag_type => 3,
|
2198
|
+
:diag_border => 7,
|
2199
|
+
:diag_color => 'red'
|
2200
|
+
)
|
2136
2201
|
|
2137
2202
|
worksheet.write('B3', 'Text', format1)
|
2138
2203
|
worksheet.write('B6', 'Text', format2)
|
@@ -2218,9 +2283,9 @@ def intro(workbook, center, heading, colors)
|
|
2218
2283
|
format2.set_color('blue')
|
2219
2284
|
|
2220
2285
|
format3 = workbook.add_format(
|
2221
|
-
|
2222
|
-
|
2223
|
-
|
2286
|
+
:color => 'blue',
|
2287
|
+
:underline => 1
|
2288
|
+
)
|
2224
2289
|
|
2225
2290
|
worksheet.write(2, 0, 'This workbook demonstrates some of', format)
|
2226
2291
|
worksheet.write(3, 0, 'the formatting options provided by', format)
|
@@ -2233,16 +2298,16 @@ def intro(workbook, center, heading, colors)
|
|
2233
2298
|
'Named colors', format3)
|
2234
2299
|
|
2235
2300
|
worksheet.write(
|
2236
|
-
|
2237
|
-
|
2238
|
-
|
2239
|
-
|
2301
|
+
'A10',
|
2302
|
+
"internal:'Standard colors'!A1",
|
2303
|
+
'Standard colors', format3
|
2304
|
+
)
|
2240
2305
|
|
2241
2306
|
worksheet.write(
|
2242
|
-
|
2243
|
-
|
2244
|
-
|
2245
|
-
|
2307
|
+
'A11',
|
2308
|
+
"internal:'Numeric formats'!A1",
|
2309
|
+
'Numeric formats', format3
|
2310
|
+
)
|
2246
2311
|
|
2247
2312
|
worksheet.write('A12', "internal:Borders!A1", 'Borders', format3)
|
2248
2313
|
worksheet.write('A13', "internal:Patterns!A1", 'Patterns', format3)
|
@@ -2272,10 +2337,10 @@ def named_colors(workbook, center, heading, colors)
|
|
2272
2337
|
[33, 11, 53, 17, 22, 18, 13, 16, 23, 9, 12, 15, 14, 20, 8, 10].each do |index|
|
2273
2338
|
color = colors[index]
|
2274
2339
|
format = workbook.add_format(
|
2275
|
-
|
2276
|
-
|
2277
|
-
|
2278
|
-
|
2340
|
+
:bg_color => color,
|
2341
|
+
:pattern => 1,
|
2342
|
+
:border => 1
|
2343
|
+
)
|
2279
2344
|
|
2280
2345
|
worksheet.write(i + 1, 0, index, center)
|
2281
2346
|
worksheet.write(i + 1, 1, sprintf("0x%02X", index), center)
|
@@ -2302,10 +2367,10 @@ def standard_colors(workbook, center, heading, colors)
|
|
2302
2367
|
|
2303
2368
|
(8 .. 63).each do |i|
|
2304
2369
|
format = workbook.add_format(
|
2305
|
-
|
2306
|
-
|
2307
|
-
|
2308
|
-
|
2370
|
+
:bg_color => i,
|
2371
|
+
:pattern => 1,
|
2372
|
+
:border => 1
|
2373
|
+
)
|
2309
2374
|
|
2310
2375
|
worksheet.write((i - 7), 0, i, center)
|
2311
2376
|
worksheet.write((i - 7), 1, sprintf("0x%02X", i), center)
|
@@ -2787,17 +2852,17 @@ def test_hyperlink
|
|
2787
2852
|
|
2788
2853
|
# Add the standard url link format.
|
2789
2854
|
url_format = workbook.add_format(
|
2790
|
-
|
2791
|
-
|
2792
|
-
|
2855
|
+
:color => 'blue',
|
2856
|
+
:underline => 1
|
2857
|
+
)
|
2793
2858
|
|
2794
2859
|
# Add a sample format.
|
2795
2860
|
red_format = workbook.add_format(
|
2796
|
-
|
2797
|
-
|
2798
|
-
|
2799
|
-
|
2800
|
-
|
2861
|
+
:color => 'red',
|
2862
|
+
:bold => 1,
|
2863
|
+
:underline => 1,
|
2864
|
+
:size => 12
|
2865
|
+
)
|
2801
2866
|
|
2802
2867
|
# Add an alternate description string to the URL.
|
2803
2868
|
str = 'Perl home.'
|
@@ -2873,16 +2938,16 @@ def test_merge2
|
|
2873
2938
|
|
2874
2939
|
# Create a merged format
|
2875
2940
|
format = workbook.add_format(
|
2876
|
-
|
2877
|
-
|
2878
|
-
|
2879
|
-
|
2880
|
-
|
2881
|
-
|
2882
|
-
|
2883
|
-
|
2884
|
-
|
2885
|
-
|
2941
|
+
:center_across => 1,
|
2942
|
+
:bold => 1,
|
2943
|
+
:size => 15,
|
2944
|
+
:pattern => 1,
|
2945
|
+
:border => 6,
|
2946
|
+
:color => 'white',
|
2947
|
+
:fg_color => 'green',
|
2948
|
+
:border_color => 'yellow',
|
2949
|
+
:align => 'vcenter'
|
2950
|
+
)
|
2886
2951
|
|
2887
2952
|
# Only one cell should contain text, the others should be blank.
|
2888
2953
|
worksheet.write(2, 1, "Center across selection", format)
|
@@ -2909,12 +2974,12 @@ def test_merge3
|
|
2909
2974
|
# Example: Merge cells containing a hyperlink using merge_range().
|
2910
2975
|
#
|
2911
2976
|
format = workbook.add_format(
|
2912
|
-
|
2913
|
-
|
2914
|
-
|
2915
|
-
|
2916
|
-
|
2917
|
-
|
2977
|
+
:border => 1,
|
2978
|
+
:underline => 1,
|
2979
|
+
:color => 'blue',
|
2980
|
+
:align => 'center',
|
2981
|
+
:valign => 'vcenter'
|
2982
|
+
)
|
2918
2983
|
|
2919
2984
|
# Merge 3 cells
|
2920
2985
|
worksheet.merge_range('B4:D4', 'http://www.perl.com', format)
|
@@ -2942,12 +3007,12 @@ def test_merge4
|
|
2942
3007
|
# Example 1: Text centered vertically and horizontally
|
2943
3008
|
#
|
2944
3009
|
format1 = workbook.add_format(
|
2945
|
-
|
2946
|
-
|
2947
|
-
|
2948
|
-
|
2949
|
-
|
2950
|
-
|
3010
|
+
:border => 6,
|
3011
|
+
:bold => 1,
|
3012
|
+
:color => 'red',
|
3013
|
+
:valign => 'vcenter',
|
3014
|
+
:align => 'center'
|
3015
|
+
)
|
2951
3016
|
|
2952
3017
|
worksheet.merge_range('B2:D3', 'Vertical and horizontal', format1)
|
2953
3018
|
|
@@ -2956,12 +3021,12 @@ def test_merge4
|
|
2956
3021
|
# Example 2: Text aligned to the top and left
|
2957
3022
|
#
|
2958
3023
|
format2 = workbook.add_format(
|
2959
|
-
|
2960
|
-
|
2961
|
-
|
2962
|
-
|
2963
|
-
|
2964
|
-
|
3024
|
+
:border => 6,
|
3025
|
+
:bold => 1,
|
3026
|
+
:color => 'red',
|
3027
|
+
:valign => 'top',
|
3028
|
+
:align => 'left'
|
3029
|
+
)
|
2965
3030
|
|
2966
3031
|
worksheet.merge_range('B5:D6', 'Aligned to the top and left', format2)
|
2967
3032
|
|
@@ -2970,12 +3035,12 @@ def test_merge4
|
|
2970
3035
|
# Example 3: Text aligned to the bottom and right
|
2971
3036
|
#
|
2972
3037
|
format3 = workbook.add_format(
|
2973
|
-
|
2974
|
-
|
2975
|
-
|
2976
|
-
|
2977
|
-
|
2978
|
-
|
3038
|
+
:border => 6,
|
3039
|
+
:bold => 1,
|
3040
|
+
:color => 'red',
|
3041
|
+
:valign => 'bottom',
|
3042
|
+
:align => 'right'
|
3043
|
+
)
|
2979
3044
|
|
2980
3045
|
worksheet.merge_range('B8:D9', 'Aligned to the bottom and right', format3)
|
2981
3046
|
|
@@ -2984,12 +3049,12 @@ def test_merge4
|
|
2984
3049
|
# Example 4: Text justified (i.e. wrapped) in the cell
|
2985
3050
|
#
|
2986
3051
|
format4 = workbook.add_format(
|
2987
|
-
|
2988
|
-
|
2989
|
-
|
2990
|
-
|
2991
|
-
|
2992
|
-
|
3052
|
+
:border => 6,
|
3053
|
+
:bold => 1,
|
3054
|
+
:color => 'red',
|
3055
|
+
:valign => 'top',
|
3056
|
+
:align => 'justify'
|
3057
|
+
)
|
2993
3058
|
|
2994
3059
|
worksheet.merge_range('B11:D12', 'Justified: ' << 'so on and ' * 18, format4)
|
2995
3060
|
|
@@ -3013,13 +3078,13 @@ def test_merge5
|
|
3013
3078
|
# Rotation 1, letters run from top to bottom
|
3014
3079
|
#
|
3015
3080
|
format1 = workbook.add_format(
|
3016
|
-
|
3017
|
-
|
3018
|
-
|
3019
|
-
|
3020
|
-
|
3021
|
-
|
3022
|
-
|
3081
|
+
:border => 6,
|
3082
|
+
:bold => 1,
|
3083
|
+
:color => 'red',
|
3084
|
+
:valign => 'vcentre',
|
3085
|
+
:align => 'centre',
|
3086
|
+
:rotation => 270
|
3087
|
+
)
|
3023
3088
|
|
3024
3089
|
worksheet.merge_range( 'B4:B9', 'Rotation 270', format1 )
|
3025
3090
|
|
@@ -3028,13 +3093,13 @@ def test_merge5
|
|
3028
3093
|
# Rotation 2, 90ー anticlockwise
|
3029
3094
|
#
|
3030
3095
|
format2 = workbook.add_format(
|
3031
|
-
|
3032
|
-
|
3033
|
-
|
3034
|
-
|
3035
|
-
|
3036
|
-
|
3037
|
-
|
3096
|
+
:border => 6,
|
3097
|
+
:bold => 1,
|
3098
|
+
:color => 'red',
|
3099
|
+
:valign => 'vcentre',
|
3100
|
+
:align => 'centre',
|
3101
|
+
:rotation => 90
|
3102
|
+
)
|
3038
3103
|
|
3039
3104
|
worksheet.merge_range( 'D4:D9', 'Rotation 90°', format2 )
|
3040
3105
|
|
@@ -3043,13 +3108,13 @@ def test_merge5
|
|
3043
3108
|
# Rotation 3, 90ー clockwise
|
3044
3109
|
#
|
3045
3110
|
format3 = workbook.add_format(
|
3046
|
-
|
3047
|
-
|
3048
|
-
|
3049
|
-
|
3050
|
-
|
3051
|
-
|
3052
|
-
|
3111
|
+
:border => 6,
|
3112
|
+
:bold => 1,
|
3113
|
+
:color => 'red',
|
3114
|
+
:valign => 'vcentre',
|
3115
|
+
:align => 'centre',
|
3116
|
+
:rotation => -90
|
3117
|
+
)
|
3053
3118
|
|
3054
3119
|
worksheet.merge_range( 'F4:F9', 'Rotation -90°', format3 )
|
3055
3120
|
|
@@ -3070,14 +3135,14 @@ def test_merge6
|
|
3070
3135
|
|
3071
3136
|
# Format for the merged cells.
|
3072
3137
|
format = workbook.add_format(
|
3073
|
-
|
3074
|
-
|
3075
|
-
|
3076
|
-
|
3077
|
-
|
3078
|
-
|
3079
|
-
|
3080
|
-
|
3138
|
+
:border => 6,
|
3139
|
+
:bold => 1,
|
3140
|
+
:color => 'red',
|
3141
|
+
:size => 20,
|
3142
|
+
:valign => 'vcentre',
|
3143
|
+
:align => 'left',
|
3144
|
+
:indent => 1
|
3145
|
+
)
|
3081
3146
|
|
3082
3147
|
###############################################################################
|
3083
3148
|
#
|
@@ -3234,12 +3299,12 @@ def test_outline
|
|
3234
3299
|
# Example 3: Create a worksheet with outlined columns.
|
3235
3300
|
#
|
3236
3301
|
data = [
|
3237
|
-
|
3238
|
-
|
3239
|
-
|
3240
|
-
|
3241
|
-
|
3242
|
-
|
3302
|
+
[ 'Month', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', ' Total' ],
|
3303
|
+
[ 'North', 50, 20, 15, 25, 65, 80, '=SUM(B2:G2)' ],
|
3304
|
+
[ 'South', 10, 20, 30, 50, 50, 50, '=SUM(B3:G3)' ],
|
3305
|
+
[ 'East', 45, 75, 50, 15, 75, 100, '=SUM(B4:G4)' ],
|
3306
|
+
[ 'West', 15, 15, 55, 35, 20, 50, '=SUM(B5:G5)' ],
|
3307
|
+
]
|
3243
3308
|
|
3244
3309
|
# Add bold format to the first row
|
3245
3310
|
worksheet3.set_row(0, nil, bold)
|
@@ -3259,10 +3324,10 @@ def test_outline
|
|
3259
3324
|
# Example 4: Show all possible outline levels.
|
3260
3325
|
#
|
3261
3326
|
levels = [
|
3262
|
-
|
3263
|
-
|
3264
|
-
|
3265
|
-
|
3327
|
+
"Level 1", "Level 2", "Level 3", "Level 4", "Level 5", "Level 6",
|
3328
|
+
"Level 7", "Level 6", "Level 5", "Level 4", "Level 3", "Level 2",
|
3329
|
+
"Level 1"
|
3330
|
+
]
|
3266
3331
|
|
3267
3332
|
|
3268
3333
|
worksheet4.write_col('A1', levels)
|
@@ -3393,12 +3458,12 @@ def test_outline_collapsed
|
|
3393
3458
|
# Example 5: Create a worksheet with outlined columns.
|
3394
3459
|
#
|
3395
3460
|
data = [
|
3396
|
-
|
3397
|
-
|
3398
|
-
|
3399
|
-
|
3400
|
-
|
3401
|
-
|
3461
|
+
[ 'Month', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Total' ],
|
3462
|
+
[ 'North', 50, 20, 15, 25, 65, 80, '=SUM(B2:G2)' ],
|
3463
|
+
[ 'South', 10, 20, 30, 50, 50, 50, '=SUM(B3:G3)' ],
|
3464
|
+
[ 'East', 45, 75, 50, 15, 75, 100, '=SUM(B4:G4)' ],
|
3465
|
+
[ 'West', 15, 15, 55, 35, 20, 50, '=SUM(B5:G6)' ]
|
3466
|
+
]
|
3402
3467
|
|
3403
3468
|
# Add bold format to the first row
|
3404
3469
|
worksheet5.set_row(0, nil, bold)
|
@@ -3499,10 +3564,10 @@ def test_panes
|
|
3499
3564
|
#
|
3500
3565
|
|
3501
3566
|
header = workbook.add_format(
|
3502
|
-
|
3503
|
-
|
3504
|
-
|
3505
|
-
|
3567
|
+
:align => 'center',
|
3568
|
+
:valign => 'vcenter',
|
3569
|
+
:fg_color => 0x2A
|
3570
|
+
)
|
3506
3571
|
|
3507
3572
|
center = workbook.add_format(:align => 'center')
|
3508
3573
|
|
@@ -3598,16 +3663,16 @@ def test_properties
|
|
3598
3663
|
worksheet = workbook.add_worksheet
|
3599
3664
|
|
3600
3665
|
workbook.set_properties(
|
3601
|
-
|
3602
|
-
|
3603
|
-
|
3604
|
-
|
3605
|
-
|
3606
|
-
|
3607
|
-
|
3608
|
-
|
3609
|
-
|
3610
|
-
|
3666
|
+
:title => 'This is an example spreadsheet',
|
3667
|
+
:subject => 'With document properties',
|
3668
|
+
:author => 'John McNamara',
|
3669
|
+
:manager => 'Dr. Heinz Doofenshmirtz',
|
3670
|
+
:company => 'of Wolves',
|
3671
|
+
:category => 'Example spreadsheets',
|
3672
|
+
:keywords => 'Sample, Example, Properties',
|
3673
|
+
:comments => 'Created with Perl and Excel::Writer::XLSX',
|
3674
|
+
:status => 'Quo'
|
3675
|
+
)
|
3611
3676
|
|
3612
3677
|
worksheet.set_column('A:A', 70)
|
3613
3678
|
worksheet.write('A1', "Select 'Office Button -> Prepare -> Properties' to see the file properties.")
|
@@ -3708,16 +3773,16 @@ def test_rich_strings
|
|
3708
3773
|
|
3709
3774
|
# Write some strings with multiple formats.
|
3710
3775
|
worksheet.write_rich_string('A1',
|
3711
|
-
|
3776
|
+
'This is ', bold, 'bold', ' and this is ', italic, 'italic')
|
3712
3777
|
|
3713
3778
|
worksheet.write_rich_string('A3',
|
3714
|
-
|
3779
|
+
'This is ', red, 'red', ' and this is ', blue, 'blue')
|
3715
3780
|
|
3716
3781
|
worksheet.write_rich_string('A5',
|
3717
|
-
|
3782
|
+
'Some ', bold, 'bold text', ' centered', center)
|
3718
3783
|
|
3719
3784
|
worksheet.write_rich_string('A7',
|
3720
|
-
|
3785
|
+
italic, 'j = k', superc, '(n-1)', center)
|
3721
3786
|
|
3722
3787
|
workbook.close
|
3723
3788
|
store_to_tempfile
|
@@ -3750,7 +3815,7 @@ def test_shape1
|
|
3750
3815
|
:text => "Hello\nWorld",
|
3751
3816
|
:width => 60,
|
3752
3817
|
:height => 60
|
3753
|
-
|
3818
|
+
)
|
3754
3819
|
|
3755
3820
|
worksheet.insert_shape('A1', ellipse, 50, 50)
|
3756
3821
|
|
@@ -3775,12 +3840,12 @@ def test_shape2
|
|
3775
3840
|
:text => "Plain",
|
3776
3841
|
:width => 100,
|
3777
3842
|
:height => 100
|
3778
|
-
|
3843
|
+
)
|
3779
3844
|
|
3780
3845
|
bbformat = workbook.add_format(
|
3781
3846
|
:color => 'red',
|
3782
3847
|
:font => 'Lucida Calligraphy'
|
3783
|
-
|
3848
|
+
)
|
3784
3849
|
|
3785
3850
|
bbformat.set_bold
|
3786
3851
|
bbformat.set_underline
|
@@ -3797,7 +3862,7 @@ def test_shape2
|
|
3797
3862
|
:line_weight => 3,
|
3798
3863
|
:fill => 'FFFF00',
|
3799
3864
|
:line => '3366FF'
|
3800
|
-
|
3865
|
+
)
|
3801
3866
|
|
3802
3867
|
worksheet.insert_shape('A1', plain, 50, 50)
|
3803
3868
|
worksheet.insert_shape('A1', decor, 250, 50)
|
@@ -3818,7 +3883,7 @@ def test_shape3
|
|
3818
3883
|
:text => 'Normal',
|
3819
3884
|
:width => 100,
|
3820
3885
|
:height => 100
|
3821
|
-
|
3886
|
+
)
|
3822
3887
|
|
3823
3888
|
worksheet.insert_shape('A1', normal, 50, 50)
|
3824
3889
|
normal.text = 'Scaled 3w x 2h'
|
@@ -3841,7 +3906,7 @@ def test_shape4
|
|
3841
3906
|
:type => type,
|
3842
3907
|
:width => 90,
|
3843
3908
|
:height => 90
|
3844
|
-
|
3909
|
+
)
|
3845
3910
|
|
3846
3911
|
(1..10).each do |n|
|
3847
3912
|
# Change the last 5 rectangles to stars. Previously
|
@@ -3857,7 +3922,7 @@ def test_shape4
|
|
3857
3922
|
:width => 90,
|
3858
3923
|
:height => 90,
|
3859
3924
|
:text => 'started as a box'
|
3860
|
-
|
3925
|
+
)
|
3861
3926
|
worksheet.insert_shape('A1', stencil, 100, 150)
|
3862
3927
|
|
3863
3928
|
stencil.stencil = 0
|
@@ -3884,14 +3949,14 @@ def test_shape5
|
|
3884
3949
|
:type => 'ellipse',
|
3885
3950
|
:width => 60,
|
3886
3951
|
:height => 60
|
3887
|
-
|
3952
|
+
)
|
3888
3953
|
worksheet.insert_shape('A1', s1, 50, 50)
|
3889
3954
|
|
3890
3955
|
s2 = workbook.add_shape(
|
3891
3956
|
:type => 'plus',
|
3892
3957
|
:width => 20,
|
3893
3958
|
:height => 20
|
3894
|
-
|
3959
|
+
)
|
3895
3960
|
worksheet.insert_shape('A1', s2, 250, 200)
|
3896
3961
|
|
3897
3962
|
# Create a connector to link the two shapes.
|
@@ -3923,14 +3988,14 @@ def test_shape6
|
|
3923
3988
|
:type => 'chevron',
|
3924
3989
|
:width => 60,
|
3925
3990
|
:height => 60
|
3926
|
-
|
3991
|
+
)
|
3927
3992
|
worksheet.insert_shape('A1', s1, 50, 50)
|
3928
3993
|
|
3929
3994
|
s2 = workbook.add_shape(
|
3930
3995
|
:type => 'pentagon',
|
3931
3996
|
:width => 20,
|
3932
3997
|
:height => 20
|
3933
|
-
|
3998
|
+
)
|
3934
3999
|
worksheet.insert_shape('A1', s2, 250, 200)
|
3935
4000
|
|
3936
4001
|
# Create a connector to link the two shapes.
|
@@ -3970,7 +4035,7 @@ def test_shape7
|
|
3970
4035
|
:text => "Hello\nWorld",
|
3971
4036
|
:width => cw,
|
3972
4037
|
:height => ch
|
3973
|
-
|
4038
|
+
)
|
3974
4039
|
worksheet.insert_shape('A1', ellipse, cx, cy)
|
3975
4040
|
|
3976
4041
|
# Add a plus sign at 4 different positions around the circle.
|
@@ -3984,7 +4049,7 @@ def test_shape7
|
|
3984
4049
|
:id => 3,
|
3985
4050
|
:width => pw,
|
3986
4051
|
:height => ph
|
3987
|
-
|
4052
|
+
)
|
3988
4053
|
|
3989
4054
|
p1 = worksheet.insert_shape('A1', plus, 350, 350)
|
3990
4055
|
p2 = worksheet.insert_shape('A1', plus, 150, 350)
|
@@ -4035,7 +4100,7 @@ def test_shape8
|
|
4035
4100
|
:text => "Hello\nWorld",
|
4036
4101
|
:width => cw,
|
4037
4102
|
:height => ch
|
4038
|
-
|
4103
|
+
)
|
4039
4104
|
worksheet.insert_shape('A1', ellipse, cx, cy)
|
4040
4105
|
|
4041
4106
|
# Add a plus sign at 4 different positionos around the circle.
|
@@ -4049,7 +4114,7 @@ def test_shape8
|
|
4049
4114
|
:id => 3,
|
4050
4115
|
:width => pw,
|
4051
4116
|
:height => ph
|
4052
|
-
|
4117
|
+
)
|
4053
4118
|
|
4054
4119
|
p1 = worksheet.insert_shape('A1', plus, 350, 150)
|
4055
4120
|
p2 = worksheet.insert_shape('A1', plus, 350, 350)
|
@@ -4100,11 +4165,11 @@ def test_shape_all
|
|
4100
4165
|
end
|
4101
4166
|
last_sheet = sheet
|
4102
4167
|
shape = workbook.add_shape(
|
4103
|
-
|
4104
|
-
|
4105
|
-
|
4106
|
-
|
4107
|
-
|
4168
|
+
:type => name,
|
4169
|
+
:text => name,
|
4170
|
+
:width => 90,
|
4171
|
+
:height => 90
|
4172
|
+
)
|
4108
4173
|
|
4109
4174
|
# Connectors can not have labels, so write the connector name in the cell
|
4110
4175
|
# to the left.
|
@@ -4536,11 +4601,11 @@ def test_tables
|
|
4536
4601
|
|
4537
4602
|
# Some sample data for the table.
|
4538
4603
|
data = [
|
4539
|
-
|
4540
|
-
|
4541
|
-
|
4542
|
-
|
4543
|
-
|
4604
|
+
[ 'Apples', 10000, 5000, 8000, 6000 ],
|
4605
|
+
[ 'Pears', 2000, 3000, 4000, 5000 ],
|
4606
|
+
[ 'Bananas', 6000, 6000, 6500, 6000 ],
|
4607
|
+
[ 'Oranges', 500, 300, 200, 700 ]
|
4608
|
+
]
|
4544
4609
|
|
4545
4610
|
###############################################################################
|
4546
4611
|
#
|
@@ -4658,18 +4723,18 @@ def test_tables
|
|
4658
4723
|
|
4659
4724
|
# Add a table to the worksheet.
|
4660
4725
|
worksheet7.add_table(
|
4661
|
-
|
4662
|
-
|
4663
|
-
|
4664
|
-
|
4665
|
-
|
4666
|
-
|
4667
|
-
|
4668
|
-
|
4669
|
-
|
4670
|
-
|
4671
|
-
|
4672
|
-
|
4726
|
+
'B3:F7',
|
4727
|
+
{
|
4728
|
+
:data => data,
|
4729
|
+
:columns => [
|
4730
|
+
{ :header => 'Product' },
|
4731
|
+
{ :header => 'Quarter 1' },
|
4732
|
+
{ :header => 'Quarter 2' },
|
4733
|
+
{ :header => 'Quarter 3' },
|
4734
|
+
{ :header => 'Quarter 4' }
|
4735
|
+
]
|
4736
|
+
}
|
4737
|
+
)
|
4673
4738
|
|
4674
4739
|
###############################################################################
|
4675
4740
|
#
|
@@ -4685,22 +4750,22 @@ def test_tables
|
|
4685
4750
|
|
4686
4751
|
# Add a table to the worksheet.
|
4687
4752
|
worksheet8.add_table(
|
4688
|
-
|
4689
|
-
|
4690
|
-
|
4691
|
-
|
4692
|
-
|
4693
|
-
|
4694
|
-
|
4695
|
-
|
4696
|
-
|
4697
|
-
|
4698
|
-
|
4699
|
-
|
4700
|
-
|
4701
|
-
|
4702
|
-
|
4703
|
-
|
4753
|
+
'B3:G7',
|
4754
|
+
{
|
4755
|
+
:data => data,
|
4756
|
+
:columns => [
|
4757
|
+
{ :header => 'Product' },
|
4758
|
+
{ :header => 'Quarter 1' },
|
4759
|
+
{ :header => 'Quarter 2' },
|
4760
|
+
{ :header => 'Quarter 3' },
|
4761
|
+
{ :header => 'Quarter 4' },
|
4762
|
+
{
|
4763
|
+
:header => 'Year',
|
4764
|
+
:formula => '=SUM(Table8[@[Quarter 1]:[Quarter 4]])'
|
4765
|
+
}
|
4766
|
+
]
|
4767
|
+
}
|
4768
|
+
)
|
4704
4769
|
|
4705
4770
|
|
4706
4771
|
###############################################################################
|
@@ -4717,23 +4782,23 @@ def test_tables
|
|
4717
4782
|
|
4718
4783
|
# Add a table to the worksheet.
|
4719
4784
|
worksheet9.add_table(
|
4720
|
-
|
4721
|
-
|
4722
|
-
|
4723
|
-
|
4724
|
-
|
4725
|
-
|
4726
|
-
|
4727
|
-
|
4728
|
-
|
4729
|
-
|
4730
|
-
|
4731
|
-
|
4732
|
-
|
4733
|
-
|
4734
|
-
|
4735
|
-
|
4736
|
-
|
4785
|
+
'B3:G8',
|
4786
|
+
{
|
4787
|
+
:data => data,
|
4788
|
+
:total_row => 1,
|
4789
|
+
:columns => [
|
4790
|
+
{ :header => 'Product' },
|
4791
|
+
{ :header => 'Quarter 1' },
|
4792
|
+
{ :header => 'Quarter 2' },
|
4793
|
+
{ :header => 'Quarter 3' },
|
4794
|
+
{ :header => 'Quarter 4' },
|
4795
|
+
{
|
4796
|
+
:header => 'Year',
|
4797
|
+
:formula => '=SUM(Table8[@[Quarter 1]:[Quarter 4]])'
|
4798
|
+
}
|
4799
|
+
]
|
4800
|
+
}
|
4801
|
+
)
|
4737
4802
|
|
4738
4803
|
###############################################################################
|
4739
4804
|
#
|
@@ -4749,24 +4814,24 @@ def test_tables
|
|
4749
4814
|
|
4750
4815
|
# Add a table to the worksheet.
|
4751
4816
|
worksheet10.add_table(
|
4752
|
-
|
4753
|
-
|
4754
|
-
|
4755
|
-
|
4756
|
-
|
4757
|
-
|
4758
|
-
|
4759
|
-
|
4760
|
-
|
4761
|
-
|
4762
|
-
|
4763
|
-
|
4764
|
-
|
4765
|
-
|
4766
|
-
|
4767
|
-
|
4768
|
-
|
4769
|
-
|
4817
|
+
'B3:G8',
|
4818
|
+
{
|
4819
|
+
:data => data,
|
4820
|
+
:total_row => 1,
|
4821
|
+
:columns => [
|
4822
|
+
{ :header => 'Product', :total_string => 'Totals' },
|
4823
|
+
{ :header => 'Quarter 1', :total_function => 'sum' },
|
4824
|
+
{ :header => 'Quarter 2', :total_function => 'sum' },
|
4825
|
+
{ :header => 'Quarter 3', :total_function => 'sum' },
|
4826
|
+
{ :header => 'Quarter 4', :total_function => 'sum' },
|
4827
|
+
{
|
4828
|
+
:header => 'Year',
|
4829
|
+
:formula => '=SUM(Table8[@[Quarter 1]:[Quarter 4]])',
|
4830
|
+
:total_function => 'sum'
|
4831
|
+
}
|
4832
|
+
]
|
4833
|
+
}
|
4834
|
+
)
|
4770
4835
|
|
4771
4836
|
###############################################################################
|
4772
4837
|
#
|
@@ -4782,25 +4847,25 @@ def test_tables
|
|
4782
4847
|
|
4783
4848
|
# Add a table to the worksheet.
|
4784
4849
|
worksheet11.add_table(
|
4785
|
-
|
4786
|
-
|
4787
|
-
|
4788
|
-
|
4789
|
-
|
4790
|
-
|
4791
|
-
|
4792
|
-
|
4793
|
-
|
4794
|
-
|
4795
|
-
|
4796
|
-
|
4797
|
-
|
4798
|
-
|
4799
|
-
|
4800
|
-
|
4801
|
-
|
4802
|
-
|
4803
|
-
|
4850
|
+
'B3:G8',
|
4851
|
+
{
|
4852
|
+
:data => data,
|
4853
|
+
:style => 'Table Style Light 11',
|
4854
|
+
:total_row => 1,
|
4855
|
+
:columns => [
|
4856
|
+
{ :header => 'Product', :total_string => 'Totals' },
|
4857
|
+
{ :header => 'Quarter 1', :total_function => 'sum' },
|
4858
|
+
{ :header => 'Quarter 2', :total_function => 'sum' },
|
4859
|
+
{ :header => 'Quarter 3', :total_function => 'sum' },
|
4860
|
+
{ :header => 'Quarter 4', :total_function => 'sum' },
|
4861
|
+
{
|
4862
|
+
:header => 'Year',
|
4863
|
+
:formula => '=SUM(Table8[@[Quarter 1]:[Quarter 4]])',
|
4864
|
+
:total_function => 'sum'
|
4865
|
+
}
|
4866
|
+
]
|
4867
|
+
}
|
4868
|
+
)
|
4804
4869
|
|
4805
4870
|
###############################################################################
|
4806
4871
|
#
|
@@ -4816,41 +4881,41 @@ def test_tables
|
|
4816
4881
|
|
4817
4882
|
# Add a table to the worksheet.
|
4818
4883
|
worksheet12.add_table(
|
4819
|
-
|
4820
|
-
|
4821
|
-
|
4822
|
-
|
4823
|
-
|
4824
|
-
|
4825
|
-
|
4826
|
-
|
4827
|
-
|
4828
|
-
|
4829
|
-
|
4830
|
-
|
4831
|
-
|
4832
|
-
|
4833
|
-
|
4834
|
-
|
4835
|
-
|
4836
|
-
|
4837
|
-
|
4838
|
-
|
4839
|
-
|
4840
|
-
|
4841
|
-
|
4842
|
-
|
4843
|
-
|
4844
|
-
|
4845
|
-
|
4846
|
-
|
4847
|
-
|
4848
|
-
|
4849
|
-
|
4850
|
-
|
4851
|
-
|
4852
|
-
|
4853
|
-
|
4884
|
+
'B3:G8',
|
4885
|
+
{
|
4886
|
+
:data => data,
|
4887
|
+
:total_row => 1,
|
4888
|
+
:columns => [
|
4889
|
+
{ :header => 'Product', :total_string => 'Totals' },
|
4890
|
+
{
|
4891
|
+
:header => 'Quarter 1',
|
4892
|
+
:total_function => 'sum',
|
4893
|
+
:format => currency_format,
|
4894
|
+
},
|
4895
|
+
{
|
4896
|
+
:header => 'Quarter 2',
|
4897
|
+
:total_function => 'sum',
|
4898
|
+
:format => currency_format,
|
4899
|
+
},
|
4900
|
+
{
|
4901
|
+
:header => 'Quarter 3',
|
4902
|
+
:total_function => 'sum',
|
4903
|
+
:format => currency_format,
|
4904
|
+
},
|
4905
|
+
{
|
4906
|
+
:header => 'Quarter 4',
|
4907
|
+
:total_function => 'sum',
|
4908
|
+
:format => currency_format,
|
4909
|
+
},
|
4910
|
+
{
|
4911
|
+
:header => 'Year',
|
4912
|
+
:formula => '=SUM(Table8[@[Quarter 1]:[Quarter 4]])',
|
4913
|
+
:total_function => 'sum',
|
4914
|
+
:format => currency_format,
|
4915
|
+
}
|
4916
|
+
]
|
4917
|
+
}
|
4918
|
+
)
|
4854
4919
|
|
4855
4920
|
workbook.close
|
4856
4921
|
store_to_tempfile
|
@@ -4864,42 +4929,42 @@ def test_sparklines1
|
|
4864
4929
|
|
4865
4930
|
# Some sample data to plot.
|
4866
4931
|
data = [
|
4867
|
-
|
4868
|
-
|
4869
|
-
|
4870
|
-
|
4932
|
+
[ -2, 2, 3, -1, 0 ],
|
4933
|
+
[ 30, 20, 33, 20, 15 ],
|
4934
|
+
[ 1, -1, -1, 1, -1 ]
|
4935
|
+
]
|
4871
4936
|
|
4872
4937
|
# Write the sample data to the worksheet.
|
4873
4938
|
worksheet.write_col('A1', data)
|
4874
4939
|
|
4875
4940
|
# Add a line sparkline (the default) with markers.
|
4876
4941
|
worksheet.add_sparkline(
|
4877
|
-
|
4878
|
-
|
4879
|
-
|
4880
|
-
|
4881
|
-
|
4882
|
-
|
4942
|
+
{
|
4943
|
+
:location => 'F1',
|
4944
|
+
:range => 'Sheet1!A1:E1',
|
4945
|
+
:markers => 1
|
4946
|
+
}
|
4947
|
+
)
|
4883
4948
|
|
4884
4949
|
# Add a column sparkline with non-default style.
|
4885
4950
|
worksheet.add_sparkline(
|
4886
|
-
|
4887
|
-
|
4888
|
-
|
4889
|
-
|
4890
|
-
|
4891
|
-
|
4892
|
-
|
4951
|
+
{
|
4952
|
+
:location => 'F2',
|
4953
|
+
:range => 'Sheet1!A2:E2',
|
4954
|
+
:type => 'column',
|
4955
|
+
:style => 12
|
4956
|
+
}
|
4957
|
+
)
|
4893
4958
|
|
4894
4959
|
# Add a win/loss sparkline with negative values highlighted.
|
4895
4960
|
worksheet.add_sparkline(
|
4896
|
-
|
4897
|
-
|
4898
|
-
|
4899
|
-
|
4900
|
-
|
4901
|
-
|
4902
|
-
|
4961
|
+
{
|
4962
|
+
:location => 'F3',
|
4963
|
+
:range => 'Sheet1!A3:E3',
|
4964
|
+
:type => 'win_loss',
|
4965
|
+
:negative_points => 1
|
4966
|
+
}
|
4967
|
+
)
|
4903
4968
|
|
4904
4969
|
workbook.close
|
4905
4970
|
store_to_tempfile
|
@@ -4928,11 +4993,11 @@ def test_sparklines2
|
|
4928
4993
|
str = 'A default "line" sparkline.'
|
4929
4994
|
|
4930
4995
|
worksheet1.add_sparkline(
|
4931
|
-
|
4932
|
-
|
4933
|
-
|
4934
|
-
|
4935
|
-
|
4996
|
+
{
|
4997
|
+
:location => 'A2',
|
4998
|
+
:range => 'Sheet2!A1:J1'
|
4999
|
+
}
|
5000
|
+
)
|
4936
5001
|
|
4937
5002
|
worksheet1.write(row, 1, str)
|
4938
5003
|
row += 1
|
@@ -4942,12 +5007,12 @@ def test_sparklines2
|
|
4942
5007
|
str = 'A default "column" sparkline.'
|
4943
5008
|
|
4944
5009
|
worksheet1.add_sparkline(
|
4945
|
-
|
4946
|
-
|
4947
|
-
|
4948
|
-
|
4949
|
-
|
4950
|
-
|
5010
|
+
{
|
5011
|
+
:location => 'A3',
|
5012
|
+
:range => 'Sheet2!A2:J2',
|
5013
|
+
:type => 'column'
|
5014
|
+
}
|
5015
|
+
)
|
4951
5016
|
|
4952
5017
|
worksheet1.write(row, 1, str)
|
4953
5018
|
row += 1
|
@@ -4957,12 +5022,12 @@ def test_sparklines2
|
|
4957
5022
|
str = 'A default "win/loss" sparkline.'
|
4958
5023
|
|
4959
5024
|
worksheet1.add_sparkline(
|
4960
|
-
|
4961
|
-
|
4962
|
-
|
4963
|
-
|
4964
|
-
|
4965
|
-
|
5025
|
+
{
|
5026
|
+
:location => 'A4',
|
5027
|
+
:range => 'Sheet2!A3:J3',
|
5028
|
+
:type => 'win_loss'
|
5029
|
+
}
|
5030
|
+
)
|
4966
5031
|
|
4967
5032
|
worksheet1.write(row, 1, str)
|
4968
5033
|
row += 2
|
@@ -4972,12 +5037,12 @@ def test_sparklines2
|
|
4972
5037
|
str = 'Line with markers.'
|
4973
5038
|
|
4974
5039
|
worksheet1.add_sparkline(
|
4975
|
-
|
4976
|
-
|
4977
|
-
|
4978
|
-
|
4979
|
-
|
4980
|
-
|
5040
|
+
{
|
5041
|
+
:location => 'A6',
|
5042
|
+
:range => 'Sheet2!A1:J1',
|
5043
|
+
:markers => 1
|
5044
|
+
}
|
5045
|
+
)
|
4981
5046
|
|
4982
5047
|
worksheet1.write(row, 1, str)
|
4983
5048
|
row += 1
|
@@ -4987,13 +5052,13 @@ def test_sparklines2
|
|
4987
5052
|
str = 'Line with high and low points.'
|
4988
5053
|
|
4989
5054
|
worksheet1.add_sparkline(
|
4990
|
-
|
4991
|
-
|
4992
|
-
|
4993
|
-
|
4994
|
-
|
4995
|
-
|
4996
|
-
|
5055
|
+
{
|
5056
|
+
:location => 'A7',
|
5057
|
+
:range => 'Sheet2!A1:J1',
|
5058
|
+
:high_point => 1,
|
5059
|
+
:low_point => 1
|
5060
|
+
}
|
5061
|
+
)
|
4997
5062
|
|
4998
5063
|
worksheet1.write(row, 1, str)
|
4999
5064
|
row += 1
|
@@ -5003,13 +5068,13 @@ def test_sparklines2
|
|
5003
5068
|
str = 'Line with first and last point markers.'
|
5004
5069
|
|
5005
5070
|
worksheet1.add_sparkline(
|
5006
|
-
|
5007
|
-
|
5008
|
-
|
5009
|
-
|
5010
|
-
|
5011
|
-
|
5012
|
-
|
5071
|
+
{
|
5072
|
+
:location => 'A8',
|
5073
|
+
:range => 'Sheet2!A1:J1',
|
5074
|
+
:first_point => 1,
|
5075
|
+
:last_point => 1
|
5076
|
+
}
|
5077
|
+
)
|
5013
5078
|
|
5014
5079
|
worksheet1.write(row, 1, str)
|
5015
5080
|
row += 1
|
@@ -5019,12 +5084,12 @@ def test_sparklines2
|
|
5019
5084
|
str = 'Line with negative point markers.'
|
5020
5085
|
|
5021
5086
|
worksheet1.add_sparkline(
|
5022
|
-
|
5023
|
-
|
5024
|
-
|
5025
|
-
|
5026
|
-
|
5027
|
-
|
5087
|
+
{
|
5088
|
+
:location => 'A9',
|
5089
|
+
:range => 'Sheet2!A1:J1',
|
5090
|
+
:negative_points => 1
|
5091
|
+
}
|
5092
|
+
)
|
5028
5093
|
|
5029
5094
|
worksheet1.write(row, 1, str)
|
5030
5095
|
row += 1
|
@@ -5034,12 +5099,12 @@ def test_sparklines2
|
|
5034
5099
|
str = 'Line with axis.'
|
5035
5100
|
|
5036
5101
|
worksheet1.add_sparkline(
|
5037
|
-
|
5038
|
-
|
5039
|
-
|
5040
|
-
|
5041
|
-
|
5042
|
-
|
5102
|
+
{
|
5103
|
+
:location => 'A10',
|
5104
|
+
:range => 'Sheet2!A1:J1',
|
5105
|
+
:axis => 1
|
5106
|
+
}
|
5107
|
+
)
|
5043
5108
|
|
5044
5109
|
worksheet1.write(row, 1, str)
|
5045
5110
|
row += 2
|
@@ -5049,12 +5114,12 @@ def test_sparklines2
|
|
5049
5114
|
str = 'Column with default style (1).'
|
5050
5115
|
|
5051
5116
|
worksheet1.add_sparkline(
|
5052
|
-
|
5053
|
-
|
5054
|
-
|
5055
|
-
|
5056
|
-
|
5057
|
-
|
5117
|
+
{
|
5118
|
+
:location => 'A12',
|
5119
|
+
:range => 'Sheet2!A2:J2',
|
5120
|
+
:type => 'column'
|
5121
|
+
}
|
5122
|
+
)
|
5058
5123
|
|
5059
5124
|
worksheet1.write(row, 1, str)
|
5060
5125
|
row += 1
|
@@ -5064,13 +5129,13 @@ def test_sparklines2
|
|
5064
5129
|
str = 'Column with style 2.'
|
5065
5130
|
|
5066
5131
|
worksheet1.add_sparkline(
|
5067
|
-
|
5068
|
-
|
5069
|
-
|
5070
|
-
|
5071
|
-
|
5072
|
-
|
5073
|
-
|
5132
|
+
{
|
5133
|
+
:location => 'A13',
|
5134
|
+
:range => 'Sheet2!A2:J2',
|
5135
|
+
:type => 'column',
|
5136
|
+
:style => 2
|
5137
|
+
}
|
5138
|
+
)
|
5074
5139
|
|
5075
5140
|
worksheet1.write(row, 1, str)
|
5076
5141
|
row += 1
|
@@ -5080,13 +5145,13 @@ def test_sparklines2
|
|
5080
5145
|
str = 'Column with style 3.'
|
5081
5146
|
|
5082
5147
|
worksheet1.add_sparkline(
|
5083
|
-
|
5084
|
-
|
5085
|
-
|
5086
|
-
|
5087
|
-
|
5088
|
-
|
5089
|
-
|
5148
|
+
{
|
5149
|
+
:location => 'A14',
|
5150
|
+
:range => 'Sheet2!A2:J2',
|
5151
|
+
:type => 'column',
|
5152
|
+
:style => 3
|
5153
|
+
}
|
5154
|
+
)
|
5090
5155
|
|
5091
5156
|
worksheet1.write(row, 1, str)
|
5092
5157
|
row += 1
|
@@ -5096,13 +5161,13 @@ def test_sparklines2
|
|
5096
5161
|
str = 'Column with style 4.'
|
5097
5162
|
|
5098
5163
|
worksheet1.add_sparkline(
|
5099
|
-
|
5100
|
-
|
5101
|
-
|
5102
|
-
|
5103
|
-
|
5104
|
-
|
5105
|
-
|
5164
|
+
{
|
5165
|
+
:location => 'A15',
|
5166
|
+
:range => 'Sheet2!A2:J2',
|
5167
|
+
:type => 'column',
|
5168
|
+
:style => 4
|
5169
|
+
}
|
5170
|
+
)
|
5106
5171
|
|
5107
5172
|
worksheet1.write(row, 1, str)
|
5108
5173
|
row += 1
|
@@ -5112,13 +5177,13 @@ def test_sparklines2
|
|
5112
5177
|
str = 'Column with style 5.'
|
5113
5178
|
|
5114
5179
|
worksheet1.add_sparkline(
|
5115
|
-
|
5116
|
-
|
5117
|
-
|
5118
|
-
|
5119
|
-
|
5120
|
-
|
5121
|
-
|
5180
|
+
{
|
5181
|
+
:location => 'A16',
|
5182
|
+
:range => 'Sheet2!A2:J2',
|
5183
|
+
:type => 'column',
|
5184
|
+
:style => 5
|
5185
|
+
}
|
5186
|
+
)
|
5122
5187
|
|
5123
5188
|
worksheet1.write(row, 1, str)
|
5124
5189
|
row += 1
|
@@ -5128,13 +5193,13 @@ def test_sparklines2
|
|
5128
5193
|
str = 'Column with style 6.'
|
5129
5194
|
|
5130
5195
|
worksheet1.add_sparkline(
|
5131
|
-
|
5132
|
-
|
5133
|
-
|
5134
|
-
|
5135
|
-
|
5136
|
-
|
5137
|
-
|
5196
|
+
{
|
5197
|
+
:location => 'A17',
|
5198
|
+
:range => 'Sheet2!A2:J2',
|
5199
|
+
:type => 'column',
|
5200
|
+
:style => 6
|
5201
|
+
}
|
5202
|
+
)
|
5138
5203
|
|
5139
5204
|
worksheet1.write(row, 1, str)
|
5140
5205
|
row += 1
|
@@ -5144,13 +5209,13 @@ def test_sparklines2
|
|
5144
5209
|
str = 'Column with a user defined colour.'
|
5145
5210
|
|
5146
5211
|
worksheet1.add_sparkline(
|
5147
|
-
|
5148
|
-
|
5149
|
-
|
5150
|
-
|
5151
|
-
|
5152
|
-
|
5153
|
-
|
5212
|
+
{
|
5213
|
+
:location => 'A18',
|
5214
|
+
:range => 'Sheet2!A2:J2',
|
5215
|
+
:type => 'column',
|
5216
|
+
:series_color => '#E965E0'
|
5217
|
+
}
|
5218
|
+
)
|
5154
5219
|
|
5155
5220
|
worksheet1.write(row, 1, str)
|
5156
5221
|
row += 2
|
@@ -5160,12 +5225,12 @@ def test_sparklines2
|
|
5160
5225
|
str = 'A win/loss sparkline.'
|
5161
5226
|
|
5162
5227
|
worksheet1.add_sparkline(
|
5163
|
-
|
5164
|
-
|
5165
|
-
|
5166
|
-
|
5167
|
-
|
5168
|
-
|
5228
|
+
{
|
5229
|
+
:location => 'A20',
|
5230
|
+
:range => 'Sheet2!A3:J3',
|
5231
|
+
:type => 'win_loss'
|
5232
|
+
}
|
5233
|
+
)
|
5169
5234
|
|
5170
5235
|
worksheet1.write(row, 1, str)
|
5171
5236
|
row += 1
|
@@ -5175,13 +5240,13 @@ def test_sparklines2
|
|
5175
5240
|
str = 'A win/loss sparkline with negative points highlighted.'
|
5176
5241
|
|
5177
5242
|
worksheet1.add_sparkline(
|
5178
|
-
|
5179
|
-
|
5180
|
-
|
5181
|
-
|
5182
|
-
|
5183
|
-
|
5184
|
-
|
5243
|
+
{
|
5244
|
+
:location => 'A21',
|
5245
|
+
:range => 'Sheet2!A3:J3',
|
5246
|
+
:type => 'win_loss',
|
5247
|
+
:negative_points => 1
|
5248
|
+
}
|
5249
|
+
)
|
5185
5250
|
|
5186
5251
|
worksheet1.write(row, 1, str)
|
5187
5252
|
row += 2
|
@@ -5191,13 +5256,13 @@ def test_sparklines2
|
|
5191
5256
|
str = 'A left to right column (the default).'
|
5192
5257
|
|
5193
5258
|
worksheet1.add_sparkline(
|
5194
|
-
|
5195
|
-
|
5196
|
-
|
5197
|
-
|
5198
|
-
|
5199
|
-
|
5200
|
-
|
5259
|
+
{
|
5260
|
+
:location => 'A23',
|
5261
|
+
:range => 'Sheet2!A4:J4',
|
5262
|
+
:type => 'column',
|
5263
|
+
:style => 20
|
5264
|
+
}
|
5265
|
+
)
|
5201
5266
|
|
5202
5267
|
worksheet1.write(row, 1, str)
|
5203
5268
|
row += 1
|
@@ -5207,14 +5272,14 @@ def test_sparklines2
|
|
5207
5272
|
str = 'A right to left column.'
|
5208
5273
|
|
5209
5274
|
worksheet1.add_sparkline(
|
5210
|
-
|
5211
|
-
|
5212
|
-
|
5213
|
-
|
5214
|
-
|
5215
|
-
|
5216
|
-
|
5217
|
-
|
5275
|
+
{
|
5276
|
+
:location => 'A24',
|
5277
|
+
:range => 'Sheet2!A4:J4',
|
5278
|
+
:type => 'column',
|
5279
|
+
:style => 20,
|
5280
|
+
:reverse => 1
|
5281
|
+
}
|
5282
|
+
)
|
5218
5283
|
|
5219
5284
|
worksheet1.write(row, 1, str)
|
5220
5285
|
row += 1
|
@@ -5224,13 +5289,13 @@ def test_sparklines2
|
|
5224
5289
|
str = 'Sparkline and text in one cell.'
|
5225
5290
|
|
5226
5291
|
worksheet1.add_sparkline(
|
5227
|
-
|
5228
|
-
|
5229
|
-
|
5230
|
-
|
5231
|
-
|
5232
|
-
|
5233
|
-
|
5292
|
+
{
|
5293
|
+
:location => 'A25',
|
5294
|
+
:range => 'Sheet2!A4:J4',
|
5295
|
+
:type => 'column',
|
5296
|
+
:style => 20
|
5297
|
+
}
|
5298
|
+
)
|
5234
5299
|
|
5235
5300
|
worksheet1.write(row, 0, 'Growth')
|
5236
5301
|
worksheet1.write(row, 1, str)
|
@@ -5241,12 +5306,12 @@ def test_sparklines2
|
|
5241
5306
|
str = 'A grouped sparkline. Changes are applied to all three.'
|
5242
5307
|
|
5243
5308
|
worksheet1.add_sparkline(
|
5244
|
-
|
5245
|
-
|
5246
|
-
|
5247
|
-
|
5248
|
-
|
5249
|
-
|
5309
|
+
{
|
5310
|
+
:location => [ 'A27', 'A28', 'A29' ],
|
5311
|
+
:range => [ 'Sheet2!A5:J5', 'Sheet2!A6:J6', 'Sheet2!A7:J7' ],
|
5312
|
+
:markers => 1
|
5313
|
+
}
|
5314
|
+
)
|
5250
5315
|
|
5251
5316
|
worksheet1.write(row, 1, str)
|
5252
5317
|
row += 1
|
@@ -5258,23 +5323,23 @@ def test_sparklines2
|
|
5258
5323
|
worksheet2.set_column('A:J', 11)
|
5259
5324
|
|
5260
5325
|
data = [
|
5261
|
-
|
5262
|
-
|
5326
|
+
# Simple line data.
|
5327
|
+
[ -2, 2, 3, -1, 0, -2, 3, 2, 1, 0 ],
|
5263
5328
|
|
5264
|
-
|
5265
|
-
|
5329
|
+
# Simple column data.
|
5330
|
+
[ 30, 20, 33, 20, 15, 5, 5, 15, 10, 15 ],
|
5266
5331
|
|
5267
|
-
|
5268
|
-
|
5332
|
+
# Simple win/loss data.
|
5333
|
+
[ 1, 1, -1, -1, 1, -1, 1, 1, 1, -1 ],
|
5269
5334
|
|
5270
|
-
|
5271
|
-
|
5335
|
+
# Unbalanced histogram.
|
5336
|
+
[ 5, 6, 7, 10, 15, 20, 30, 50, 70, 100 ],
|
5272
5337
|
|
5273
|
-
|
5274
|
-
|
5275
|
-
|
5276
|
-
|
5277
|
-
|
5338
|
+
# Data for the grouped sparkline example.
|
5339
|
+
[ -2, 2, 3, -1, 0, -2, 3, 2, 1, 0 ],
|
5340
|
+
[ 3, -1, 0, -2, 3, 2, 1, 0, 2, 1 ],
|
5341
|
+
[ 0, -2, 3, 2, 1, 0, 1, 2, 3, 1 ]
|
5342
|
+
]
|
5278
5343
|
|
5279
5344
|
# Write the sample data to the worksheet.
|
5280
5345
|
worksheet2.write_col('A1', data)
|
@@ -5339,10 +5404,10 @@ def test_chart_data_table
|
|
5339
5404
|
# Add the worksheet data that the charts will refer to.
|
5340
5405
|
headings = [ 'Number', 'Batch 1', 'Batch 2' ]
|
5341
5406
|
data = [
|
5342
|
-
|
5343
|
-
|
5344
|
-
|
5345
|
-
|
5407
|
+
[ 2, 3, 4, 5, 6, 7 ],
|
5408
|
+
[ 10, 40, 50, 20, 10, 50 ],
|
5409
|
+
[ 30, 60, 70, 50, 40, 30 ]
|
5410
|
+
]
|
5346
5411
|
|
5347
5412
|
worksheet.write('A1', headings, bold)
|
5348
5413
|
worksheet.write('A2', data)
|
@@ -5352,18 +5417,18 @@ def test_chart_data_table
|
|
5352
5417
|
|
5353
5418
|
# Configure the first series.
|
5354
5419
|
chart1.add_series(
|
5355
|
-
|
5356
|
-
|
5357
|
-
|
5358
|
-
|
5420
|
+
:name => '=Sheet1!$B$1',
|
5421
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
5422
|
+
:values => '=Sheet1!$B$2:$B$7'
|
5423
|
+
)
|
5359
5424
|
|
5360
5425
|
# Configure second series. Note alternative use of array ref to define
|
5361
5426
|
# ranges: [ sheetname, row_start, row_end, col_start, col_end ].
|
5362
5427
|
chart1.add_series(
|
5363
|
-
|
5364
|
-
|
5365
|
-
|
5366
|
-
|
5428
|
+
:name => '=Sheet1!$C$1',
|
5429
|
+
:categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
5430
|
+
:values => [ 'Sheet1', 1, 6, 2, 2 ]
|
5431
|
+
)
|
5367
5432
|
|
5368
5433
|
# Add a chart title and some axis labels.
|
5369
5434
|
chart1.set_title(:name => 'Chart with Data Table')
|
@@ -5383,18 +5448,18 @@ def test_chart_data_table
|
|
5383
5448
|
|
5384
5449
|
# Configure the first series.
|
5385
5450
|
chart2.add_series(
|
5386
|
-
|
5387
|
-
|
5388
|
-
|
5389
|
-
|
5451
|
+
:name => '=Sheet1!$B$1',
|
5452
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
5453
|
+
:values => '=Sheet1!$B$2:$B$7'
|
5454
|
+
)
|
5390
5455
|
|
5391
5456
|
# Configure second series. Note alternative use of array ref to define
|
5392
5457
|
# ranges: [ sheetname, row_start, row_end, col_start, col_end ].
|
5393
5458
|
chart2.add_series(
|
5394
|
-
|
5395
|
-
|
5396
|
-
|
5397
|
-
|
5459
|
+
:name => '=Sheet1!$C$1',
|
5460
|
+
:categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
5461
|
+
:values => [ 'Sheet1', 1, 6, 2, 2 ]
|
5462
|
+
)
|
5398
5463
|
|
5399
5464
|
# Add a chart title and some axis labels.
|
5400
5465
|
chart2.set_title(:name => 'Data Table with legend keys')
|
@@ -5424,10 +5489,10 @@ def test_chart_data_tools
|
|
5424
5489
|
# Add the worksheet data that the charts will refer to.
|
5425
5490
|
headings = [ 'Number', 'Data 1', 'Data 2' ]
|
5426
5491
|
data = [
|
5427
|
-
|
5428
|
-
|
5429
|
-
|
5430
|
-
|
5492
|
+
[ 2, 3, 4, 5, 6, 7 ],
|
5493
|
+
[ 10, 40, 50, 20, 10, 50 ],
|
5494
|
+
[ 30, 60, 70, 50, 40, 30 ]
|
5495
|
+
]
|
5431
5496
|
|
5432
5497
|
worksheet.write('A1', headings, bold)
|
5433
5498
|
worksheet.write('A2', data)
|
@@ -5443,20 +5508,20 @@ def test_chart_data_tools
|
|
5443
5508
|
|
5444
5509
|
# Configure the first series with a polynomial trendline.
|
5445
5510
|
chart1.add_series(
|
5446
|
-
|
5447
|
-
|
5448
|
-
|
5449
|
-
|
5450
|
-
|
5451
|
-
|
5452
|
-
|
5511
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
5512
|
+
:values => '=Sheet1!$B$2:$B$7',
|
5513
|
+
:trendline => {
|
5514
|
+
:type => 'polynomial',
|
5515
|
+
:order => 3,
|
5516
|
+
}
|
5517
|
+
)
|
5453
5518
|
|
5454
5519
|
# Configure the second series with a moving average trendline.
|
5455
5520
|
chart1.add_series(
|
5456
|
-
|
5457
|
-
|
5458
|
-
|
5459
|
-
|
5521
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
5522
|
+
:values => '=Sheet1!$C$2:$C$7',
|
5523
|
+
:trendline => { :type => 'linear' }
|
5524
|
+
)
|
5460
5525
|
|
5461
5526
|
# Add a chart title. and some axis labels.
|
5462
5527
|
chart1.set_title(:name => 'Chart with Trendlines')
|
@@ -5474,17 +5539,17 @@ def test_chart_data_tools
|
|
5474
5539
|
|
5475
5540
|
# Configure the first series.
|
5476
5541
|
chart2.add_series(
|
5477
|
-
|
5478
|
-
|
5479
|
-
|
5480
|
-
|
5481
|
-
|
5542
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
5543
|
+
:values => '=Sheet1!$B$2:$B$7',
|
5544
|
+
:data_labels => { :value => 1 },
|
5545
|
+
:marker => { :type => 'automatic' }
|
5546
|
+
)
|
5482
5547
|
|
5483
5548
|
# Configure the second series.
|
5484
5549
|
chart2.add_series(
|
5485
|
-
|
5486
|
-
|
5487
|
-
|
5550
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
5551
|
+
:values => '=Sheet1!$C$2:$C$7'
|
5552
|
+
)
|
5488
5553
|
|
5489
5554
|
# Add a chart title. and some axis labels.
|
5490
5555
|
chart2.set_title(:name => 'Chart with Data Labels and Markers')
|
@@ -5502,16 +5567,16 @@ def test_chart_data_tools
|
|
5502
5567
|
|
5503
5568
|
# Configure the first series.
|
5504
5569
|
chart3.add_series(
|
5505
|
-
|
5506
|
-
|
5507
|
-
|
5508
|
-
|
5570
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
5571
|
+
:values => '=Sheet1!$B$2:$B$7',
|
5572
|
+
:y_error_bars => { :type => 'standard_error' }
|
5573
|
+
)
|
5509
5574
|
|
5510
5575
|
# Configure the second series.
|
5511
5576
|
chart3.add_series(
|
5512
|
-
|
5513
|
-
|
5514
|
-
|
5577
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
5578
|
+
:values => '=Sheet1!$C$2:$C$7'
|
5579
|
+
)
|
5515
5580
|
|
5516
5581
|
# Add a chart title. and some axis labels.
|
5517
5582
|
chart3.set_title(:name => 'Chart with Error Bars')
|
@@ -5532,15 +5597,15 @@ def test_chart_data_tools
|
|
5532
5597
|
|
5533
5598
|
# Configure the first series.
|
5534
5599
|
chart4.add_series(
|
5535
|
-
|
5536
|
-
|
5537
|
-
|
5600
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
5601
|
+
:values => '=Sheet1!$B$2:$B$7'
|
5602
|
+
)
|
5538
5603
|
|
5539
5604
|
# Configure the second series.
|
5540
5605
|
chart4.add_series(
|
5541
|
-
|
5542
|
-
|
5543
|
-
|
5606
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
5607
|
+
:values => '=Sheet1!$C$2:$C$7'
|
5608
|
+
)
|
5544
5609
|
|
5545
5610
|
# Add a chart title. and some axis labels.
|
5546
5611
|
chart4.set_title(:name => 'Chart with Up-Down Bars')
|
@@ -5561,15 +5626,15 @@ def test_chart_data_tools
|
|
5561
5626
|
|
5562
5627
|
# Configure the first series.
|
5563
5628
|
chart5.add_series(
|
5564
|
-
|
5565
|
-
|
5566
|
-
|
5629
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
5630
|
+
:values => '=Sheet1!$B$2:$B$7'
|
5631
|
+
)
|
5567
5632
|
|
5568
5633
|
# Configure the second series.
|
5569
5634
|
chart5.add_series(
|
5570
|
-
|
5571
|
-
|
5572
|
-
|
5635
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
5636
|
+
:values => '=Sheet1!$C$2:$C$7'
|
5637
|
+
)
|
5573
5638
|
|
5574
5639
|
# Add a chart title. and some axis labels.
|
5575
5640
|
chart5.set_title(:name => 'Chart with High-Low Lines')
|
@@ -5590,15 +5655,15 @@ def test_chart_data_tools
|
|
5590
5655
|
|
5591
5656
|
# Configure the first series.
|
5592
5657
|
chart6.add_series(
|
5593
|
-
|
5594
|
-
|
5595
|
-
|
5658
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
5659
|
+
:values => '=Sheet1!$B$2:$B$7'
|
5660
|
+
)
|
5596
5661
|
|
5597
5662
|
# Configure the second series.
|
5598
5663
|
chart6.add_series(
|
5599
|
-
|
5600
|
-
|
5601
|
-
|
5664
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
5665
|
+
:values => '=Sheet1!$C$2:$C$7'
|
5666
|
+
)
|
5602
5667
|
|
5603
5668
|
# Add a chart title. and some axis labels.
|
5604
5669
|
chart6.set_title(:name => 'Chart with Drop Lines')
|