write_xlsx 0.99.0 → 1.07.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +0 -1
- data/Changes +70 -0
- data/README.md +1 -1
- 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_labels.rb +320 -0
- 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 +90 -12
- 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 +78 -43
- data/lib/write_xlsx/chart.rb +163 -34
- 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 +16 -2
- 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/series.rb +100 -0
- data/lib/write_xlsx/chart/stock.rb +1 -1
- data/lib/write_xlsx/chartsheet.rb +5 -5
- data/lib/write_xlsx/drawing.rb +86 -30
- data/lib/write_xlsx/format.rb +5 -5
- data/lib/write_xlsx/package/comments.rb +11 -11
- data/lib/write_xlsx/package/relationships.rb +4 -4
- data/lib/write_xlsx/package/styles.rb +26 -8
- data/lib/write_xlsx/package/table.rb +8 -7
- data/lib/write_xlsx/package/vml.rb +20 -19
- data/lib/write_xlsx/shape.rb +4 -3
- data/lib/write_xlsx/sheets.rb +18 -16
- data/lib/write_xlsx/sparkline.rb +1 -1
- data/lib/write_xlsx/utility.rb +40 -7
- data/lib/write_xlsx/version.rb +1 -1
- data/lib/write_xlsx/workbook.rb +69 -44
- data/lib/write_xlsx/worksheet.rb +206 -138
- data/lib/write_xlsx/worksheet/hyperlink.rb +16 -37
- 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_data_labels.xlsx +0 -0
- data/test/perl_output/chart_gauge.xlsx +0 -0
- data/test/perl_output/chart_line.xlsx +0 -0
- data/test/perl_output/comments2.xlsx +0 -0
- data/test/perl_output/tables.xlsx +0 -0
- data/test/regression/images/red2.png +0 -0
- data/test/regression/test_array_formula04.rb +31 -0
- data/test/regression/test_chart_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_data_labels26.rb +44 -0
- data/test/regression/test_chart_data_labels27.rb +44 -0
- data/test/regression/test_chart_data_labels28.rb +52 -0
- data/test/regression/test_chart_data_labels29.rb +43 -0
- data/test/regression/test_chart_data_labels30.rb +46 -0
- data/test/regression/test_chart_data_labels31.rb +49 -0
- data/test/regression/test_chart_data_labels32.rb +54 -0
- data/test/regression/test_chart_data_labels33.rb +52 -0
- data/test/regression/test_chart_data_labels34.rb +54 -0
- data/test/regression/test_chart_data_labels35.rb +46 -0
- data/test/regression/test_chart_data_labels36.rb +54 -0
- data/test/regression/test_chart_data_labels37.rb +51 -0
- data/test/regression/test_chart_data_labels38.rb +54 -0
- data/test/regression/test_chart_data_labels39.rb +53 -0
- data/test/regression/test_chart_data_labels40.rb +53 -0
- data/test/regression/test_chart_data_labels41.rb +54 -0
- data/test/regression/test_chart_data_labels42.rb +58 -0
- data/test/regression/test_chart_data_labels43.rb +58 -0
- data/test/regression/test_chart_data_labels44.rb +56 -0
- data/test/regression/test_chart_data_labels45.rb +57 -0
- data/test/regression/test_chart_data_labels46.rb +61 -0
- data/test/regression/test_chart_data_labels47.rb +61 -0
- data/test/regression/test_chart_doughnut07.rb +37 -0
- data/test/regression/test_chart_font09.rb +1 -1
- data/test/regression/test_chart_line05.rb +43 -0
- data/test/regression/test_chart_line06.rb +43 -0
- data/test/regression/test_chart_size03.rb +4 -1
- data/test/regression/test_comment14.rb +29 -0
- data/test/regression/test_comment15.rb +28 -0
- data/test/regression/test_comment16.rb +34 -0
- data/test/regression/test_header_image15.rb +36 -0
- data/test/regression/test_header_image16.rb +42 -0
- data/test/regression/test_header_image17.rb +46 -0
- data/test/regression/test_header_image18.rb +48 -0
- data/test/regression/test_header_image19.rb +36 -0
- data/test/regression/test_hyperlink32.rb +27 -0
- data/test/regression/test_hyperlink33.rb +28 -0
- data/test/regression/test_hyperlink34.rb +33 -0
- data/test/regression/test_hyperlink35.rb +39 -0
- data/test/regression/test_hyperlink36.rb +34 -0
- data/test/regression/test_hyperlink37.rb +33 -0
- data/test/regression/test_hyperlink38.rb +27 -0
- data/test/regression/test_hyperlink39.rb +27 -0
- data/test/regression/test_hyperlink40.rb +27 -0
- data/test/regression/test_hyperlink41.rb +27 -0
- data/test/regression/test_hyperlink42.rb +27 -0
- data/test/regression/test_hyperlink43.rb +27 -0
- data/test/regression/test_hyperlink44.rb +27 -0
- data/test/regression/test_hyperlink45.rb +27 -0
- data/test/regression/test_hyperlink47.rb +27 -0
- data/test/regression/test_hyperlink48.rb +31 -0
- data/test/regression/test_hyperlink49.rb +29 -0
- data/test/regression/test_image06.rb +5 -5
- 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_image44.rb +28 -0
- data/test/regression/test_image45.rb +29 -0
- data/test/regression/test_image46.rb +29 -0
- data/test/regression/test_image47.rb +28 -0
- data/test/regression/test_image48.rb +32 -0
- data/test/regression/test_image49.rb +38 -0
- data/test/regression/test_image50.rb +24 -0
- data/test/regression/test_image51.rb +30 -0
- data/test/regression/test_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_object_position12.rb +25 -0
- data/test/regression/test_object_position13.rb +25 -0
- data/test/regression/test_object_position14.rb +25 -0
- data/test/regression/test_object_position15.rb +29 -0
- data/test/regression/test_object_position16.rb +29 -0
- data/test/regression/test_object_position17.rb +29 -0
- data/test/regression/test_object_position18.rb +29 -0
- data/test/regression/test_object_position19.rb +29 -0
- data/test/regression/test_object_position20.rb +29 -0
- data/test/regression/test_shape_connect01.rb +4 -2
- data/test/regression/test_table24.rb +27 -0
- data/test/regression/test_table25.rb +27 -0
- data/test/regression/xlsx_files/array_formula04.xlsx +0 -0
- 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_data_labels26.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels27.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels28.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels29.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels30.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels31.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels32.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels33.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels34.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels35.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels36.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels37.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels38.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels39.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels40.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels41.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels42.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels43.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels44.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels45.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels46.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels47.xlsx +0 -0
- data/test/regression/xlsx_files/chart_doughnut07.xlsx +0 -0
- data/test/regression/xlsx_files/chart_font09.xlsx +0 -0
- data/test/regression/xlsx_files/chart_line05.xlsx +0 -0
- data/test/regression/xlsx_files/chart_line06.xlsx +0 -0
- data/test/regression/xlsx_files/comment14.xlsx +0 -0
- data/test/regression/xlsx_files/comment15.xlsx +0 -0
- data/test/regression/xlsx_files/comment16.xlsx +0 -0
- data/test/regression/xlsx_files/header_image15.xlsx +0 -0
- data/test/regression/xlsx_files/header_image16.xlsx +0 -0
- data/test/regression/xlsx_files/header_image17.xlsx +0 -0
- data/test/regression/xlsx_files/header_image18.xlsx +0 -0
- data/test/regression/xlsx_files/header_image19.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink32.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink33.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink34.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink35.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink36.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink37.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink38.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink39.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink40.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink41.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink42.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink43.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink44.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink45.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink46.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink47.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink48.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink49.xlsx +0 -0
- data/test/regression/xlsx_files/image06.xlsx +0 -0
- data/test/regression/xlsx_files/image44.xlsx +0 -0
- data/test/regression/xlsx_files/image45.xlsx +0 -0
- data/test/regression/xlsx_files/image46.xlsx +0 -0
- data/test/regression/xlsx_files/image47.xlsx +0 -0
- data/test/regression/xlsx_files/image48.xlsx +0 -0
- data/test/regression/xlsx_files/image49.xlsx +0 -0
- data/test/regression/xlsx_files/image50.xlsx +0 -0
- data/test/regression/xlsx_files/image51.xlsx +0 -0
- data/test/regression/xlsx_files/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/regression/xlsx_files/object_position12.xlsx +0 -0
- data/test/regression/xlsx_files/object_position13.xlsx +0 -0
- data/test/regression/xlsx_files/object_position14.xlsx +0 -0
- data/test/regression/xlsx_files/object_position15.xlsx +0 -0
- data/test/regression/xlsx_files/object_position16.xlsx +0 -0
- data/test/regression/xlsx_files/object_position17.xlsx +0 -0
- data/test/regression/xlsx_files/object_position18.xlsx +0 -0
- data/test/regression/xlsx_files/object_position19.xlsx +0 -0
- data/test/regression/xlsx_files/object_position20.xlsx +0 -0
- data/test/regression/xlsx_files/table24.xlsx +0 -0
- data/test/regression/xlsx_files/table25.xlsx +0 -0
- data/test/test_example_match.rb +1268 -780
- data/test/workbook/test_check_sheetname.rb +51 -0
- data/write_xlsx.gemspec +1 -0
- metadata +367 -5
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
|
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
|
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,381 @@ def test_autofilter
|
|
242
242
|
compare_xlsx(File.join(@perl_output, @xlsx), @tempfile.path)
|
243
243
|
end
|
244
244
|
|
245
|
+
def test_chart_data_labels
|
246
|
+
@xlsx = 'chart_data_labels.xlsx'
|
247
|
+
workbook = WriteXLSX.new(@io)
|
248
|
+
|
249
|
+
worksheet = workbook.add_worksheet
|
250
|
+
bold = workbook.add_format(:bold => 1)
|
251
|
+
|
252
|
+
# Add the worksheet data that the charts will refer to.
|
253
|
+
headings = ['Number', 'Data', 'Text']
|
254
|
+
data = [
|
255
|
+
[ 2, 3, 4, 5, 6, 7 ],
|
256
|
+
[20, 10, 20, 30, 40, 30 ],
|
257
|
+
['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
|
258
|
+
]
|
259
|
+
|
260
|
+
worksheet.write('A1', headings, bold)
|
261
|
+
worksheet.write('A2', data)
|
262
|
+
|
263
|
+
|
264
|
+
#######################################################################
|
265
|
+
#
|
266
|
+
# Example with standard data labels.
|
267
|
+
#
|
268
|
+
|
269
|
+
# Create a Column chart.
|
270
|
+
chart1 = workbook.add_chart(:type => 'column', :embedded => 1)
|
271
|
+
|
272
|
+
# Configure the data series and add the data labels.
|
273
|
+
chart1.add_series(
|
274
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
275
|
+
:values => '=Sheet1!$B$2:$B$7',
|
276
|
+
:data_labels => { :value => 1 }
|
277
|
+
)
|
278
|
+
|
279
|
+
# Add a chart title.
|
280
|
+
chart1.set_title(:name => 'Chart with standard data labels')
|
281
|
+
|
282
|
+
# Turn off the chart legend.
|
283
|
+
chart1.set_legend(:none => 1)
|
284
|
+
|
285
|
+
# Insert the chart into the worksheet (with an offset).
|
286
|
+
worksheet.insert_chart('D2', chart1, { :x_offset => 25, :y_offset => 10 })
|
287
|
+
|
288
|
+
|
289
|
+
#######################################################################
|
290
|
+
#
|
291
|
+
# Example with value and category data labels.
|
292
|
+
#
|
293
|
+
|
294
|
+
# Create a Column chart.
|
295
|
+
chart2 = workbook.add_chart(:type => 'column', :embedded => 1)
|
296
|
+
|
297
|
+
# Configure the data series and add the data labels.
|
298
|
+
chart2.add_series(
|
299
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
300
|
+
:values => '=Sheet1!$B$2:$B$7',
|
301
|
+
:data_labels => { :value => 1, :category => 1 }
|
302
|
+
)
|
303
|
+
|
304
|
+
# Add a chart title.
|
305
|
+
chart2.set_title(:name => 'Category and Value data labels')
|
306
|
+
|
307
|
+
# Turn off the chart legend.
|
308
|
+
chart2.set_legend(:none => 1)
|
309
|
+
|
310
|
+
# Insert the chart into the worksheet (with an offset).
|
311
|
+
worksheet.insert_chart('D18', chart2, { :x_offset => 25, :y_offset => 10 })
|
312
|
+
|
313
|
+
|
314
|
+
#######################################################################
|
315
|
+
#
|
316
|
+
# Example with standard data labels with different font.
|
317
|
+
#
|
318
|
+
|
319
|
+
# Create a Column chart.
|
320
|
+
chart3 = workbook.add_chart(:type => 'column', :embedded => 1)
|
321
|
+
|
322
|
+
# Configure the data series and add the data labels.
|
323
|
+
chart3.add_series(
|
324
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
325
|
+
:values => '=Sheet1!$B$2:$B$7',
|
326
|
+
:data_labels => { :value => 1,
|
327
|
+
:font => {:bold => 1,
|
328
|
+
:color => 'red',
|
329
|
+
:rotation => -30}
|
330
|
+
}
|
331
|
+
)
|
332
|
+
|
333
|
+
# Add a chart title.
|
334
|
+
chart3.set_title(:name => 'Data labels with user defined font')
|
335
|
+
|
336
|
+
# Turn off the chart legend.
|
337
|
+
chart3.set_legend(:none => 1)
|
338
|
+
|
339
|
+
# Insert the chart into the worksheet (with an offset).
|
340
|
+
worksheet.insert_chart('D34', chart3, { :x_offset => 25, :y_offset => 10 })
|
341
|
+
|
342
|
+
|
343
|
+
#######################################################################
|
344
|
+
#
|
345
|
+
# Example with custom string data labels.
|
346
|
+
#
|
347
|
+
|
348
|
+
# Create a Column chart.
|
349
|
+
chart4 = workbook.add_chart(:type => 'column', :embedded => 1)
|
350
|
+
|
351
|
+
# Configure the data series and add the data labels.
|
352
|
+
chart4.add_series(
|
353
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
354
|
+
:values => '=Sheet1!$B$2:$B$7',
|
355
|
+
:data_labels => {
|
356
|
+
:value => 1,
|
357
|
+
:border => {:color => 'red'},
|
358
|
+
:fill => {:color => 'yellow'}
|
359
|
+
}
|
360
|
+
)
|
361
|
+
|
362
|
+
# Add a chart title.
|
363
|
+
chart4.set_title(:name => 'Data labels with formatting')
|
364
|
+
|
365
|
+
# Turn off the chart legend.
|
366
|
+
chart4.set_legend(:none => 1)
|
367
|
+
|
368
|
+
# Insert the chart into the worksheet (with an offset).
|
369
|
+
worksheet.insert_chart('D50', chart4, { :x_offset => 25, :y_offset => 10 })
|
370
|
+
|
371
|
+
|
372
|
+
#######################################################################
|
373
|
+
#
|
374
|
+
# Example with custom string data labels.
|
375
|
+
#
|
376
|
+
|
377
|
+
# Create a Column chart.
|
378
|
+
chart5 = workbook.add_chart( :type => 'column', :embedded => 1 )
|
379
|
+
|
380
|
+
# Some custom labels.
|
381
|
+
custom_labels = [
|
382
|
+
{ :value => 'Amy' },
|
383
|
+
{ :value => 'Bea' },
|
384
|
+
{ :value => 'Eva' },
|
385
|
+
{ :value => 'Fay' },
|
386
|
+
{ :value => 'Liv' },
|
387
|
+
{ :value => 'Una' }
|
388
|
+
]
|
389
|
+
|
390
|
+
# Configure the data series and add the data labels.
|
391
|
+
chart5.add_series(
|
392
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
393
|
+
:values => '=Sheet1!$B$2:$B$7',
|
394
|
+
:data_labels => { :value => 1, :custom => custom_labels }
|
395
|
+
)
|
396
|
+
|
397
|
+
# Add a chart title.
|
398
|
+
chart5.set_title(:name => 'Chart with custom string data labels')
|
399
|
+
|
400
|
+
# Turn off the chart legend.
|
401
|
+
chart5.set_legend(:none => 1)
|
402
|
+
|
403
|
+
# Insert the chart into the worksheet (with an offset).
|
404
|
+
worksheet.insert_chart('D66', chart5, { :x_offset => 25, :y_offset => 10 })
|
405
|
+
|
406
|
+
|
407
|
+
#######################################################################
|
408
|
+
#
|
409
|
+
# Example with custom data labels from cells.
|
410
|
+
#
|
411
|
+
|
412
|
+
# Create a Column chart.
|
413
|
+
chart6 = workbook.add_chart(:type => 'column', :embedded => 1)
|
414
|
+
|
415
|
+
# Some custom labels.
|
416
|
+
custom_labels = [
|
417
|
+
{ :value => '=Sheet1!$C$2' },
|
418
|
+
{ :value => '=Sheet1!$C$3' },
|
419
|
+
{ :value => '=Sheet1!$C$4' },
|
420
|
+
{ :value => '=Sheet1!$C$5' },
|
421
|
+
{ :value => '=Sheet1!$C$6' },
|
422
|
+
{ :value => '=Sheet1!$C$7' }
|
423
|
+
]
|
424
|
+
|
425
|
+
|
426
|
+
# Configure the data series and add the data labels.
|
427
|
+
chart6.add_series(
|
428
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
429
|
+
:values => '=Sheet1!$B$2:$B$7',
|
430
|
+
:data_labels => { :value => 1, :custom => custom_labels }
|
431
|
+
)
|
432
|
+
|
433
|
+
# Add a chart title.
|
434
|
+
chart6.set_title(:name => 'Chart with custom data labels from cells')
|
435
|
+
|
436
|
+
# Turn off the chart legend.
|
437
|
+
chart6.set_legend(:none => 1)
|
438
|
+
|
439
|
+
# Insert the chart into the worksheet (with an offset).
|
440
|
+
worksheet.insert_chart('D82', chart6, { :x_offset => 25, :y_offset => 10 })
|
441
|
+
|
442
|
+
|
443
|
+
#######################################################################
|
444
|
+
#
|
445
|
+
# Example with custom and default data labels.
|
446
|
+
#
|
447
|
+
|
448
|
+
# Create a Column chart.
|
449
|
+
chart7 = workbook.add_chart(:type => 'column', :embedded => 1)
|
450
|
+
|
451
|
+
# Some custom labels. The nil items will get the default value.
|
452
|
+
# We also set a font for the custom items as an extra example.
|
453
|
+
custom_labels = [
|
454
|
+
{ :value => '=Sheet1!$C$2', :font => { :color => 'red' } },
|
455
|
+
nil,
|
456
|
+
{ :value => '=Sheet1!$C$4', :font => { :color => 'red' } },
|
457
|
+
{ :value => '=Sheet1!$C$5', :font => { :color => 'red' } }
|
458
|
+
]
|
459
|
+
|
460
|
+
|
461
|
+
# Configure the data series and add the data labels.
|
462
|
+
chart7.add_series(
|
463
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
464
|
+
:values => '=Sheet1!$B$2:$B$7',
|
465
|
+
:data_labels => { :value => 1, :custom => custom_labels }
|
466
|
+
)
|
467
|
+
|
468
|
+
# Add a chart title.
|
469
|
+
chart7.set_title(:name => 'Mixed custom and default data labels')
|
470
|
+
|
471
|
+
# Turn off the chart legend.
|
472
|
+
chart7.set_legend(:none => 1)
|
473
|
+
|
474
|
+
# Insert the chart into the worksheet (with an offset).
|
475
|
+
worksheet.insert_chart('D98', chart7, { :x_offset => 25, :y_offset => 10 })
|
476
|
+
|
477
|
+
|
478
|
+
#######################################################################
|
479
|
+
#
|
480
|
+
# Example with deleted custom data labels.
|
481
|
+
#
|
482
|
+
|
483
|
+
# Create a Column chart.
|
484
|
+
chart8 = workbook.add_chart(:type => 'column', :embedded => 1)
|
485
|
+
|
486
|
+
# Some deleted custom labels and defaults (nil). This allows us to
|
487
|
+
# highlight certain values such as the minimum and maximum.
|
488
|
+
custom_labels = [
|
489
|
+
{ :delete => 1 },
|
490
|
+
nil,
|
491
|
+
{ :delete => 1 },
|
492
|
+
{ :delete => 1 },
|
493
|
+
nil,
|
494
|
+
{ :delete => 1 }
|
495
|
+
]
|
496
|
+
|
497
|
+
# Configure the data series and add the data labels.
|
498
|
+
chart8.add_series(
|
499
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
500
|
+
:values => '=Sheet1!$B$2:$B$7',
|
501
|
+
:data_labels => { :value => 1, :custom => custom_labels }
|
502
|
+
)
|
503
|
+
|
504
|
+
# Add a chart title.
|
505
|
+
chart8.set_title(:name => 'Chart with deleted data labels')
|
506
|
+
|
507
|
+
# Turn off the chart legend.
|
508
|
+
chart8.set_legend(:none => 1)
|
509
|
+
|
510
|
+
# Insert the chart into the worksheet (with an offset).
|
511
|
+
worksheet.insert_chart('D114', chart8, { :x_offset => 25, :y_offset => 10 })
|
512
|
+
|
513
|
+
#######################################################################
|
514
|
+
#
|
515
|
+
# Example with custom string data labels and formatting.
|
516
|
+
#
|
517
|
+
|
518
|
+
# Create a Column chart.
|
519
|
+
chart9 = workbook.add_chart( :type => 'column', :embedded => 1 )
|
520
|
+
|
521
|
+
# Some custom labels.
|
522
|
+
custom_labels = [
|
523
|
+
{ :value => 'Amy', :border => {:color => 'blue'} },
|
524
|
+
{ :value => 'Bea' },
|
525
|
+
{ :value => 'Eva' },
|
526
|
+
{ :value => 'Fay' },
|
527
|
+
{ :value => 'Liv' },
|
528
|
+
{ :value => 'Una', :fill => {:color => 'green'} }
|
529
|
+
]
|
530
|
+
|
531
|
+
|
532
|
+
# Configure the data series and add the data labels.
|
533
|
+
chart9.add_series(
|
534
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
535
|
+
:values => '=Sheet1!$B$2:$B$7',
|
536
|
+
:data_labels => {
|
537
|
+
:value => 1,
|
538
|
+
:custom => custom_labels,
|
539
|
+
:border => {:color => 'red'},
|
540
|
+
:fill => {:color => 'yellow'}
|
541
|
+
}
|
542
|
+
)
|
543
|
+
|
544
|
+
# Add a chart title.
|
545
|
+
chart9.set_title( :name => 'Chart with custom labels and formatting' )
|
546
|
+
|
547
|
+
# Turn off the chart legend.
|
548
|
+
chart9.set_legend( :none => 1 )
|
549
|
+
|
550
|
+
# Insert the chart into the worksheet (with an offset).
|
551
|
+
worksheet.insert_chart( 'D130', chart9, { :x_offset => 25, :y_offset => 10 } )
|
552
|
+
|
553
|
+
workbook.close
|
554
|
+
store_to_tempfile
|
555
|
+
compare_xlsx(File.join(@perl_output, @xlsx), @tempfile.path)
|
556
|
+
end
|
557
|
+
|
558
|
+
def test_chart_gauge
|
559
|
+
@xlsx = 'chart_gauge.xlsx'
|
560
|
+
workbook = WriteXLSX.new(@io)
|
561
|
+
worksheet = workbook.add_worksheet
|
562
|
+
|
563
|
+
chart_doughnut = workbook.add_chart(:type => 'doughnut', :embedded => 1)
|
564
|
+
chart_pie = workbook.add_chart(:type => 'pie', :embedded => 1)
|
565
|
+
|
566
|
+
# Add some data for the Doughnut and Pie charts. This is set up so the
|
567
|
+
# gauge goes from 0-100. It is initially set at 75%.
|
568
|
+
worksheet.write_col('H2', ['Donut', 25, 50, 25, 100])
|
569
|
+
worksheet.write_col('I2', ['Pie', 75, 1, '=200-I4-I3'])
|
570
|
+
|
571
|
+
# Configure the doughnut chart as the background for the gauge.
|
572
|
+
chart_doughnut.add_series(
|
573
|
+
:name => '=Sheet1!$H$2',
|
574
|
+
:values => '=Sheet1!$H$3:$H$6',
|
575
|
+
:points => [
|
576
|
+
{ :fill => { :color => 'green' } },
|
577
|
+
{ :fill => { :color => 'yellow' } },
|
578
|
+
{ :fill => { :color => 'red' } },
|
579
|
+
{ :fill => { :none => 1 } }
|
580
|
+
]
|
581
|
+
)
|
582
|
+
|
583
|
+
# Rotate chart so the gauge parts are above the horizontal.
|
584
|
+
chart_doughnut.set_rotation(270)
|
585
|
+
|
586
|
+
# Turn off the chart legend.
|
587
|
+
chart_doughnut.set_legend(:none => 1)
|
588
|
+
|
589
|
+
# Turn off the chart fill and border.
|
590
|
+
chart_doughnut.set_chartarea(
|
591
|
+
:border => { :none => 1 },
|
592
|
+
:fill => { :none => 1 }
|
593
|
+
)
|
594
|
+
|
595
|
+
# Configure the pie chart as the needle for the gauge.
|
596
|
+
chart_pie.add_series(
|
597
|
+
:name => '=Sheet1!$I$2',
|
598
|
+
:values => '=Sheet1!$I$3:$I$6',
|
599
|
+
:points => [
|
600
|
+
{ :fill => { :none => 1 } },
|
601
|
+
{ :fill => { :color => 'black' } },
|
602
|
+
{ :fill => { :none => 1 } }
|
603
|
+
]
|
604
|
+
)
|
605
|
+
|
606
|
+
# Rotate the pie chart/needle to align with the doughnut/gauge.
|
607
|
+
chart_pie.set_rotation(270)
|
608
|
+
|
609
|
+
# Combine the pie and doughnut charts.
|
610
|
+
chart_doughnut.combine(chart_pie)
|
611
|
+
|
612
|
+
# Insert the chart into the worksheet.
|
613
|
+
worksheet.insert_chart('A1', chart_doughnut)
|
614
|
+
|
615
|
+
workbook.close
|
616
|
+
store_to_tempfile
|
617
|
+
compare_xlsx(File.join(@perl_output, @xlsx), @tempfile.path)
|
618
|
+
end
|
619
|
+
|
245
620
|
def test_chart_scatter06
|
246
621
|
@xlsx = 'chart_scatter06.xlsx'
|
247
622
|
workbook = WriteXLSX.new(@io)
|
@@ -252,23 +627,23 @@ def test_chart_scatter06
|
|
252
627
|
chart.instance_variable_set(:@axis_ids, [57708544, 44297600])
|
253
628
|
|
254
629
|
data = [
|
255
|
-
|
256
|
-
|
257
|
-
|
630
|
+
[ 1, 2, 3, 4, 5 ],
|
631
|
+
[ 2, 4, 6, 8, 10 ],
|
632
|
+
[ 3, 6, 9, 12, 15 ]
|
258
633
|
|
259
|
-
|
634
|
+
]
|
260
635
|
|
261
636
|
worksheet.write('A1', data)
|
262
637
|
|
263
638
|
chart.add_series(
|
264
|
-
|
265
|
-
|
266
|
-
|
639
|
+
:categories => '=Sheet1!$A$1:$A$5',
|
640
|
+
:values => '=Sheet1!$B$1:$B$5'
|
641
|
+
)
|
267
642
|
|
268
643
|
chart.add_series(
|
269
|
-
|
270
|
-
|
271
|
-
|
644
|
+
:categories => '=Sheet1!$A$1:$A$5',
|
645
|
+
:values => '=Sheet1!$C$1:$C$5'
|
646
|
+
)
|
272
647
|
|
273
648
|
chart.set_x_axis(:minor_unit => 1, :major_unit => 3)
|
274
649
|
chart.set_y_axis(:minor_unit => 2, :major_unit => 4)
|
@@ -281,7 +656,7 @@ def test_chart_scatter06
|
|
281
656
|
end
|
282
657
|
|
283
658
|
def autofilter_data
|
284
|
-
<<EOS
|
659
|
+
<<EOS
|
285
660
|
Region Item Volume Month
|
286
661
|
East Apple 9000 July
|
287
662
|
East Apple 5000 July
|
@@ -345,10 +720,10 @@ def test_chart_area
|
|
345
720
|
# Add the worksheet data that the charts will refer to.
|
346
721
|
headings = [ 'Number', 'Batch 1', 'Batch 2' ]
|
347
722
|
data = [
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
723
|
+
[ 2, 3, 4, 5, 6, 7 ],
|
724
|
+
[ 40, 40, 50, 30, 25, 50 ],
|
725
|
+
[ 30, 25, 30, 10, 5, 10 ]
|
726
|
+
]
|
352
727
|
|
353
728
|
worksheet.write('A1', headings, bold)
|
354
729
|
worksheet.write('A2', data)
|
@@ -358,18 +733,18 @@ def test_chart_area
|
|
358
733
|
|
359
734
|
# Configure the first series.
|
360
735
|
chart.add_series(
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
736
|
+
:name => '=Sheet1!$B$1',
|
737
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
738
|
+
:values => '=Sheet1!$B$2:$B$7'
|
739
|
+
)
|
365
740
|
|
366
741
|
# Configure second series. Note alternative use of array ref to define
|
367
742
|
# ranges: [ sheetname, row_start, row_end, col_start, col_end ].
|
368
743
|
chart.add_series(
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
744
|
+
:name => '=Sheet1!$C$1',
|
745
|
+
:categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
746
|
+
:values => [ 'Sheet1', 1, 6, 2, 2 ]
|
747
|
+
)
|
373
748
|
|
374
749
|
# Add a chart title and some axis labels.
|
375
750
|
chart.set_title(:name => 'Results of sample analysis')
|
@@ -396,9 +771,9 @@ def test_chart_bar
|
|
396
771
|
# Add the worksheet data that the charts will refer to.
|
397
772
|
headings = [ 'Number', 'Batch 1', 'Batch 2' ]
|
398
773
|
data = [
|
399
|
-
|
400
|
-
|
401
|
-
|
774
|
+
[ 2, 3, 4, 5, 6, 7 ],
|
775
|
+
[ 10, 40, 50, 20, 10, 50 ],
|
776
|
+
[ 30, 60, 70, 50, 40, 30 ]
|
402
777
|
]
|
403
778
|
|
404
779
|
worksheet.write('A1', headings, bold)
|
@@ -409,17 +784,17 @@ def test_chart_bar
|
|
409
784
|
|
410
785
|
# Configure the first series.
|
411
786
|
chart.add_series(
|
412
|
-
|
413
|
-
|
414
|
-
|
787
|
+
:name => '=Sheet1!$B$1',
|
788
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
789
|
+
:values => '=Sheet1!$B$2:$B$7'
|
415
790
|
)
|
416
791
|
|
417
792
|
# Configure second series. Note alternative use of array ref to define
|
418
793
|
# ranges: [ sheetname, row_start, row_end, col_start, col_end ].
|
419
794
|
chart.add_series(
|
420
|
-
|
421
|
-
|
422
|
-
|
795
|
+
:name => '=Sheet1!$C$1',
|
796
|
+
:categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
797
|
+
:values => [ 'Sheet1', 1, 6, 2, 2 ]
|
423
798
|
)
|
424
799
|
|
425
800
|
# Add a chart title and some axis labels.
|
@@ -447,9 +822,9 @@ def test_chart_column
|
|
447
822
|
# Add the worksheet data that the charts will refer to.
|
448
823
|
headings = [ 'Number', 'Batch 1', 'Batch 2' ]
|
449
824
|
data = [
|
450
|
-
|
451
|
-
|
452
|
-
|
825
|
+
[ 2, 3, 4, 5, 6, 7 ],
|
826
|
+
[ 10, 40, 50, 20, 10, 50 ],
|
827
|
+
[ 30, 60, 70, 50, 40, 30 ]
|
453
828
|
]
|
454
829
|
|
455
830
|
worksheet.write('A1', headings, bold)
|
@@ -460,17 +835,17 @@ def test_chart_column
|
|
460
835
|
|
461
836
|
# Configure the first series.
|
462
837
|
chart.add_series(
|
463
|
-
|
464
|
-
|
465
|
-
|
838
|
+
:name => '=Sheet1!$B$1',
|
839
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
840
|
+
:values => '=Sheet1!$B$2:$B$7'
|
466
841
|
)
|
467
842
|
|
468
843
|
# Configure second series. Note alternative use of array ref to define
|
469
844
|
# ranges: [ sheetname, row_start, row_end, col_start, col_end ].
|
470
845
|
chart.add_series(
|
471
|
-
|
472
|
-
|
473
|
-
|
846
|
+
:name => '=Sheet1!$C$1',
|
847
|
+
:categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
848
|
+
:values => [ 'Sheet1', 1, 6, 2, 2 ]
|
474
849
|
)
|
475
850
|
|
476
851
|
# Add a chart title and some axis labels.
|
@@ -498,9 +873,9 @@ def test_chart_doughnut
|
|
498
873
|
# Add the worksheet data that the charts will refer to.
|
499
874
|
headings = [ 'Category', 'Values' ]
|
500
875
|
data = [
|
501
|
-
|
502
|
-
|
503
|
-
|
876
|
+
[ 'Glazed', 'Chocolate', 'Cream' ],
|
877
|
+
[ 50, 35, 15 ]
|
878
|
+
]
|
504
879
|
|
505
880
|
worksheet.write('A1', headings, bold)
|
506
881
|
worksheet.write('A2', data)
|
@@ -512,10 +887,10 @@ def test_chart_doughnut
|
|
512
887
|
# [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
|
513
888
|
# See below for an alternative syntax.
|
514
889
|
chart1.add_series(
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
890
|
+
:name => 'Doughnut sales data',
|
891
|
+
:categories => [ 'Sheet1', 1, 3, 0, 0 ],
|
892
|
+
:values => [ 'Sheet1', 1, 3, 1, 1 ]
|
893
|
+
)
|
519
894
|
|
520
895
|
# Add a title.
|
521
896
|
chart1.set_title(:name => 'Popular Doughnut Types')
|
@@ -536,15 +911,15 @@ def test_chart_doughnut
|
|
536
911
|
|
537
912
|
# Configure the series and add user defined segment colours.
|
538
913
|
chart2.add_series(
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
914
|
+
:name => 'Doughnut sales data',
|
915
|
+
:categories => '=Sheet1!$A$2:$A$4',
|
916
|
+
:values => '=Sheet1!$B$2:$B$4',
|
917
|
+
:points => [
|
918
|
+
{ :fill => { :color => '#FA58D0' } },
|
919
|
+
{ :fill => { :color => '#61210B' } },
|
920
|
+
{ :fill => { :color => '#F5F6CE' } }
|
921
|
+
]
|
922
|
+
)
|
548
923
|
|
549
924
|
# Add a title.
|
550
925
|
chart2.set_title(:name => 'Doughnut Chart with user defined colors')
|
@@ -563,10 +938,10 @@ def test_chart_doughnut
|
|
563
938
|
|
564
939
|
# Configure the series.
|
565
940
|
chart3.add_series(
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
941
|
+
:name => 'Doughnut sales data',
|
942
|
+
:categories => '=Sheet1!$A$2:$A$4',
|
943
|
+
:values => '=Sheet1!$B$2:$B$4'
|
944
|
+
)
|
570
945
|
|
571
946
|
# Add a title.
|
572
947
|
chart3.set_title(:name => 'Doughnut Chart with segment rotation')
|
@@ -587,10 +962,10 @@ def test_chart_doughnut
|
|
587
962
|
|
588
963
|
# Configure the series.
|
589
964
|
chart4.add_series(
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
965
|
+
:name => 'Doughnut sales data',
|
966
|
+
:categories => '=Sheet1!$A$2:$A$4',
|
967
|
+
:values => '=Sheet1!$B$2:$B$4'
|
968
|
+
)
|
594
969
|
|
595
970
|
# Add a title.
|
596
971
|
chart4.set_title(:name => 'Doughnut Chart with user defined hole size')
|
@@ -615,9 +990,9 @@ def test_chart_line
|
|
615
990
|
# Add the worksheet data that the charts will refer to.
|
616
991
|
headings = [ 'Number', 'Batch 1', 'Batch 2' ]
|
617
992
|
data = [
|
618
|
-
|
619
|
-
|
620
|
-
|
993
|
+
[ 2, 3, 4, 5, 6, 7 ],
|
994
|
+
[ 10, 40, 50, 20, 10, 50 ],
|
995
|
+
[ 30, 60, 70, 50, 40, 30 ]
|
621
996
|
]
|
622
997
|
|
623
998
|
worksheet.write('A1', headings, bold)
|
@@ -628,17 +1003,17 @@ def test_chart_line
|
|
628
1003
|
|
629
1004
|
# Configure the first series.
|
630
1005
|
chart.add_series(
|
631
|
-
|
632
|
-
|
633
|
-
|
1006
|
+
:name => '=Sheet1!$B$1',
|
1007
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1008
|
+
:values => '=Sheet1!$B$2:$B$7'
|
634
1009
|
)
|
635
1010
|
|
636
1011
|
# Configure second series. Note alternative use of array ref to define
|
637
1012
|
# ranges: [ sheetname, row_start, row_end, col_start, col_end ].
|
638
1013
|
chart.add_series(
|
639
|
-
|
640
|
-
|
641
|
-
|
1014
|
+
:name => '=Sheet1!$C$1',
|
1015
|
+
:categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
1016
|
+
:values => [ 'Sheet1', 1, 6, 2, 2 ]
|
642
1017
|
)
|
643
1018
|
|
644
1019
|
# Add a chart title and some axis labels.
|
@@ -652,6 +1027,81 @@ def test_chart_line
|
|
652
1027
|
# Insert the chart into the worksheet (with an offset).
|
653
1028
|
worksheet.insert_chart('D2', chart, 25, 10)
|
654
1029
|
|
1030
|
+
#
|
1031
|
+
# Create a stacked chart sub-type
|
1032
|
+
#
|
1033
|
+
chart2 = workbook.add_chart(
|
1034
|
+
:type => 'line',
|
1035
|
+
:embedded => 1,
|
1036
|
+
:subtype => 'stacked'
|
1037
|
+
)
|
1038
|
+
|
1039
|
+
# Configure the first series.
|
1040
|
+
chart2.add_series(
|
1041
|
+
:name => '=Sheet1!$B$1',
|
1042
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1043
|
+
:values => '=Sheet1!$B$2:$B$7'
|
1044
|
+
)
|
1045
|
+
|
1046
|
+
# Configure second series.
|
1047
|
+
chart2.add_series(
|
1048
|
+
:name => '=Sheet1!$C$1',
|
1049
|
+
:categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
1050
|
+
:values => [ 'Sheet1', 1, 6, 2, 2 ]
|
1051
|
+
)
|
1052
|
+
|
1053
|
+
# Add a chart title and some axis labels.
|
1054
|
+
chart2.set_title( :name => 'Stacked Chart' )
|
1055
|
+
chart2.set_x_axis( :name => 'Test number' )
|
1056
|
+
chart2.set_y_axis( :name => 'Sample length (mm)' )
|
1057
|
+
|
1058
|
+
# Set an Excel chart style. Blue colors with white outline and shadow.
|
1059
|
+
chart2.set_style( 12 )
|
1060
|
+
|
1061
|
+
# Insert the chart into the worksheet (with an offset).
|
1062
|
+
worksheet.insert_chart(
|
1063
|
+
'D18', chart2,
|
1064
|
+
{ :x_offset => 25, :y_offset => 10 }
|
1065
|
+
)
|
1066
|
+
|
1067
|
+
|
1068
|
+
#
|
1069
|
+
# Create a percent stacked chart sub-type
|
1070
|
+
#
|
1071
|
+
chart3 = workbook.add_chart(
|
1072
|
+
:type => 'line',
|
1073
|
+
:embedded => 1,
|
1074
|
+
:subtype => 'percent_stacked'
|
1075
|
+
)
|
1076
|
+
|
1077
|
+
# Configure the first series.
|
1078
|
+
chart3.add_series(
|
1079
|
+
:name => '=Sheet1!$B$1',
|
1080
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1081
|
+
:values => '=Sheet1!$B$2:$B$7'
|
1082
|
+
)
|
1083
|
+
|
1084
|
+
# Configure second series.
|
1085
|
+
chart3.add_series(
|
1086
|
+
:name => '=Sheet1!$C$1',
|
1087
|
+
:categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
1088
|
+
:values => [ 'Sheet1', 1, 6, 2, 2 ]
|
1089
|
+
)
|
1090
|
+
|
1091
|
+
# Add a chart title and some axis labels.
|
1092
|
+
chart3.set_title( :name => 'Percent Stacked Chart' )
|
1093
|
+
chart3.set_x_axis( :name => 'Test number' )
|
1094
|
+
chart3.set_y_axis( :name => 'Sample length (mm)' )
|
1095
|
+
|
1096
|
+
# Set an Excel chart style. Blue colors with white outline and shadow.
|
1097
|
+
chart3.set_style( 13 )
|
1098
|
+
|
1099
|
+
# Insert the chart into the worksheet (with an offset).
|
1100
|
+
worksheet.insert_chart(
|
1101
|
+
'D34', chart3,
|
1102
|
+
{ :x_offset => 25, :y_offset => 10 }
|
1103
|
+
)
|
1104
|
+
|
655
1105
|
workbook.close
|
656
1106
|
store_to_tempfile
|
657
1107
|
compare_xlsx(File.join(@perl_output, @xlsx), @tempfile.path)
|
@@ -666,9 +1116,9 @@ def test_chart_pie
|
|
666
1116
|
# Add the worksheet data that the charts will refer to.
|
667
1117
|
headings = [ 'Category', 'Values' ]
|
668
1118
|
data = [
|
669
|
-
|
670
|
-
|
671
|
-
|
1119
|
+
[ 'Apple', 'Cherry', 'Pecan' ],
|
1120
|
+
[ 60, 30, 10 ]
|
1121
|
+
]
|
672
1122
|
|
673
1123
|
worksheet.write('A1', headings, bold)
|
674
1124
|
worksheet.write('A2', data)
|
@@ -680,10 +1130,10 @@ def test_chart_pie
|
|
680
1130
|
# [ $sheetname, $row_start, $row_end, $col_start, $col_end ].
|
681
1131
|
# See below for an alternative syntax.
|
682
1132
|
chart1.add_series(
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
1133
|
+
:name => 'Pie sales data',
|
1134
|
+
:categories => [ 'Sheet1', 1, 3, 0, 0 ],
|
1135
|
+
:values => [ 'Sheet1', 1, 3, 1, 1 ]
|
1136
|
+
)
|
687
1137
|
|
688
1138
|
# Add a title.
|
689
1139
|
chart1.set_title(:name => 'Popular Pie Types')
|
@@ -703,15 +1153,15 @@ def test_chart_pie
|
|
703
1153
|
|
704
1154
|
# Configure the series and add user defined segment colours.
|
705
1155
|
chart2.add_series(
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
1156
|
+
:name => 'Pie sales data',
|
1157
|
+
:categories => '=Sheet1!$A$2:$A$4',
|
1158
|
+
:values => '=Sheet1!$B$2:$B$4',
|
1159
|
+
:points => [
|
1160
|
+
{ :fill => { :color => '#5ABA10' } },
|
1161
|
+
{ :fill => { :color => '#FE110E' } },
|
1162
|
+
{ :fill => { :color => '#CA5C05' } }
|
1163
|
+
]
|
1164
|
+
)
|
715
1165
|
|
716
1166
|
# Add a title.
|
717
1167
|
chart2.set_title(:name => 'Pie Chart with user defined colors')
|
@@ -733,10 +1183,10 @@ def test_chart_radar
|
|
733
1183
|
# Add the worksheet data that the charts will refer to.
|
734
1184
|
headings = [ 'Number', 'Batch 1', 'Batch 2' ]
|
735
1185
|
data = [
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
1186
|
+
[ 2, 3, 4, 5, 6, 7 ],
|
1187
|
+
[ 30, 60, 70, 50, 40, 30 ],
|
1188
|
+
[ 25, 40, 50, 30, 50, 40 ]
|
1189
|
+
]
|
740
1190
|
|
741
1191
|
worksheet.write('A1', headings, bold)
|
742
1192
|
worksheet.write('A2', data)
|
@@ -746,18 +1196,18 @@ def test_chart_radar
|
|
746
1196
|
|
747
1197
|
# Configure the first series.
|
748
1198
|
chart1.add_series(
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
1199
|
+
:name => '=Sheet1!$B$1',
|
1200
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1201
|
+
:values => '=Sheet1!$B$2:$B$7'
|
1202
|
+
)
|
753
1203
|
|
754
1204
|
# Configure second series. Note alternative use of array ref to define
|
755
1205
|
# ranges: [ sheetname, row_start, row_end, col_start, col_end ].
|
756
1206
|
chart1.add_series(
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
1207
|
+
:name => '=Sheet1!$C$1',
|
1208
|
+
:categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
1209
|
+
:values => [ 'Sheet1', 1, 6, 2, 2 ]
|
1210
|
+
)
|
761
1211
|
|
762
1212
|
# Add a chart title and some axis labels.
|
763
1213
|
chart1.set_title(:name => 'Results of sample analysis')
|
@@ -774,24 +1224,24 @@ def test_chart_radar
|
|
774
1224
|
# Create a with_markers chart sub-type
|
775
1225
|
#
|
776
1226
|
chart2 = workbook.add_chart(
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
1227
|
+
:type => 'radar',
|
1228
|
+
:embedded => 1,
|
1229
|
+
:subtype => 'with_markers'
|
1230
|
+
)
|
781
1231
|
|
782
1232
|
# Configure the first series.
|
783
1233
|
chart2.add_series(
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
1234
|
+
:name => '=Sheet1!$B$1',
|
1235
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1236
|
+
:values => '=Sheet1!$B$2:$B$7'
|
1237
|
+
)
|
788
1238
|
|
789
1239
|
# Configure second series.
|
790
1240
|
chart2.add_series(
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
1241
|
+
:name => '=Sheet1!$C$1',
|
1242
|
+
:categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
1243
|
+
:values => [ 'Sheet1', 1, 6, 2, 2 ]
|
1244
|
+
)
|
795
1245
|
|
796
1246
|
# Add a chart title and some axis labels.
|
797
1247
|
chart2.set_title(:name => 'Stacked Chart')
|
@@ -808,24 +1258,24 @@ def test_chart_radar
|
|
808
1258
|
# Create a filled chart sub-type
|
809
1259
|
#
|
810
1260
|
chart3 = workbook.add_chart(
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
1261
|
+
:type => 'radar',
|
1262
|
+
:embedded => 1,
|
1263
|
+
:subtype => 'filled'
|
1264
|
+
)
|
815
1265
|
|
816
1266
|
# Configure the first series.
|
817
1267
|
chart3.add_series(
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
1268
|
+
:name => '=Sheet1!$B$1',
|
1269
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1270
|
+
:values => '=Sheet1!$B$2:$B$7'
|
1271
|
+
)
|
822
1272
|
|
823
1273
|
# Configure second series.
|
824
1274
|
chart3.add_series(
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
1275
|
+
:name => '=Sheet1!$C$1',
|
1276
|
+
:categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
1277
|
+
:values => [ 'Sheet1', 1, 6, 2, 2 ]
|
1278
|
+
)
|
829
1279
|
|
830
1280
|
# Add a chart title and some axis labels.
|
831
1281
|
chart3.set_title(:name => 'Percent Stacked Chart')
|
@@ -852,9 +1302,9 @@ def test_chart_scatter
|
|
852
1302
|
# Add the worksheet data that the charts will refer to.
|
853
1303
|
headings = [ 'Number', 'Batch 1', 'Batch 2' ]
|
854
1304
|
data = [
|
855
|
-
|
856
|
-
|
857
|
-
|
1305
|
+
[ 2, 3, 4, 5, 6, 7 ],
|
1306
|
+
[ 10, 40, 50, 20, 10, 50 ],
|
1307
|
+
[ 30, 60, 70, 50, 40, 30 ]
|
858
1308
|
]
|
859
1309
|
|
860
1310
|
worksheet.write('A1', headings, bold)
|
@@ -865,17 +1315,17 @@ def test_chart_scatter
|
|
865
1315
|
|
866
1316
|
# Configure the first series.
|
867
1317
|
chart.add_series(
|
868
|
-
|
869
|
-
|
870
|
-
|
1318
|
+
:name => '=Sheet1!$B$1',
|
1319
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1320
|
+
:values => '=Sheet1!$B$2:$B$7'
|
871
1321
|
)
|
872
1322
|
|
873
1323
|
# Configure second series. Note alternative use of array ref to define
|
874
1324
|
# ranges: [ $sheetname, $row_start, $row_end, $col_start, $col_end ].$chart->add_series(
|
875
1325
|
chart.add_series(
|
876
|
-
|
877
|
-
|
878
|
-
|
1326
|
+
:name => '=Sheet1!$C$1',
|
1327
|
+
:categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
1328
|
+
:values => [ 'Sheet1', 1, 6, 2, 2 ]
|
879
1329
|
)
|
880
1330
|
|
881
1331
|
# Add a chart title and some axis labels.
|
@@ -906,19 +1356,19 @@ def test_chart_stock
|
|
906
1356
|
# Add the worksheet data that the charts will refer to.
|
907
1357
|
headings = [ 'Date', 'High', 'Low', 'Close' ]
|
908
1358
|
data = [
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
1359
|
+
[ '2007-01-01T', '2007-01-02T', '2007-01-03T', '2007-01-04T', '2007-01-05T' ],
|
1360
|
+
[ 27.2, 25.03, 19.05, 20.34, 18.5 ],
|
1361
|
+
[ 23.49, 19.55, 15.12, 17.84, 16.34 ],
|
1362
|
+
[ 25.45, 23.05, 17.32, 20.45, 17.34 ]
|
913
1363
|
]
|
914
1364
|
|
915
1365
|
worksheet.write('A1', headings, bold)
|
916
1366
|
|
917
1367
|
(0 .. 4).each do |row|
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
1368
|
+
worksheet.write_date_time(row + 1, 0, data[0][row], date_format)
|
1369
|
+
worksheet.write(row + 1, 1, data[1][row])
|
1370
|
+
worksheet.write(row + 1, 2, data[2][row])
|
1371
|
+
worksheet.write(row + 1, 3, data[3][row])
|
922
1372
|
end
|
923
1373
|
|
924
1374
|
worksheet.set_column('A:D', 11)
|
@@ -960,9 +1410,9 @@ def test_chart_secondary_axis
|
|
960
1410
|
# Add the worksheet data that the charts will refer to.
|
961
1411
|
headings = [ 'Aliens', 'Humans']
|
962
1412
|
data = [
|
963
|
-
|
964
|
-
|
965
|
-
|
1413
|
+
[ 2, 3, 4, 5, 6, 7 ],
|
1414
|
+
[ 10, 40, 50, 20, 10, 50 ]
|
1415
|
+
]
|
966
1416
|
|
967
1417
|
worksheet.write('A1', headings, bold)
|
968
1418
|
worksheet.write('A2', data)
|
@@ -972,15 +1422,15 @@ def test_chart_secondary_axis
|
|
972
1422
|
|
973
1423
|
# Configure the first series.
|
974
1424
|
chart.add_series(
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
1425
|
+
:name => '=Sheet1!$A$1',
|
1426
|
+
:values => '=Sheet1!$A$2:$A$7',
|
1427
|
+
:y2_axis => 1
|
1428
|
+
)
|
979
1429
|
|
980
1430
|
chart.add_series(
|
981
|
-
|
982
|
-
|
983
|
-
|
1431
|
+
:name => '=Sheet1!$B$1',
|
1432
|
+
:values => '=Sheet1!$B$2:$B$7'
|
1433
|
+
)
|
984
1434
|
|
985
1435
|
chart.set_legend(:position => 'right')
|
986
1436
|
|
@@ -1258,7 +1708,7 @@ def test_comments2
|
|
1258
1708
|
comment = 'Hello.'
|
1259
1709
|
|
1260
1710
|
worksheet6.write( 'C9', cell_text, text_wrap )
|
1261
|
-
worksheet6.write_comment( 'C9', comment, :color =>
|
1711
|
+
worksheet6.write_comment( 'C9', comment, :color => '#FF6600' )
|
1262
1712
|
|
1263
1713
|
|
1264
1714
|
###############################################################################
|
@@ -1275,7 +1725,7 @@ def test_comments2
|
|
1275
1725
|
cell = 'C3'
|
1276
1726
|
|
1277
1727
|
cell_text = "Move the mouse over this cell and you will see 'Cell commented " +
|
1278
|
-
|
1728
|
+
"by #{author}' (blank) in the status bar at the bottom"
|
1279
1729
|
|
1280
1730
|
comment = 'Hello.'
|
1281
1731
|
|
@@ -1286,7 +1736,7 @@ def test_comments2
|
|
1286
1736
|
author = 'Ruby'
|
1287
1737
|
cell = 'C6'
|
1288
1738
|
cell_text = "Move the mouse over this cell and you will see 'Cell commented " +
|
1289
|
-
|
1739
|
+
"by #{author}' in the status bar at the bottom"
|
1290
1740
|
|
1291
1741
|
comment = 'Hello.'
|
1292
1742
|
|
@@ -1297,7 +1747,7 @@ def test_comments2
|
|
1297
1747
|
author = '€'
|
1298
1748
|
cell = 'C9'
|
1299
1749
|
cell_text = "Move the mouse over this cell and you will see 'Cell commented " +
|
1300
|
-
|
1750
|
+
"by #{author}' in the status bar at the bottom"
|
1301
1751
|
comment = 'Hello.'
|
1302
1752
|
|
1303
1753
|
worksheet7.write( cell, cell_text, text_wrap )
|
@@ -1361,36 +1811,36 @@ def test_conditional_format
|
|
1361
1811
|
|
1362
1812
|
# Light red fill with dark red text.
|
1363
1813
|
format1 = workbook.add_format(
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1814
|
+
:bg_color => '#FFC7CE',
|
1815
|
+
:color => '#9C0006'
|
1816
|
+
)
|
1367
1817
|
|
1368
1818
|
# Green fill with dark green text.
|
1369
1819
|
format2 = workbook.add_format(
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1820
|
+
:bg_color => '#C6EFCE',
|
1821
|
+
:color => '#006100'
|
1822
|
+
)
|
1373
1823
|
|
1374
1824
|
# Some sample data to run the conditional formatting against.
|
1375
1825
|
data = [
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1826
|
+
[ 34, 72, 38, 30, 75, 48, 75, 66, 84, 86 ],
|
1827
|
+
[ 6, 24, 1, 84, 54, 62, 60, 3, 26, 59 ],
|
1828
|
+
[ 28, 79, 97, 13, 85, 93, 93, 22, 5, 14 ],
|
1829
|
+
[ 27, 71, 40, 17, 18, 79, 90, 93, 29, 47 ],
|
1830
|
+
[ 88, 25, 33, 23, 67, 1, 59, 79, 47, 36 ],
|
1831
|
+
[ 24, 100, 20, 88, 29, 33, 38, 54, 54, 88 ],
|
1832
|
+
[ 6, 57, 88, 28, 10, 26, 37, 7, 41, 48 ],
|
1833
|
+
[ 52, 78, 1, 96, 26, 45, 47, 33, 96, 36 ],
|
1834
|
+
[ 60, 54, 81, 66, 81, 90, 80, 93, 12, 55 ],
|
1835
|
+
[ 70, 5, 46, 14, 71, 19, 66, 36, 41, 21 ]
|
1836
|
+
]
|
1387
1837
|
|
1388
1838
|
###############################################################################
|
1389
1839
|
#
|
1390
1840
|
# Example 1.
|
1391
1841
|
#
|
1392
1842
|
caption = 'Cells with values >= 50 are in light red. ' +
|
1393
|
-
|
1843
|
+
'Values < 50 are in light green.'
|
1394
1844
|
|
1395
1845
|
# Write the data.
|
1396
1846
|
worksheet1.write('A1', caption)
|
@@ -1404,7 +1854,7 @@ def test_conditional_format
|
|
1404
1854
|
:value => 50,
|
1405
1855
|
:format => format1
|
1406
1856
|
}
|
1407
|
-
|
1857
|
+
)
|
1408
1858
|
|
1409
1859
|
# Write another conditional format over the same range.
|
1410
1860
|
worksheet1.conditional_formatting('B3:K12',
|
@@ -1414,7 +1864,7 @@ def test_conditional_format
|
|
1414
1864
|
:value => 50,
|
1415
1865
|
:format => format2
|
1416
1866
|
}
|
1417
|
-
|
1867
|
+
)
|
1418
1868
|
|
1419
1869
|
|
1420
1870
|
###############################################################################
|
@@ -1422,7 +1872,7 @@ def test_conditional_format
|
|
1422
1872
|
# Example 2.
|
1423
1873
|
#
|
1424
1874
|
caption = 'Values between 30 and 70 are in light red. ' +
|
1425
|
-
|
1875
|
+
'Values outside that range are in light green.'
|
1426
1876
|
|
1427
1877
|
worksheet2.write('A1', caption)
|
1428
1878
|
worksheet2.write_col('B3', data)
|
@@ -1435,7 +1885,7 @@ def test_conditional_format
|
|
1435
1885
|
:maximum => 70,
|
1436
1886
|
:format => format1
|
1437
1887
|
}
|
1438
|
-
|
1888
|
+
)
|
1439
1889
|
|
1440
1890
|
worksheet2.conditional_formatting('B3:K12',
|
1441
1891
|
{
|
@@ -1445,7 +1895,7 @@ def test_conditional_format
|
|
1445
1895
|
:maximum => 70,
|
1446
1896
|
:format => format2
|
1447
1897
|
}
|
1448
|
-
|
1898
|
+
)
|
1449
1899
|
|
1450
1900
|
|
1451
1901
|
###############################################################################
|
@@ -1453,7 +1903,7 @@ def test_conditional_format
|
|
1453
1903
|
# Example 3.
|
1454
1904
|
#
|
1455
1905
|
caption = 'Duplicate values are in light red. ' +
|
1456
|
-
|
1906
|
+
'Unique values are in light green.'
|
1457
1907
|
|
1458
1908
|
worksheet3.write('A1', caption)
|
1459
1909
|
worksheet3.write_col('B3', data)
|
@@ -1463,14 +1913,14 @@ def test_conditional_format
|
|
1463
1913
|
:type => 'duplicate',
|
1464
1914
|
:format => format1,
|
1465
1915
|
}
|
1466
|
-
|
1916
|
+
)
|
1467
1917
|
|
1468
1918
|
worksheet3.conditional_formatting('B3:K12',
|
1469
1919
|
{
|
1470
1920
|
:type => 'unique',
|
1471
1921
|
:format => format2,
|
1472
1922
|
}
|
1473
|
-
|
1923
|
+
)
|
1474
1924
|
|
1475
1925
|
|
1476
1926
|
###############################################################################
|
@@ -1478,7 +1928,7 @@ def test_conditional_format
|
|
1478
1928
|
# Example 4.
|
1479
1929
|
#
|
1480
1930
|
caption = 'Above average values are in light red. ' +
|
1481
|
-
|
1931
|
+
'Below average values are in light green.'
|
1482
1932
|
|
1483
1933
|
worksheet4.write('A1', caption)
|
1484
1934
|
worksheet4.write_col('B3', data)
|
@@ -1489,7 +1939,7 @@ def test_conditional_format
|
|
1489
1939
|
:criteria => 'above',
|
1490
1940
|
:format => format1
|
1491
1941
|
}
|
1492
|
-
|
1942
|
+
)
|
1493
1943
|
|
1494
1944
|
worksheet4.conditional_formatting('B3:K12',
|
1495
1945
|
{
|
@@ -1497,7 +1947,7 @@ def test_conditional_format
|
|
1497
1947
|
:criteria => 'below',
|
1498
1948
|
:format => format2
|
1499
1949
|
}
|
1500
|
-
|
1950
|
+
)
|
1501
1951
|
|
1502
1952
|
|
1503
1953
|
###############################################################################
|
@@ -1505,7 +1955,7 @@ def test_conditional_format
|
|
1505
1955
|
# Example 5.
|
1506
1956
|
#
|
1507
1957
|
caption = 'Top 10 values are in light red. ' +
|
1508
|
-
|
1958
|
+
'Bottom 10 values are in light green.'
|
1509
1959
|
|
1510
1960
|
worksheet5.write('A1', caption)
|
1511
1961
|
worksheet5.write_col('B3', data)
|
@@ -1516,7 +1966,7 @@ def test_conditional_format
|
|
1516
1966
|
:value => '10',
|
1517
1967
|
:format => format1
|
1518
1968
|
}
|
1519
|
-
|
1969
|
+
)
|
1520
1970
|
|
1521
1971
|
worksheet5.conditional_formatting('B3:K12',
|
1522
1972
|
{
|
@@ -1524,7 +1974,7 @@ def test_conditional_format
|
|
1524
1974
|
:value => '10',
|
1525
1975
|
:format => format2
|
1526
1976
|
}
|
1527
|
-
|
1977
|
+
)
|
1528
1978
|
|
1529
1979
|
|
1530
1980
|
###############################################################################
|
@@ -1532,7 +1982,7 @@ def test_conditional_format
|
|
1532
1982
|
# Example 6.
|
1533
1983
|
#
|
1534
1984
|
caption = 'Cells with values >= 50 are in light red. ' +
|
1535
|
-
|
1985
|
+
'Values < 50 are in light green. Non-contiguous ranges.'
|
1536
1986
|
|
1537
1987
|
# Write the data.
|
1538
1988
|
worksheet6.write('A1', caption)
|
@@ -1546,7 +1996,7 @@ def test_conditional_format
|
|
1546
1996
|
:value => 50,
|
1547
1997
|
:format => format1
|
1548
1998
|
}
|
1549
|
-
|
1999
|
+
)
|
1550
2000
|
|
1551
2001
|
# Write another conditional format over the same range.
|
1552
2002
|
worksheet6.conditional_formatting('B3:K6,B9:K12',
|
@@ -1556,7 +2006,7 @@ def test_conditional_format
|
|
1556
2006
|
:value => 50,
|
1557
2007
|
:format => format2
|
1558
2008
|
}
|
1559
|
-
|
2009
|
+
)
|
1560
2010
|
|
1561
2011
|
|
1562
2012
|
###############################################################################
|
@@ -1583,19 +2033,19 @@ def test_conditional_format
|
|
1583
2033
|
{
|
1584
2034
|
:type => '2_color_scale'
|
1585
2035
|
}
|
1586
|
-
|
2036
|
+
)
|
1587
2037
|
|
1588
2038
|
worksheet7.conditional_formatting('D3:D14',
|
1589
2039
|
{
|
1590
2040
|
:type => '3_color_scale'
|
1591
2041
|
}
|
1592
|
-
|
2042
|
+
)
|
1593
2043
|
|
1594
2044
|
worksheet7.conditional_formatting('F3:F14',
|
1595
2045
|
{
|
1596
2046
|
:type => 'data_bar'
|
1597
2047
|
}
|
1598
|
-
|
2048
|
+
)
|
1599
2049
|
|
1600
2050
|
|
1601
2051
|
###############################################################################
|
@@ -1624,7 +2074,7 @@ def test_conditional_format
|
|
1624
2074
|
:min_color => "#FF0000",
|
1625
2075
|
:max_color => "#00FF00"
|
1626
2076
|
}
|
1627
|
-
|
2077
|
+
)
|
1628
2078
|
|
1629
2079
|
worksheet8.conditional_formatting('D3:D14',
|
1630
2080
|
{
|
@@ -1633,14 +2083,14 @@ def test_conditional_format
|
|
1633
2083
|
:mid_color => "#8DB4E3",
|
1634
2084
|
:max_color => "#538ED5"
|
1635
2085
|
}
|
1636
|
-
|
2086
|
+
)
|
1637
2087
|
|
1638
2088
|
worksheet8.conditional_formatting('F3:F14',
|
1639
2089
|
{
|
1640
2090
|
:type => 'data_bar',
|
1641
2091
|
:bar_color => '#63C384'
|
1642
2092
|
}
|
1643
|
-
|
2093
|
+
)
|
1644
2094
|
|
1645
2095
|
workbook.close
|
1646
2096
|
store_to_tempfile
|
@@ -1654,13 +2104,13 @@ def test_data_validate
|
|
1654
2104
|
|
1655
2105
|
# Add a format for the header cells.
|
1656
2106
|
header_format = workbook.add_format(
|
1657
|
-
|
1658
|
-
|
1659
|
-
|
1660
|
-
|
1661
|
-
|
1662
|
-
|
1663
|
-
|
2107
|
+
:border => 1,
|
2108
|
+
:bg_color => 43,
|
2109
|
+
:bold => 1,
|
2110
|
+
:text_wrap => 1,
|
2111
|
+
:valign => 'vcenter',
|
2112
|
+
:indent => 1
|
2113
|
+
)
|
1664
2114
|
|
1665
2115
|
# Set up layout of the worksheet.
|
1666
2116
|
worksheet.set_column('A:A', 68)
|
@@ -1932,32 +2382,32 @@ def test_date_time
|
|
1932
2382
|
# the format codes change the appearance of the date.
|
1933
2383
|
#
|
1934
2384
|
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
|
-
|
2385
|
+
'dd/mm/yy',
|
2386
|
+
'mm/dd/yy',
|
2387
|
+
'',
|
2388
|
+
'd mm yy',
|
2389
|
+
'dd mm yy',
|
2390
|
+
'',
|
2391
|
+
'dd m yy',
|
2392
|
+
'dd mm yy',
|
2393
|
+
'dd mmm yy',
|
2394
|
+
'dd mmmm yy',
|
2395
|
+
'',
|
2396
|
+
'dd mm y',
|
2397
|
+
'dd mm yyy',
|
2398
|
+
'dd mm yyyy',
|
2399
|
+
'',
|
2400
|
+
'd mmmm yyyy',
|
2401
|
+
'',
|
2402
|
+
'dd/mm/yy',
|
2403
|
+
'dd/mm/yy hh:mm',
|
2404
|
+
'dd/mm/yy hh:mm:ss',
|
2405
|
+
'dd/mm/yy hh:mm:ss.000',
|
2406
|
+
'',
|
2407
|
+
'hh:mm',
|
2408
|
+
'hh:mm:ss',
|
2409
|
+
'hh:mm:ss.000'
|
2410
|
+
]
|
1961
2411
|
|
1962
2412
|
# Write the same date and time using each of the above formats. The empty
|
1963
2413
|
# string formats create a blank line to make the example clearer.
|
@@ -1969,9 +2419,9 @@ def test_date_time
|
|
1969
2419
|
|
1970
2420
|
# Create a format for the date or time.
|
1971
2421
|
format = workbook.add_format(
|
1972
|
-
|
1973
|
-
|
1974
|
-
|
2422
|
+
:num_format => date_format,
|
2423
|
+
:align => 'left'
|
2424
|
+
)
|
1975
2425
|
|
1976
2426
|
# Write the same date using different formats.
|
1977
2427
|
worksheet.write_date_time(row, 0, '2004-08-01T12:30:45.123', format)
|
@@ -2036,17 +2486,17 @@ def test_demo
|
|
2036
2486
|
worksheet.set_row(0, 40)
|
2037
2487
|
|
2038
2488
|
heading = workbook.add_format(
|
2039
|
-
|
2040
|
-
|
2041
|
-
|
2042
|
-
|
2043
|
-
|
2044
|
-
|
2489
|
+
:bold => 1,
|
2490
|
+
:color => 'blue',
|
2491
|
+
:size => 16,
|
2492
|
+
:merge => 1,
|
2493
|
+
:align => 'vcenter'
|
2494
|
+
)
|
2045
2495
|
|
2046
2496
|
hyperlink_format = workbook.add_format(
|
2047
|
-
|
2048
|
-
|
2049
|
-
|
2497
|
+
:color => 'blue',
|
2498
|
+
:underline => 1
|
2499
|
+
)
|
2050
2500
|
|
2051
2501
|
headings = ['Features of WriteXLSX', '']
|
2052
2502
|
worksheet.write_row('A1', headings, heading)
|
@@ -2056,12 +2506,12 @@ def test_demo
|
|
2056
2506
|
# Some text examples
|
2057
2507
|
#
|
2058
2508
|
text_format = workbook.add_format(
|
2059
|
-
|
2060
|
-
|
2061
|
-
|
2062
|
-
|
2063
|
-
|
2064
|
-
|
2509
|
+
:bold => 1,
|
2510
|
+
:italic => 1,
|
2511
|
+
:color => 'red',
|
2512
|
+
:size => 18,
|
2513
|
+
:font => 'Lucida Calligraphy'
|
2514
|
+
)
|
2065
2515
|
|
2066
2516
|
worksheet.write('A2', "Text")
|
2067
2517
|
worksheet.write('B2', "Hello Excel")
|
@@ -2104,7 +2554,10 @@ def test_demo
|
|
2104
2554
|
# Images
|
2105
2555
|
#
|
2106
2556
|
worksheet.write('A10', "Images")
|
2107
|
-
worksheet.insert_image(
|
2557
|
+
worksheet.insert_image(
|
2558
|
+
'B10', File.join(@test_dir, 'republic.png'),
|
2559
|
+
:x_offset => 16, :y_offset => 8
|
2560
|
+
)
|
2108
2561
|
|
2109
2562
|
#######################################################################
|
2110
2563
|
#
|
@@ -2129,10 +2582,10 @@ def test_diag_border
|
|
2129
2582
|
format3 = workbook.add_format(:diag_type => 3)
|
2130
2583
|
|
2131
2584
|
format4 = workbook.add_format(
|
2132
|
-
|
2133
|
-
|
2134
|
-
|
2135
|
-
|
2585
|
+
:diag_type => 3,
|
2586
|
+
:diag_border => 7,
|
2587
|
+
:diag_color => 'red'
|
2588
|
+
)
|
2136
2589
|
|
2137
2590
|
worksheet.write('B3', 'Text', format1)
|
2138
2591
|
worksheet.write('B6', 'Text', format2)
|
@@ -2218,9 +2671,9 @@ def intro(workbook, center, heading, colors)
|
|
2218
2671
|
format2.set_color('blue')
|
2219
2672
|
|
2220
2673
|
format3 = workbook.add_format(
|
2221
|
-
|
2222
|
-
|
2223
|
-
|
2674
|
+
:color => 'blue',
|
2675
|
+
:underline => 1
|
2676
|
+
)
|
2224
2677
|
|
2225
2678
|
worksheet.write(2, 0, 'This workbook demonstrates some of', format)
|
2226
2679
|
worksheet.write(3, 0, 'the formatting options provided by', format)
|
@@ -2233,16 +2686,16 @@ def intro(workbook, center, heading, colors)
|
|
2233
2686
|
'Named colors', format3)
|
2234
2687
|
|
2235
2688
|
worksheet.write(
|
2236
|
-
|
2237
|
-
|
2238
|
-
|
2239
|
-
|
2689
|
+
'A10',
|
2690
|
+
"internal:'Standard colors'!A1",
|
2691
|
+
'Standard colors', format3
|
2692
|
+
)
|
2240
2693
|
|
2241
2694
|
worksheet.write(
|
2242
|
-
|
2243
|
-
|
2244
|
-
|
2245
|
-
|
2695
|
+
'A11',
|
2696
|
+
"internal:'Numeric formats'!A1",
|
2697
|
+
'Numeric formats', format3
|
2698
|
+
)
|
2246
2699
|
|
2247
2700
|
worksheet.write('A12', "internal:Borders!A1", 'Borders', format3)
|
2248
2701
|
worksheet.write('A13', "internal:Patterns!A1", 'Patterns', format3)
|
@@ -2272,10 +2725,10 @@ def named_colors(workbook, center, heading, colors)
|
|
2272
2725
|
[33, 11, 53, 17, 22, 18, 13, 16, 23, 9, 12, 15, 14, 20, 8, 10].each do |index|
|
2273
2726
|
color = colors[index]
|
2274
2727
|
format = workbook.add_format(
|
2275
|
-
|
2276
|
-
|
2277
|
-
|
2278
|
-
|
2728
|
+
:bg_color => color,
|
2729
|
+
:pattern => 1,
|
2730
|
+
:border => 1
|
2731
|
+
)
|
2279
2732
|
|
2280
2733
|
worksheet.write(i + 1, 0, index, center)
|
2281
2734
|
worksheet.write(i + 1, 1, sprintf("0x%02X", index), center)
|
@@ -2302,10 +2755,10 @@ def standard_colors(workbook, center, heading, colors)
|
|
2302
2755
|
|
2303
2756
|
(8 .. 63).each do |i|
|
2304
2757
|
format = workbook.add_format(
|
2305
|
-
|
2306
|
-
|
2307
|
-
|
2308
|
-
|
2758
|
+
:bg_color => i,
|
2759
|
+
:pattern => 1,
|
2760
|
+
:border => 1
|
2761
|
+
)
|
2309
2762
|
|
2310
2763
|
worksheet.write((i - 7), 0, i, center)
|
2311
2764
|
worksheet.write((i - 7), 1, sprintf("0x%02X", i), center)
|
@@ -2787,17 +3240,17 @@ def test_hyperlink
|
|
2787
3240
|
|
2788
3241
|
# Add the standard url link format.
|
2789
3242
|
url_format = workbook.add_format(
|
2790
|
-
|
2791
|
-
|
2792
|
-
|
3243
|
+
:color => 'blue',
|
3244
|
+
:underline => 1
|
3245
|
+
)
|
2793
3246
|
|
2794
3247
|
# Add a sample format.
|
2795
3248
|
red_format = workbook.add_format(
|
2796
|
-
|
2797
|
-
|
2798
|
-
|
2799
|
-
|
2800
|
-
|
3249
|
+
:color => 'red',
|
3250
|
+
:bold => 1,
|
3251
|
+
:underline => 1,
|
3252
|
+
:size => 12
|
3253
|
+
)
|
2801
3254
|
|
2802
3255
|
# Add an alternate description string to the URL.
|
2803
3256
|
str = 'Perl home.'
|
@@ -2873,16 +3326,16 @@ def test_merge2
|
|
2873
3326
|
|
2874
3327
|
# Create a merged format
|
2875
3328
|
format = workbook.add_format(
|
2876
|
-
|
2877
|
-
|
2878
|
-
|
2879
|
-
|
2880
|
-
|
2881
|
-
|
2882
|
-
|
2883
|
-
|
2884
|
-
|
2885
|
-
|
3329
|
+
:center_across => 1,
|
3330
|
+
:bold => 1,
|
3331
|
+
:size => 15,
|
3332
|
+
:pattern => 1,
|
3333
|
+
:border => 6,
|
3334
|
+
:color => 'white',
|
3335
|
+
:fg_color => 'green',
|
3336
|
+
:border_color => 'yellow',
|
3337
|
+
:align => 'vcenter'
|
3338
|
+
)
|
2886
3339
|
|
2887
3340
|
# Only one cell should contain text, the others should be blank.
|
2888
3341
|
worksheet.write(2, 1, "Center across selection", format)
|
@@ -2909,12 +3362,12 @@ def test_merge3
|
|
2909
3362
|
# Example: Merge cells containing a hyperlink using merge_range().
|
2910
3363
|
#
|
2911
3364
|
format = workbook.add_format(
|
2912
|
-
|
2913
|
-
|
2914
|
-
|
2915
|
-
|
2916
|
-
|
2917
|
-
|
3365
|
+
:border => 1,
|
3366
|
+
:underline => 1,
|
3367
|
+
:color => 'blue',
|
3368
|
+
:align => 'center',
|
3369
|
+
:valign => 'vcenter'
|
3370
|
+
)
|
2918
3371
|
|
2919
3372
|
# Merge 3 cells
|
2920
3373
|
worksheet.merge_range('B4:D4', 'http://www.perl.com', format)
|
@@ -2942,12 +3395,12 @@ def test_merge4
|
|
2942
3395
|
# Example 1: Text centered vertically and horizontally
|
2943
3396
|
#
|
2944
3397
|
format1 = workbook.add_format(
|
2945
|
-
|
2946
|
-
|
2947
|
-
|
2948
|
-
|
2949
|
-
|
2950
|
-
|
3398
|
+
:border => 6,
|
3399
|
+
:bold => 1,
|
3400
|
+
:color => 'red',
|
3401
|
+
:valign => 'vcenter',
|
3402
|
+
:align => 'center'
|
3403
|
+
)
|
2951
3404
|
|
2952
3405
|
worksheet.merge_range('B2:D3', 'Vertical and horizontal', format1)
|
2953
3406
|
|
@@ -2956,12 +3409,12 @@ def test_merge4
|
|
2956
3409
|
# Example 2: Text aligned to the top and left
|
2957
3410
|
#
|
2958
3411
|
format2 = workbook.add_format(
|
2959
|
-
|
2960
|
-
|
2961
|
-
|
2962
|
-
|
2963
|
-
|
2964
|
-
|
3412
|
+
:border => 6,
|
3413
|
+
:bold => 1,
|
3414
|
+
:color => 'red',
|
3415
|
+
:valign => 'top',
|
3416
|
+
:align => 'left'
|
3417
|
+
)
|
2965
3418
|
|
2966
3419
|
worksheet.merge_range('B5:D6', 'Aligned to the top and left', format2)
|
2967
3420
|
|
@@ -2970,12 +3423,12 @@ def test_merge4
|
|
2970
3423
|
# Example 3: Text aligned to the bottom and right
|
2971
3424
|
#
|
2972
3425
|
format3 = workbook.add_format(
|
2973
|
-
|
2974
|
-
|
2975
|
-
|
2976
|
-
|
2977
|
-
|
2978
|
-
|
3426
|
+
:border => 6,
|
3427
|
+
:bold => 1,
|
3428
|
+
:color => 'red',
|
3429
|
+
:valign => 'bottom',
|
3430
|
+
:align => 'right'
|
3431
|
+
)
|
2979
3432
|
|
2980
3433
|
worksheet.merge_range('B8:D9', 'Aligned to the bottom and right', format3)
|
2981
3434
|
|
@@ -2984,12 +3437,12 @@ def test_merge4
|
|
2984
3437
|
# Example 4: Text justified (i.e. wrapped) in the cell
|
2985
3438
|
#
|
2986
3439
|
format4 = workbook.add_format(
|
2987
|
-
|
2988
|
-
|
2989
|
-
|
2990
|
-
|
2991
|
-
|
2992
|
-
|
3440
|
+
:border => 6,
|
3441
|
+
:bold => 1,
|
3442
|
+
:color => 'red',
|
3443
|
+
:valign => 'top',
|
3444
|
+
:align => 'justify'
|
3445
|
+
)
|
2993
3446
|
|
2994
3447
|
worksheet.merge_range('B11:D12', 'Justified: ' << 'so on and ' * 18, format4)
|
2995
3448
|
|
@@ -3013,13 +3466,13 @@ def test_merge5
|
|
3013
3466
|
# Rotation 1, letters run from top to bottom
|
3014
3467
|
#
|
3015
3468
|
format1 = workbook.add_format(
|
3016
|
-
|
3017
|
-
|
3018
|
-
|
3019
|
-
|
3020
|
-
|
3021
|
-
|
3022
|
-
|
3469
|
+
:border => 6,
|
3470
|
+
:bold => 1,
|
3471
|
+
:color => 'red',
|
3472
|
+
:valign => 'vcentre',
|
3473
|
+
:align => 'centre',
|
3474
|
+
:rotation => 270
|
3475
|
+
)
|
3023
3476
|
|
3024
3477
|
worksheet.merge_range( 'B4:B9', 'Rotation 270', format1 )
|
3025
3478
|
|
@@ -3028,13 +3481,13 @@ def test_merge5
|
|
3028
3481
|
# Rotation 2, 90ー anticlockwise
|
3029
3482
|
#
|
3030
3483
|
format2 = workbook.add_format(
|
3031
|
-
|
3032
|
-
|
3033
|
-
|
3034
|
-
|
3035
|
-
|
3036
|
-
|
3037
|
-
|
3484
|
+
:border => 6,
|
3485
|
+
:bold => 1,
|
3486
|
+
:color => 'red',
|
3487
|
+
:valign => 'vcentre',
|
3488
|
+
:align => 'centre',
|
3489
|
+
:rotation => 90
|
3490
|
+
)
|
3038
3491
|
|
3039
3492
|
worksheet.merge_range( 'D4:D9', 'Rotation 90°', format2 )
|
3040
3493
|
|
@@ -3043,13 +3496,13 @@ def test_merge5
|
|
3043
3496
|
# Rotation 3, 90ー clockwise
|
3044
3497
|
#
|
3045
3498
|
format3 = workbook.add_format(
|
3046
|
-
|
3047
|
-
|
3048
|
-
|
3049
|
-
|
3050
|
-
|
3051
|
-
|
3052
|
-
|
3499
|
+
:border => 6,
|
3500
|
+
:bold => 1,
|
3501
|
+
:color => 'red',
|
3502
|
+
:valign => 'vcentre',
|
3503
|
+
:align => 'centre',
|
3504
|
+
:rotation => -90
|
3505
|
+
)
|
3053
3506
|
|
3054
3507
|
worksheet.merge_range( 'F4:F9', 'Rotation -90°', format3 )
|
3055
3508
|
|
@@ -3070,14 +3523,14 @@ def test_merge6
|
|
3070
3523
|
|
3071
3524
|
# Format for the merged cells.
|
3072
3525
|
format = workbook.add_format(
|
3073
|
-
|
3074
|
-
|
3075
|
-
|
3076
|
-
|
3077
|
-
|
3078
|
-
|
3079
|
-
|
3080
|
-
|
3526
|
+
:border => 6,
|
3527
|
+
:bold => 1,
|
3528
|
+
:color => 'red',
|
3529
|
+
:size => 20,
|
3530
|
+
:valign => 'vcentre',
|
3531
|
+
:align => 'left',
|
3532
|
+
:indent => 1
|
3533
|
+
)
|
3081
3534
|
|
3082
3535
|
###############################################################################
|
3083
3536
|
#
|
@@ -3234,12 +3687,12 @@ def test_outline
|
|
3234
3687
|
# Example 3: Create a worksheet with outlined columns.
|
3235
3688
|
#
|
3236
3689
|
data = [
|
3237
|
-
|
3238
|
-
|
3239
|
-
|
3240
|
-
|
3241
|
-
|
3242
|
-
|
3690
|
+
[ 'Month', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', ' Total' ],
|
3691
|
+
[ 'North', 50, 20, 15, 25, 65, 80, '=SUM(B2:G2)' ],
|
3692
|
+
[ 'South', 10, 20, 30, 50, 50, 50, '=SUM(B3:G3)' ],
|
3693
|
+
[ 'East', 45, 75, 50, 15, 75, 100, '=SUM(B4:G4)' ],
|
3694
|
+
[ 'West', 15, 15, 55, 35, 20, 50, '=SUM(B5:G5)' ],
|
3695
|
+
]
|
3243
3696
|
|
3244
3697
|
# Add bold format to the first row
|
3245
3698
|
worksheet3.set_row(0, nil, bold)
|
@@ -3259,10 +3712,10 @@ def test_outline
|
|
3259
3712
|
# Example 4: Show all possible outline levels.
|
3260
3713
|
#
|
3261
3714
|
levels = [
|
3262
|
-
|
3263
|
-
|
3264
|
-
|
3265
|
-
|
3715
|
+
"Level 1", "Level 2", "Level 3", "Level 4", "Level 5", "Level 6",
|
3716
|
+
"Level 7", "Level 6", "Level 5", "Level 4", "Level 3", "Level 2",
|
3717
|
+
"Level 1"
|
3718
|
+
]
|
3266
3719
|
|
3267
3720
|
|
3268
3721
|
worksheet4.write_col('A1', levels)
|
@@ -3393,12 +3846,12 @@ def test_outline_collapsed
|
|
3393
3846
|
# Example 5: Create a worksheet with outlined columns.
|
3394
3847
|
#
|
3395
3848
|
data = [
|
3396
|
-
|
3397
|
-
|
3398
|
-
|
3399
|
-
|
3400
|
-
|
3401
|
-
|
3849
|
+
[ 'Month', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Total' ],
|
3850
|
+
[ 'North', 50, 20, 15, 25, 65, 80, '=SUM(B2:G2)' ],
|
3851
|
+
[ 'South', 10, 20, 30, 50, 50, 50, '=SUM(B3:G3)' ],
|
3852
|
+
[ 'East', 45, 75, 50, 15, 75, 100, '=SUM(B4:G4)' ],
|
3853
|
+
[ 'West', 15, 15, 55, 35, 20, 50, '=SUM(B5:G6)' ]
|
3854
|
+
]
|
3402
3855
|
|
3403
3856
|
# Add bold format to the first row
|
3404
3857
|
worksheet5.set_row(0, nil, bold)
|
@@ -3499,10 +3952,10 @@ def test_panes
|
|
3499
3952
|
#
|
3500
3953
|
|
3501
3954
|
header = workbook.add_format(
|
3502
|
-
|
3503
|
-
|
3504
|
-
|
3505
|
-
|
3955
|
+
:align => 'center',
|
3956
|
+
:valign => 'vcenter',
|
3957
|
+
:fg_color => 0x2A
|
3958
|
+
)
|
3506
3959
|
|
3507
3960
|
center = workbook.add_format(:align => 'center')
|
3508
3961
|
|
@@ -3598,16 +4051,16 @@ def test_properties
|
|
3598
4051
|
worksheet = workbook.add_worksheet
|
3599
4052
|
|
3600
4053
|
workbook.set_properties(
|
3601
|
-
|
3602
|
-
|
3603
|
-
|
3604
|
-
|
3605
|
-
|
3606
|
-
|
3607
|
-
|
3608
|
-
|
3609
|
-
|
3610
|
-
|
4054
|
+
:title => 'This is an example spreadsheet',
|
4055
|
+
:subject => 'With document properties',
|
4056
|
+
:author => 'John McNamara',
|
4057
|
+
:manager => 'Dr. Heinz Doofenshmirtz',
|
4058
|
+
:company => 'of Wolves',
|
4059
|
+
:category => 'Example spreadsheets',
|
4060
|
+
:keywords => 'Sample, Example, Properties',
|
4061
|
+
:comments => 'Created with Perl and Excel::Writer::XLSX',
|
4062
|
+
:status => 'Quo'
|
4063
|
+
)
|
3611
4064
|
|
3612
4065
|
worksheet.set_column('A:A', 70)
|
3613
4066
|
worksheet.write('A1', "Select 'Office Button -> Prepare -> Properties' to see the file properties.")
|
@@ -3708,16 +4161,16 @@ def test_rich_strings
|
|
3708
4161
|
|
3709
4162
|
# Write some strings with multiple formats.
|
3710
4163
|
worksheet.write_rich_string('A1',
|
3711
|
-
|
4164
|
+
'This is ', bold, 'bold', ' and this is ', italic, 'italic')
|
3712
4165
|
|
3713
4166
|
worksheet.write_rich_string('A3',
|
3714
|
-
|
4167
|
+
'This is ', red, 'red', ' and this is ', blue, 'blue')
|
3715
4168
|
|
3716
4169
|
worksheet.write_rich_string('A5',
|
3717
|
-
|
4170
|
+
'Some ', bold, 'bold text', ' centered', center)
|
3718
4171
|
|
3719
4172
|
worksheet.write_rich_string('A7',
|
3720
|
-
|
4173
|
+
italic, 'j = k', superc, '(n-1)', center)
|
3721
4174
|
|
3722
4175
|
workbook.close
|
3723
4176
|
store_to_tempfile
|
@@ -3750,7 +4203,7 @@ def test_shape1
|
|
3750
4203
|
:text => "Hello\nWorld",
|
3751
4204
|
:width => 60,
|
3752
4205
|
:height => 60
|
3753
|
-
|
4206
|
+
)
|
3754
4207
|
|
3755
4208
|
worksheet.insert_shape('A1', ellipse, 50, 50)
|
3756
4209
|
|
@@ -3775,12 +4228,12 @@ def test_shape2
|
|
3775
4228
|
:text => "Plain",
|
3776
4229
|
:width => 100,
|
3777
4230
|
:height => 100
|
3778
|
-
|
4231
|
+
)
|
3779
4232
|
|
3780
4233
|
bbformat = workbook.add_format(
|
3781
4234
|
:color => 'red',
|
3782
4235
|
:font => 'Lucida Calligraphy'
|
3783
|
-
|
4236
|
+
)
|
3784
4237
|
|
3785
4238
|
bbformat.set_bold
|
3786
4239
|
bbformat.set_underline
|
@@ -3797,7 +4250,7 @@ def test_shape2
|
|
3797
4250
|
:line_weight => 3,
|
3798
4251
|
:fill => 'FFFF00',
|
3799
4252
|
:line => '3366FF'
|
3800
|
-
|
4253
|
+
)
|
3801
4254
|
|
3802
4255
|
worksheet.insert_shape('A1', plain, 50, 50)
|
3803
4256
|
worksheet.insert_shape('A1', decor, 250, 50)
|
@@ -3818,7 +4271,7 @@ def test_shape3
|
|
3818
4271
|
:text => 'Normal',
|
3819
4272
|
:width => 100,
|
3820
4273
|
:height => 100
|
3821
|
-
|
4274
|
+
)
|
3822
4275
|
|
3823
4276
|
worksheet.insert_shape('A1', normal, 50, 50)
|
3824
4277
|
normal.text = 'Scaled 3w x 2h'
|
@@ -3841,7 +4294,7 @@ def test_shape4
|
|
3841
4294
|
:type => type,
|
3842
4295
|
:width => 90,
|
3843
4296
|
:height => 90
|
3844
|
-
|
4297
|
+
)
|
3845
4298
|
|
3846
4299
|
(1..10).each do |n|
|
3847
4300
|
# Change the last 5 rectangles to stars. Previously
|
@@ -3857,7 +4310,7 @@ def test_shape4
|
|
3857
4310
|
:width => 90,
|
3858
4311
|
:height => 90,
|
3859
4312
|
:text => 'started as a box'
|
3860
|
-
|
4313
|
+
)
|
3861
4314
|
worksheet.insert_shape('A1', stencil, 100, 150)
|
3862
4315
|
|
3863
4316
|
stencil.stencil = 0
|
@@ -3884,14 +4337,14 @@ def test_shape5
|
|
3884
4337
|
:type => 'ellipse',
|
3885
4338
|
:width => 60,
|
3886
4339
|
:height => 60
|
3887
|
-
|
4340
|
+
)
|
3888
4341
|
worksheet.insert_shape('A1', s1, 50, 50)
|
3889
4342
|
|
3890
4343
|
s2 = workbook.add_shape(
|
3891
4344
|
:type => 'plus',
|
3892
4345
|
:width => 20,
|
3893
4346
|
:height => 20
|
3894
|
-
|
4347
|
+
)
|
3895
4348
|
worksheet.insert_shape('A1', s2, 250, 200)
|
3896
4349
|
|
3897
4350
|
# Create a connector to link the two shapes.
|
@@ -3923,14 +4376,14 @@ def test_shape6
|
|
3923
4376
|
:type => 'chevron',
|
3924
4377
|
:width => 60,
|
3925
4378
|
:height => 60
|
3926
|
-
|
4379
|
+
)
|
3927
4380
|
worksheet.insert_shape('A1', s1, 50, 50)
|
3928
4381
|
|
3929
4382
|
s2 = workbook.add_shape(
|
3930
4383
|
:type => 'pentagon',
|
3931
4384
|
:width => 20,
|
3932
4385
|
:height => 20
|
3933
|
-
|
4386
|
+
)
|
3934
4387
|
worksheet.insert_shape('A1', s2, 250, 200)
|
3935
4388
|
|
3936
4389
|
# Create a connector to link the two shapes.
|
@@ -3970,7 +4423,7 @@ def test_shape7
|
|
3970
4423
|
:text => "Hello\nWorld",
|
3971
4424
|
:width => cw,
|
3972
4425
|
:height => ch
|
3973
|
-
|
4426
|
+
)
|
3974
4427
|
worksheet.insert_shape('A1', ellipse, cx, cy)
|
3975
4428
|
|
3976
4429
|
# Add a plus sign at 4 different positions around the circle.
|
@@ -3984,7 +4437,7 @@ def test_shape7
|
|
3984
4437
|
:id => 3,
|
3985
4438
|
:width => pw,
|
3986
4439
|
:height => ph
|
3987
|
-
|
4440
|
+
)
|
3988
4441
|
|
3989
4442
|
p1 = worksheet.insert_shape('A1', plus, 350, 350)
|
3990
4443
|
p2 = worksheet.insert_shape('A1', plus, 150, 350)
|
@@ -4035,7 +4488,7 @@ def test_shape8
|
|
4035
4488
|
:text => "Hello\nWorld",
|
4036
4489
|
:width => cw,
|
4037
4490
|
:height => ch
|
4038
|
-
|
4491
|
+
)
|
4039
4492
|
worksheet.insert_shape('A1', ellipse, cx, cy)
|
4040
4493
|
|
4041
4494
|
# Add a plus sign at 4 different positionos around the circle.
|
@@ -4049,7 +4502,7 @@ def test_shape8
|
|
4049
4502
|
:id => 3,
|
4050
4503
|
:width => pw,
|
4051
4504
|
:height => ph
|
4052
|
-
|
4505
|
+
)
|
4053
4506
|
|
4054
4507
|
p1 = worksheet.insert_shape('A1', plus, 350, 150)
|
4055
4508
|
p2 = worksheet.insert_shape('A1', plus, 350, 350)
|
@@ -4100,11 +4553,11 @@ def test_shape_all
|
|
4100
4553
|
end
|
4101
4554
|
last_sheet = sheet
|
4102
4555
|
shape = workbook.add_shape(
|
4103
|
-
|
4104
|
-
|
4105
|
-
|
4106
|
-
|
4107
|
-
|
4556
|
+
:type => name,
|
4557
|
+
:text => name,
|
4558
|
+
:width => 90,
|
4559
|
+
:height => 90
|
4560
|
+
)
|
4108
4561
|
|
4109
4562
|
# Connectors can not have labels, so write the connector name in the cell
|
4110
4563
|
# to the left.
|
@@ -4530,17 +4983,18 @@ def test_tables
|
|
4530
4983
|
worksheet10 = workbook.add_worksheet
|
4531
4984
|
worksheet11 = workbook.add_worksheet
|
4532
4985
|
worksheet12 = workbook.add_worksheet
|
4986
|
+
worksheet13 = workbook.add_worksheet
|
4533
4987
|
|
4534
4988
|
currency_format = workbook.add_format(:num_format => '$#,##0')
|
4535
4989
|
|
4536
4990
|
|
4537
4991
|
# Some sample data for the table.
|
4538
4992
|
data = [
|
4539
|
-
|
4540
|
-
|
4541
|
-
|
4542
|
-
|
4543
|
-
|
4993
|
+
[ 'Apples', 10000, 5000, 8000, 6000 ],
|
4994
|
+
[ 'Pears', 2000, 3000, 4000, 5000 ],
|
4995
|
+
[ 'Bananas', 6000, 6000, 6500, 6000 ],
|
4996
|
+
[ 'Oranges', 500, 300, 200, 700 ]
|
4997
|
+
]
|
4544
4998
|
|
4545
4999
|
###############################################################################
|
4546
5000
|
#
|
@@ -4561,7 +5015,7 @@ def test_tables
|
|
4561
5015
|
#
|
4562
5016
|
# Example 2.
|
4563
5017
|
#
|
4564
|
-
caption = 'Default table with data.'
|
5018
|
+
caption = 'Default table with data.'
|
4565
5019
|
|
4566
5020
|
# Set the columns widths.
|
4567
5021
|
worksheet2.set_column('B:G', 12)
|
@@ -4630,7 +5084,7 @@ def test_tables
|
|
4630
5084
|
#
|
4631
5085
|
# Example 6.
|
4632
5086
|
#
|
4633
|
-
caption = 'Table with banded columns but without default banded rows.'
|
5087
|
+
caption = 'Table with banded columns but without default banded rows.'
|
4634
5088
|
|
4635
5089
|
# Set the columns widths.
|
4636
5090
|
worksheet6.set_column('B:G', 12)
|
@@ -4648,7 +5102,7 @@ def test_tables
|
|
4648
5102
|
#
|
4649
5103
|
# Example 7.
|
4650
5104
|
#
|
4651
|
-
caption = 'Table with user defined column headers'
|
5105
|
+
caption = 'Table with user defined column headers'
|
4652
5106
|
|
4653
5107
|
# Set the columns widths.
|
4654
5108
|
worksheet7.set_column('B:G', 12)
|
@@ -4658,24 +5112,24 @@ def test_tables
|
|
4658
5112
|
|
4659
5113
|
# Add a table to the worksheet.
|
4660
5114
|
worksheet7.add_table(
|
4661
|
-
|
4662
|
-
|
4663
|
-
|
4664
|
-
|
4665
|
-
|
4666
|
-
|
4667
|
-
|
4668
|
-
|
4669
|
-
|
4670
|
-
|
4671
|
-
|
4672
|
-
|
5115
|
+
'B3:F7',
|
5116
|
+
{
|
5117
|
+
:data => data,
|
5118
|
+
:columns => [
|
5119
|
+
{ :header => 'Product' },
|
5120
|
+
{ :header => 'Quarter 1' },
|
5121
|
+
{ :header => 'Quarter 2' },
|
5122
|
+
{ :header => 'Quarter 3' },
|
5123
|
+
{ :header => 'Quarter 4' }
|
5124
|
+
]
|
5125
|
+
}
|
5126
|
+
)
|
4673
5127
|
|
4674
5128
|
###############################################################################
|
4675
5129
|
#
|
4676
5130
|
# Example 8.
|
4677
5131
|
#
|
4678
|
-
caption = 'Table with user defined column headers'
|
5132
|
+
caption = 'Table with user defined column headers'
|
4679
5133
|
|
4680
5134
|
# Set the columns widths.
|
4681
5135
|
worksheet8.set_column('B:G', 12)
|
@@ -4685,29 +5139,29 @@ def test_tables
|
|
4685
5139
|
|
4686
5140
|
# Add a table to the worksheet.
|
4687
5141
|
worksheet8.add_table(
|
4688
|
-
|
4689
|
-
|
4690
|
-
|
4691
|
-
|
4692
|
-
|
4693
|
-
|
4694
|
-
|
4695
|
-
|
4696
|
-
|
4697
|
-
|
4698
|
-
|
4699
|
-
|
4700
|
-
|
4701
|
-
|
4702
|
-
|
4703
|
-
|
5142
|
+
'B3:G7',
|
5143
|
+
{
|
5144
|
+
:data => data,
|
5145
|
+
:columns => [
|
5146
|
+
{ :header => 'Product' },
|
5147
|
+
{ :header => 'Quarter 1' },
|
5148
|
+
{ :header => 'Quarter 2' },
|
5149
|
+
{ :header => 'Quarter 3' },
|
5150
|
+
{ :header => 'Quarter 4' },
|
5151
|
+
{
|
5152
|
+
:header => 'Year',
|
5153
|
+
:formula => '=SUM(Table8[@[Quarter 1]:[Quarter 4]])'
|
5154
|
+
}
|
5155
|
+
]
|
5156
|
+
}
|
5157
|
+
)
|
4704
5158
|
|
4705
5159
|
|
4706
5160
|
###############################################################################
|
4707
5161
|
#
|
4708
5162
|
# Example 9.
|
4709
5163
|
#
|
4710
|
-
caption = 'Table with totals row (but no caption or totals).'
|
5164
|
+
caption = 'Table with totals row (but no caption or totals).'
|
4711
5165
|
|
4712
5166
|
# Set the columns widths.
|
4713
5167
|
worksheet9.set_column('B:G', 12)
|
@@ -4717,29 +5171,29 @@ def test_tables
|
|
4717
5171
|
|
4718
5172
|
# Add a table to the worksheet.
|
4719
5173
|
worksheet9.add_table(
|
4720
|
-
|
4721
|
-
|
4722
|
-
|
4723
|
-
|
4724
|
-
|
4725
|
-
|
4726
|
-
|
4727
|
-
|
4728
|
-
|
4729
|
-
|
4730
|
-
|
4731
|
-
|
4732
|
-
|
4733
|
-
|
4734
|
-
|
4735
|
-
|
4736
|
-
|
5174
|
+
'B3:G8',
|
5175
|
+
{
|
5176
|
+
:data => data,
|
5177
|
+
:total_row => 1,
|
5178
|
+
:columns => [
|
5179
|
+
{ :header => 'Product' },
|
5180
|
+
{ :header => 'Quarter 1' },
|
5181
|
+
{ :header => 'Quarter 2' },
|
5182
|
+
{ :header => 'Quarter 3' },
|
5183
|
+
{ :header => 'Quarter 4' },
|
5184
|
+
{
|
5185
|
+
:header => 'Year',
|
5186
|
+
:formula => '=SUM(Table8[@[Quarter 1]:[Quarter 4]])'
|
5187
|
+
}
|
5188
|
+
]
|
5189
|
+
}
|
5190
|
+
)
|
4737
5191
|
|
4738
5192
|
###############################################################################
|
4739
5193
|
#
|
4740
5194
|
# Example 10.
|
4741
5195
|
#
|
4742
|
-
caption = 'Table with totals row with user captions and functions.'
|
5196
|
+
caption = 'Table with totals row with user captions and functions.'
|
4743
5197
|
|
4744
5198
|
# Set the columns widths.
|
4745
5199
|
worksheet10.set_column('B:G', 12)
|
@@ -4749,30 +5203,30 @@ def test_tables
|
|
4749
5203
|
|
4750
5204
|
# Add a table to the worksheet.
|
4751
5205
|
worksheet10.add_table(
|
4752
|
-
|
4753
|
-
|
4754
|
-
|
4755
|
-
|
4756
|
-
|
4757
|
-
|
4758
|
-
|
4759
|
-
|
4760
|
-
|
4761
|
-
|
4762
|
-
|
4763
|
-
|
4764
|
-
|
4765
|
-
|
4766
|
-
|
4767
|
-
|
4768
|
-
|
4769
|
-
|
5206
|
+
'B3:G8',
|
5207
|
+
{
|
5208
|
+
:data => data,
|
5209
|
+
:total_row => 1,
|
5210
|
+
:columns => [
|
5211
|
+
{ :header => 'Product', :total_string => 'Totals' },
|
5212
|
+
{ :header => 'Quarter 1', :total_function => 'sum' },
|
5213
|
+
{ :header => 'Quarter 2', :total_function => 'sum' },
|
5214
|
+
{ :header => 'Quarter 3', :total_function => 'sum' },
|
5215
|
+
{ :header => 'Quarter 4', :total_function => 'sum' },
|
5216
|
+
{
|
5217
|
+
:header => 'Year',
|
5218
|
+
:formula => '=SUM(Table8[@[Quarter 1]:[Quarter 4]])',
|
5219
|
+
:total_function => 'sum'
|
5220
|
+
}
|
5221
|
+
]
|
5222
|
+
}
|
5223
|
+
)
|
4770
5224
|
|
4771
5225
|
###############################################################################
|
4772
5226
|
#
|
4773
5227
|
# Example 11.
|
4774
5228
|
#
|
4775
|
-
caption = 'Table with alternative Excel style.'
|
5229
|
+
caption = 'Table with alternative Excel style.'
|
4776
5230
|
|
4777
5231
|
# Set the columns widths.
|
4778
5232
|
worksheet11.set_column('B:G', 12)
|
@@ -4782,31 +5236,31 @@ def test_tables
|
|
4782
5236
|
|
4783
5237
|
# Add a table to the worksheet.
|
4784
5238
|
worksheet11.add_table(
|
4785
|
-
|
4786
|
-
|
4787
|
-
|
4788
|
-
|
4789
|
-
|
4790
|
-
|
4791
|
-
|
4792
|
-
|
4793
|
-
|
4794
|
-
|
4795
|
-
|
4796
|
-
|
4797
|
-
|
4798
|
-
|
4799
|
-
|
4800
|
-
|
4801
|
-
|
4802
|
-
|
4803
|
-
|
5239
|
+
'B3:G8',
|
5240
|
+
{
|
5241
|
+
:data => data,
|
5242
|
+
:style => 'Table Style Light 11',
|
5243
|
+
:total_row => 1,
|
5244
|
+
:columns => [
|
5245
|
+
{ :header => 'Product', :total_string => 'Totals' },
|
5246
|
+
{ :header => 'Quarter 1', :total_function => 'sum' },
|
5247
|
+
{ :header => 'Quarter 2', :total_function => 'sum' },
|
5248
|
+
{ :header => 'Quarter 3', :total_function => 'sum' },
|
5249
|
+
{ :header => 'Quarter 4', :total_function => 'sum' },
|
5250
|
+
{
|
5251
|
+
:header => 'Year',
|
5252
|
+
:formula => '=SUM(Table8[@[Quarter 1]:[Quarter 4]])',
|
5253
|
+
:total_function => 'sum'
|
5254
|
+
}
|
5255
|
+
]
|
5256
|
+
}
|
5257
|
+
)
|
4804
5258
|
|
4805
5259
|
###############################################################################
|
4806
5260
|
#
|
4807
5261
|
# Example 12.
|
4808
5262
|
#
|
4809
|
-
caption = 'Table with
|
5263
|
+
caption = 'Table with no Excel style.'
|
4810
5264
|
|
4811
5265
|
# Set the columns widths.
|
4812
5266
|
worksheet12.set_column('B:G', 12)
|
@@ -4816,41 +5270,75 @@ def test_tables
|
|
4816
5270
|
|
4817
5271
|
# Add a table to the worksheet.
|
4818
5272
|
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
|
-
|
5273
|
+
'B3:G8',
|
5274
|
+
{
|
5275
|
+
:data => data,
|
5276
|
+
:style => 'None',
|
5277
|
+
:total_row => 1,
|
5278
|
+
:columns => [
|
5279
|
+
{ :header => 'Product', :total_string => 'Totals' },
|
5280
|
+
{ :header => 'Quarter 1', :total_function => 'sum' },
|
5281
|
+
{ :header => 'Quarter 2', :total_function => 'sum' },
|
5282
|
+
{ :header => 'Quarter 3', :total_function => 'sum' },
|
5283
|
+
{ :header => 'Quarter 4', :total_function => 'sum' },
|
5284
|
+
{
|
5285
|
+
:header => 'Year',
|
5286
|
+
:formula => '=SUM(Table12[@[Quarter 1]:[Quarter 4]])',
|
5287
|
+
:total_function => 'sum'
|
5288
|
+
}
|
5289
|
+
]
|
5290
|
+
}
|
5291
|
+
)
|
5292
|
+
|
5293
|
+
###############################################################################
|
5294
|
+
#
|
5295
|
+
# Example 13.
|
5296
|
+
#
|
5297
|
+
caption = 'Table with column formats.'
|
5298
|
+
|
5299
|
+
# Set the columns widths.
|
5300
|
+
worksheet13.set_column('B:G', 12)
|
5301
|
+
|
5302
|
+
# Write the caption.
|
5303
|
+
worksheet13.write('B1', caption)
|
5304
|
+
|
5305
|
+
# Add a table to the worksheet.
|
5306
|
+
worksheet13.add_table(
|
5307
|
+
'B3:G8',
|
5308
|
+
{
|
5309
|
+
:data => data,
|
5310
|
+
:total_row => 1,
|
5311
|
+
:columns => [
|
5312
|
+
{ :header => 'Product', :total_string => 'Totals' },
|
5313
|
+
{
|
5314
|
+
:header => 'Quarter 1',
|
5315
|
+
:total_function => 'sum',
|
5316
|
+
:format => currency_format,
|
5317
|
+
},
|
5318
|
+
{
|
5319
|
+
:header => 'Quarter 2',
|
5320
|
+
:total_function => 'sum',
|
5321
|
+
:format => currency_format,
|
5322
|
+
},
|
5323
|
+
{
|
5324
|
+
:header => 'Quarter 3',
|
5325
|
+
:total_function => 'sum',
|
5326
|
+
:format => currency_format,
|
5327
|
+
},
|
5328
|
+
{
|
5329
|
+
:header => 'Quarter 4',
|
5330
|
+
:total_function => 'sum',
|
5331
|
+
:format => currency_format,
|
5332
|
+
},
|
5333
|
+
{
|
5334
|
+
:header => 'Year',
|
5335
|
+
:formula => '=SUM(Table8[@[Quarter 1]:[Quarter 4]])',
|
5336
|
+
:total_function => 'sum',
|
5337
|
+
:format => currency_format,
|
5338
|
+
}
|
5339
|
+
]
|
5340
|
+
}
|
5341
|
+
)
|
4854
5342
|
|
4855
5343
|
workbook.close
|
4856
5344
|
store_to_tempfile
|
@@ -4864,42 +5352,42 @@ def test_sparklines1
|
|
4864
5352
|
|
4865
5353
|
# Some sample data to plot.
|
4866
5354
|
data = [
|
4867
|
-
|
4868
|
-
|
4869
|
-
|
4870
|
-
|
5355
|
+
[ -2, 2, 3, -1, 0 ],
|
5356
|
+
[ 30, 20, 33, 20, 15 ],
|
5357
|
+
[ 1, -1, -1, 1, -1 ]
|
5358
|
+
]
|
4871
5359
|
|
4872
5360
|
# Write the sample data to the worksheet.
|
4873
5361
|
worksheet.write_col('A1', data)
|
4874
5362
|
|
4875
5363
|
# Add a line sparkline (the default) with markers.
|
4876
5364
|
worksheet.add_sparkline(
|
4877
|
-
|
4878
|
-
|
4879
|
-
|
4880
|
-
|
4881
|
-
|
4882
|
-
|
5365
|
+
{
|
5366
|
+
:location => 'F1',
|
5367
|
+
:range => 'Sheet1!A1:E1',
|
5368
|
+
:markers => 1
|
5369
|
+
}
|
5370
|
+
)
|
4883
5371
|
|
4884
5372
|
# Add a column sparkline with non-default style.
|
4885
5373
|
worksheet.add_sparkline(
|
4886
|
-
|
4887
|
-
|
4888
|
-
|
4889
|
-
|
4890
|
-
|
4891
|
-
|
4892
|
-
|
5374
|
+
{
|
5375
|
+
:location => 'F2',
|
5376
|
+
:range => 'Sheet1!A2:E2',
|
5377
|
+
:type => 'column',
|
5378
|
+
:style => 12
|
5379
|
+
}
|
5380
|
+
)
|
4893
5381
|
|
4894
5382
|
# Add a win/loss sparkline with negative values highlighted.
|
4895
5383
|
worksheet.add_sparkline(
|
4896
|
-
|
4897
|
-
|
4898
|
-
|
4899
|
-
|
4900
|
-
|
4901
|
-
|
4902
|
-
|
5384
|
+
{
|
5385
|
+
:location => 'F3',
|
5386
|
+
:range => 'Sheet1!A3:E3',
|
5387
|
+
:type => 'win_loss',
|
5388
|
+
:negative_points => 1
|
5389
|
+
}
|
5390
|
+
)
|
4903
5391
|
|
4904
5392
|
workbook.close
|
4905
5393
|
store_to_tempfile
|
@@ -4928,11 +5416,11 @@ def test_sparklines2
|
|
4928
5416
|
str = 'A default "line" sparkline.'
|
4929
5417
|
|
4930
5418
|
worksheet1.add_sparkline(
|
4931
|
-
|
4932
|
-
|
4933
|
-
|
4934
|
-
|
4935
|
-
|
5419
|
+
{
|
5420
|
+
:location => 'A2',
|
5421
|
+
:range => 'Sheet2!A1:J1'
|
5422
|
+
}
|
5423
|
+
)
|
4936
5424
|
|
4937
5425
|
worksheet1.write(row, 1, str)
|
4938
5426
|
row += 1
|
@@ -4942,12 +5430,12 @@ def test_sparklines2
|
|
4942
5430
|
str = 'A default "column" sparkline.'
|
4943
5431
|
|
4944
5432
|
worksheet1.add_sparkline(
|
4945
|
-
|
4946
|
-
|
4947
|
-
|
4948
|
-
|
4949
|
-
|
4950
|
-
|
5433
|
+
{
|
5434
|
+
:location => 'A3',
|
5435
|
+
:range => 'Sheet2!A2:J2',
|
5436
|
+
:type => 'column'
|
5437
|
+
}
|
5438
|
+
)
|
4951
5439
|
|
4952
5440
|
worksheet1.write(row, 1, str)
|
4953
5441
|
row += 1
|
@@ -4957,12 +5445,12 @@ def test_sparklines2
|
|
4957
5445
|
str = 'A default "win/loss" sparkline.'
|
4958
5446
|
|
4959
5447
|
worksheet1.add_sparkline(
|
4960
|
-
|
4961
|
-
|
4962
|
-
|
4963
|
-
|
4964
|
-
|
4965
|
-
|
5448
|
+
{
|
5449
|
+
:location => 'A4',
|
5450
|
+
:range => 'Sheet2!A3:J3',
|
5451
|
+
:type => 'win_loss'
|
5452
|
+
}
|
5453
|
+
)
|
4966
5454
|
|
4967
5455
|
worksheet1.write(row, 1, str)
|
4968
5456
|
row += 2
|
@@ -4972,12 +5460,12 @@ def test_sparklines2
|
|
4972
5460
|
str = 'Line with markers.'
|
4973
5461
|
|
4974
5462
|
worksheet1.add_sparkline(
|
4975
|
-
|
4976
|
-
|
4977
|
-
|
4978
|
-
|
4979
|
-
|
4980
|
-
|
5463
|
+
{
|
5464
|
+
:location => 'A6',
|
5465
|
+
:range => 'Sheet2!A1:J1',
|
5466
|
+
:markers => 1
|
5467
|
+
}
|
5468
|
+
)
|
4981
5469
|
|
4982
5470
|
worksheet1.write(row, 1, str)
|
4983
5471
|
row += 1
|
@@ -4987,13 +5475,13 @@ def test_sparklines2
|
|
4987
5475
|
str = 'Line with high and low points.'
|
4988
5476
|
|
4989
5477
|
worksheet1.add_sparkline(
|
4990
|
-
|
4991
|
-
|
4992
|
-
|
4993
|
-
|
4994
|
-
|
4995
|
-
|
4996
|
-
|
5478
|
+
{
|
5479
|
+
:location => 'A7',
|
5480
|
+
:range => 'Sheet2!A1:J1',
|
5481
|
+
:high_point => 1,
|
5482
|
+
:low_point => 1
|
5483
|
+
}
|
5484
|
+
)
|
4997
5485
|
|
4998
5486
|
worksheet1.write(row, 1, str)
|
4999
5487
|
row += 1
|
@@ -5003,13 +5491,13 @@ def test_sparklines2
|
|
5003
5491
|
str = 'Line with first and last point markers.'
|
5004
5492
|
|
5005
5493
|
worksheet1.add_sparkline(
|
5006
|
-
|
5007
|
-
|
5008
|
-
|
5009
|
-
|
5010
|
-
|
5011
|
-
|
5012
|
-
|
5494
|
+
{
|
5495
|
+
:location => 'A8',
|
5496
|
+
:range => 'Sheet2!A1:J1',
|
5497
|
+
:first_point => 1,
|
5498
|
+
:last_point => 1
|
5499
|
+
}
|
5500
|
+
)
|
5013
5501
|
|
5014
5502
|
worksheet1.write(row, 1, str)
|
5015
5503
|
row += 1
|
@@ -5019,12 +5507,12 @@ def test_sparklines2
|
|
5019
5507
|
str = 'Line with negative point markers.'
|
5020
5508
|
|
5021
5509
|
worksheet1.add_sparkline(
|
5022
|
-
|
5023
|
-
|
5024
|
-
|
5025
|
-
|
5026
|
-
|
5027
|
-
|
5510
|
+
{
|
5511
|
+
:location => 'A9',
|
5512
|
+
:range => 'Sheet2!A1:J1',
|
5513
|
+
:negative_points => 1
|
5514
|
+
}
|
5515
|
+
)
|
5028
5516
|
|
5029
5517
|
worksheet1.write(row, 1, str)
|
5030
5518
|
row += 1
|
@@ -5034,12 +5522,12 @@ def test_sparklines2
|
|
5034
5522
|
str = 'Line with axis.'
|
5035
5523
|
|
5036
5524
|
worksheet1.add_sparkline(
|
5037
|
-
|
5038
|
-
|
5039
|
-
|
5040
|
-
|
5041
|
-
|
5042
|
-
|
5525
|
+
{
|
5526
|
+
:location => 'A10',
|
5527
|
+
:range => 'Sheet2!A1:J1',
|
5528
|
+
:axis => 1
|
5529
|
+
}
|
5530
|
+
)
|
5043
5531
|
|
5044
5532
|
worksheet1.write(row, 1, str)
|
5045
5533
|
row += 2
|
@@ -5049,12 +5537,12 @@ def test_sparklines2
|
|
5049
5537
|
str = 'Column with default style (1).'
|
5050
5538
|
|
5051
5539
|
worksheet1.add_sparkline(
|
5052
|
-
|
5053
|
-
|
5054
|
-
|
5055
|
-
|
5056
|
-
|
5057
|
-
|
5540
|
+
{
|
5541
|
+
:location => 'A12',
|
5542
|
+
:range => 'Sheet2!A2:J2',
|
5543
|
+
:type => 'column'
|
5544
|
+
}
|
5545
|
+
)
|
5058
5546
|
|
5059
5547
|
worksheet1.write(row, 1, str)
|
5060
5548
|
row += 1
|
@@ -5064,13 +5552,13 @@ def test_sparklines2
|
|
5064
5552
|
str = 'Column with style 2.'
|
5065
5553
|
|
5066
5554
|
worksheet1.add_sparkline(
|
5067
|
-
|
5068
|
-
|
5069
|
-
|
5070
|
-
|
5071
|
-
|
5072
|
-
|
5073
|
-
|
5555
|
+
{
|
5556
|
+
:location => 'A13',
|
5557
|
+
:range => 'Sheet2!A2:J2',
|
5558
|
+
:type => 'column',
|
5559
|
+
:style => 2
|
5560
|
+
}
|
5561
|
+
)
|
5074
5562
|
|
5075
5563
|
worksheet1.write(row, 1, str)
|
5076
5564
|
row += 1
|
@@ -5080,13 +5568,13 @@ def test_sparklines2
|
|
5080
5568
|
str = 'Column with style 3.'
|
5081
5569
|
|
5082
5570
|
worksheet1.add_sparkline(
|
5083
|
-
|
5084
|
-
|
5085
|
-
|
5086
|
-
|
5087
|
-
|
5088
|
-
|
5089
|
-
|
5571
|
+
{
|
5572
|
+
:location => 'A14',
|
5573
|
+
:range => 'Sheet2!A2:J2',
|
5574
|
+
:type => 'column',
|
5575
|
+
:style => 3
|
5576
|
+
}
|
5577
|
+
)
|
5090
5578
|
|
5091
5579
|
worksheet1.write(row, 1, str)
|
5092
5580
|
row += 1
|
@@ -5096,13 +5584,13 @@ def test_sparklines2
|
|
5096
5584
|
str = 'Column with style 4.'
|
5097
5585
|
|
5098
5586
|
worksheet1.add_sparkline(
|
5099
|
-
|
5100
|
-
|
5101
|
-
|
5102
|
-
|
5103
|
-
|
5104
|
-
|
5105
|
-
|
5587
|
+
{
|
5588
|
+
:location => 'A15',
|
5589
|
+
:range => 'Sheet2!A2:J2',
|
5590
|
+
:type => 'column',
|
5591
|
+
:style => 4
|
5592
|
+
}
|
5593
|
+
)
|
5106
5594
|
|
5107
5595
|
worksheet1.write(row, 1, str)
|
5108
5596
|
row += 1
|
@@ -5112,13 +5600,13 @@ def test_sparklines2
|
|
5112
5600
|
str = 'Column with style 5.'
|
5113
5601
|
|
5114
5602
|
worksheet1.add_sparkline(
|
5115
|
-
|
5116
|
-
|
5117
|
-
|
5118
|
-
|
5119
|
-
|
5120
|
-
|
5121
|
-
|
5603
|
+
{
|
5604
|
+
:location => 'A16',
|
5605
|
+
:range => 'Sheet2!A2:J2',
|
5606
|
+
:type => 'column',
|
5607
|
+
:style => 5
|
5608
|
+
}
|
5609
|
+
)
|
5122
5610
|
|
5123
5611
|
worksheet1.write(row, 1, str)
|
5124
5612
|
row += 1
|
@@ -5128,13 +5616,13 @@ def test_sparklines2
|
|
5128
5616
|
str = 'Column with style 6.'
|
5129
5617
|
|
5130
5618
|
worksheet1.add_sparkline(
|
5131
|
-
|
5132
|
-
|
5133
|
-
|
5134
|
-
|
5135
|
-
|
5136
|
-
|
5137
|
-
|
5619
|
+
{
|
5620
|
+
:location => 'A17',
|
5621
|
+
:range => 'Sheet2!A2:J2',
|
5622
|
+
:type => 'column',
|
5623
|
+
:style => 6
|
5624
|
+
}
|
5625
|
+
)
|
5138
5626
|
|
5139
5627
|
worksheet1.write(row, 1, str)
|
5140
5628
|
row += 1
|
@@ -5144,13 +5632,13 @@ def test_sparklines2
|
|
5144
5632
|
str = 'Column with a user defined colour.'
|
5145
5633
|
|
5146
5634
|
worksheet1.add_sparkline(
|
5147
|
-
|
5148
|
-
|
5149
|
-
|
5150
|
-
|
5151
|
-
|
5152
|
-
|
5153
|
-
|
5635
|
+
{
|
5636
|
+
:location => 'A18',
|
5637
|
+
:range => 'Sheet2!A2:J2',
|
5638
|
+
:type => 'column',
|
5639
|
+
:series_color => '#E965E0'
|
5640
|
+
}
|
5641
|
+
)
|
5154
5642
|
|
5155
5643
|
worksheet1.write(row, 1, str)
|
5156
5644
|
row += 2
|
@@ -5160,12 +5648,12 @@ def test_sparklines2
|
|
5160
5648
|
str = 'A win/loss sparkline.'
|
5161
5649
|
|
5162
5650
|
worksheet1.add_sparkline(
|
5163
|
-
|
5164
|
-
|
5165
|
-
|
5166
|
-
|
5167
|
-
|
5168
|
-
|
5651
|
+
{
|
5652
|
+
:location => 'A20',
|
5653
|
+
:range => 'Sheet2!A3:J3',
|
5654
|
+
:type => 'win_loss'
|
5655
|
+
}
|
5656
|
+
)
|
5169
5657
|
|
5170
5658
|
worksheet1.write(row, 1, str)
|
5171
5659
|
row += 1
|
@@ -5175,13 +5663,13 @@ def test_sparklines2
|
|
5175
5663
|
str = 'A win/loss sparkline with negative points highlighted.'
|
5176
5664
|
|
5177
5665
|
worksheet1.add_sparkline(
|
5178
|
-
|
5179
|
-
|
5180
|
-
|
5181
|
-
|
5182
|
-
|
5183
|
-
|
5184
|
-
|
5666
|
+
{
|
5667
|
+
:location => 'A21',
|
5668
|
+
:range => 'Sheet2!A3:J3',
|
5669
|
+
:type => 'win_loss',
|
5670
|
+
:negative_points => 1
|
5671
|
+
}
|
5672
|
+
)
|
5185
5673
|
|
5186
5674
|
worksheet1.write(row, 1, str)
|
5187
5675
|
row += 2
|
@@ -5191,13 +5679,13 @@ def test_sparklines2
|
|
5191
5679
|
str = 'A left to right column (the default).'
|
5192
5680
|
|
5193
5681
|
worksheet1.add_sparkline(
|
5194
|
-
|
5195
|
-
|
5196
|
-
|
5197
|
-
|
5198
|
-
|
5199
|
-
|
5200
|
-
|
5682
|
+
{
|
5683
|
+
:location => 'A23',
|
5684
|
+
:range => 'Sheet2!A4:J4',
|
5685
|
+
:type => 'column',
|
5686
|
+
:style => 20
|
5687
|
+
}
|
5688
|
+
)
|
5201
5689
|
|
5202
5690
|
worksheet1.write(row, 1, str)
|
5203
5691
|
row += 1
|
@@ -5207,14 +5695,14 @@ def test_sparklines2
|
|
5207
5695
|
str = 'A right to left column.'
|
5208
5696
|
|
5209
5697
|
worksheet1.add_sparkline(
|
5210
|
-
|
5211
|
-
|
5212
|
-
|
5213
|
-
|
5214
|
-
|
5215
|
-
|
5216
|
-
|
5217
|
-
|
5698
|
+
{
|
5699
|
+
:location => 'A24',
|
5700
|
+
:range => 'Sheet2!A4:J4',
|
5701
|
+
:type => 'column',
|
5702
|
+
:style => 20,
|
5703
|
+
:reverse => 1
|
5704
|
+
}
|
5705
|
+
)
|
5218
5706
|
|
5219
5707
|
worksheet1.write(row, 1, str)
|
5220
5708
|
row += 1
|
@@ -5224,13 +5712,13 @@ def test_sparklines2
|
|
5224
5712
|
str = 'Sparkline and text in one cell.'
|
5225
5713
|
|
5226
5714
|
worksheet1.add_sparkline(
|
5227
|
-
|
5228
|
-
|
5229
|
-
|
5230
|
-
|
5231
|
-
|
5232
|
-
|
5233
|
-
|
5715
|
+
{
|
5716
|
+
:location => 'A25',
|
5717
|
+
:range => 'Sheet2!A4:J4',
|
5718
|
+
:type => 'column',
|
5719
|
+
:style => 20
|
5720
|
+
}
|
5721
|
+
)
|
5234
5722
|
|
5235
5723
|
worksheet1.write(row, 0, 'Growth')
|
5236
5724
|
worksheet1.write(row, 1, str)
|
@@ -5241,12 +5729,12 @@ def test_sparklines2
|
|
5241
5729
|
str = 'A grouped sparkline. Changes are applied to all three.'
|
5242
5730
|
|
5243
5731
|
worksheet1.add_sparkline(
|
5244
|
-
|
5245
|
-
|
5246
|
-
|
5247
|
-
|
5248
|
-
|
5249
|
-
|
5732
|
+
{
|
5733
|
+
:location => [ 'A27', 'A28', 'A29' ],
|
5734
|
+
:range => [ 'Sheet2!A5:J5', 'Sheet2!A6:J6', 'Sheet2!A7:J7' ],
|
5735
|
+
:markers => 1
|
5736
|
+
}
|
5737
|
+
)
|
5250
5738
|
|
5251
5739
|
worksheet1.write(row, 1, str)
|
5252
5740
|
row += 1
|
@@ -5258,23 +5746,23 @@ def test_sparklines2
|
|
5258
5746
|
worksheet2.set_column('A:J', 11)
|
5259
5747
|
|
5260
5748
|
data = [
|
5261
|
-
|
5262
|
-
|
5749
|
+
# Simple line data.
|
5750
|
+
[ -2, 2, 3, -1, 0, -2, 3, 2, 1, 0 ],
|
5263
5751
|
|
5264
|
-
|
5265
|
-
|
5752
|
+
# Simple column data.
|
5753
|
+
[ 30, 20, 33, 20, 15, 5, 5, 15, 10, 15 ],
|
5266
5754
|
|
5267
|
-
|
5268
|
-
|
5755
|
+
# Simple win/loss data.
|
5756
|
+
[ 1, 1, -1, -1, 1, -1, 1, 1, 1, -1 ],
|
5269
5757
|
|
5270
|
-
|
5271
|
-
|
5758
|
+
# Unbalanced histogram.
|
5759
|
+
[ 5, 6, 7, 10, 15, 20, 30, 50, 70, 100 ],
|
5272
5760
|
|
5273
|
-
|
5274
|
-
|
5275
|
-
|
5276
|
-
|
5277
|
-
|
5761
|
+
# Data for the grouped sparkline example.
|
5762
|
+
[ -2, 2, 3, -1, 0, -2, 3, 2, 1, 0 ],
|
5763
|
+
[ 3, -1, 0, -2, 3, 2, 1, 0, 2, 1 ],
|
5764
|
+
[ 0, -2, 3, 2, 1, 0, 1, 2, 3, 1 ]
|
5765
|
+
]
|
5278
5766
|
|
5279
5767
|
# Write the sample data to the worksheet.
|
5280
5768
|
worksheet2.write_col('A1', data)
|
@@ -5339,10 +5827,10 @@ def test_chart_data_table
|
|
5339
5827
|
# Add the worksheet data that the charts will refer to.
|
5340
5828
|
headings = [ 'Number', 'Batch 1', 'Batch 2' ]
|
5341
5829
|
data = [
|
5342
|
-
|
5343
|
-
|
5344
|
-
|
5345
|
-
|
5830
|
+
[ 2, 3, 4, 5, 6, 7 ],
|
5831
|
+
[ 10, 40, 50, 20, 10, 50 ],
|
5832
|
+
[ 30, 60, 70, 50, 40, 30 ]
|
5833
|
+
]
|
5346
5834
|
|
5347
5835
|
worksheet.write('A1', headings, bold)
|
5348
5836
|
worksheet.write('A2', data)
|
@@ -5352,18 +5840,18 @@ def test_chart_data_table
|
|
5352
5840
|
|
5353
5841
|
# Configure the first series.
|
5354
5842
|
chart1.add_series(
|
5355
|
-
|
5356
|
-
|
5357
|
-
|
5358
|
-
|
5843
|
+
:name => '=Sheet1!$B$1',
|
5844
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
5845
|
+
:values => '=Sheet1!$B$2:$B$7'
|
5846
|
+
)
|
5359
5847
|
|
5360
5848
|
# Configure second series. Note alternative use of array ref to define
|
5361
5849
|
# ranges: [ sheetname, row_start, row_end, col_start, col_end ].
|
5362
5850
|
chart1.add_series(
|
5363
|
-
|
5364
|
-
|
5365
|
-
|
5366
|
-
|
5851
|
+
:name => '=Sheet1!$C$1',
|
5852
|
+
:categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
5853
|
+
:values => [ 'Sheet1', 1, 6, 2, 2 ]
|
5854
|
+
)
|
5367
5855
|
|
5368
5856
|
# Add a chart title and some axis labels.
|
5369
5857
|
chart1.set_title(:name => 'Chart with Data Table')
|
@@ -5383,18 +5871,18 @@ def test_chart_data_table
|
|
5383
5871
|
|
5384
5872
|
# Configure the first series.
|
5385
5873
|
chart2.add_series(
|
5386
|
-
|
5387
|
-
|
5388
|
-
|
5389
|
-
|
5874
|
+
:name => '=Sheet1!$B$1',
|
5875
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
5876
|
+
:values => '=Sheet1!$B$2:$B$7'
|
5877
|
+
)
|
5390
5878
|
|
5391
5879
|
# Configure second series. Note alternative use of array ref to define
|
5392
5880
|
# ranges: [ sheetname, row_start, row_end, col_start, col_end ].
|
5393
5881
|
chart2.add_series(
|
5394
|
-
|
5395
|
-
|
5396
|
-
|
5397
|
-
|
5882
|
+
:name => '=Sheet1!$C$1',
|
5883
|
+
:categories => [ 'Sheet1', 1, 6, 0, 0 ],
|
5884
|
+
:values => [ 'Sheet1', 1, 6, 2, 2 ]
|
5885
|
+
)
|
5398
5886
|
|
5399
5887
|
# Add a chart title and some axis labels.
|
5400
5888
|
chart2.set_title(:name => 'Data Table with legend keys')
|
@@ -5424,10 +5912,10 @@ def test_chart_data_tools
|
|
5424
5912
|
# Add the worksheet data that the charts will refer to.
|
5425
5913
|
headings = [ 'Number', 'Data 1', 'Data 2' ]
|
5426
5914
|
data = [
|
5427
|
-
|
5428
|
-
|
5429
|
-
|
5430
|
-
|
5915
|
+
[ 2, 3, 4, 5, 6, 7 ],
|
5916
|
+
[ 10, 40, 50, 20, 10, 50 ],
|
5917
|
+
[ 30, 60, 70, 50, 40, 30 ]
|
5918
|
+
]
|
5431
5919
|
|
5432
5920
|
worksheet.write('A1', headings, bold)
|
5433
5921
|
worksheet.write('A2', data)
|
@@ -5443,20 +5931,20 @@ def test_chart_data_tools
|
|
5443
5931
|
|
5444
5932
|
# Configure the first series with a polynomial trendline.
|
5445
5933
|
chart1.add_series(
|
5446
|
-
|
5447
|
-
|
5448
|
-
|
5449
|
-
|
5450
|
-
|
5451
|
-
|
5452
|
-
|
5934
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
5935
|
+
:values => '=Sheet1!$B$2:$B$7',
|
5936
|
+
:trendline => {
|
5937
|
+
:type => 'polynomial',
|
5938
|
+
:order => 3,
|
5939
|
+
}
|
5940
|
+
)
|
5453
5941
|
|
5454
5942
|
# Configure the second series with a moving average trendline.
|
5455
5943
|
chart1.add_series(
|
5456
|
-
|
5457
|
-
|
5458
|
-
|
5459
|
-
|
5944
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
5945
|
+
:values => '=Sheet1!$C$2:$C$7',
|
5946
|
+
:trendline => { :type => 'linear' }
|
5947
|
+
)
|
5460
5948
|
|
5461
5949
|
# Add a chart title. and some axis labels.
|
5462
5950
|
chart1.set_title(:name => 'Chart with Trendlines')
|
@@ -5474,17 +5962,17 @@ def test_chart_data_tools
|
|
5474
5962
|
|
5475
5963
|
# Configure the first series.
|
5476
5964
|
chart2.add_series(
|
5477
|
-
|
5478
|
-
|
5479
|
-
|
5480
|
-
|
5481
|
-
|
5965
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
5966
|
+
:values => '=Sheet1!$B$2:$B$7',
|
5967
|
+
:data_labels => { :value => 1 },
|
5968
|
+
:marker => { :type => 'automatic' }
|
5969
|
+
)
|
5482
5970
|
|
5483
5971
|
# Configure the second series.
|
5484
5972
|
chart2.add_series(
|
5485
|
-
|
5486
|
-
|
5487
|
-
|
5973
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
5974
|
+
:values => '=Sheet1!$C$2:$C$7'
|
5975
|
+
)
|
5488
5976
|
|
5489
5977
|
# Add a chart title. and some axis labels.
|
5490
5978
|
chart2.set_title(:name => 'Chart with Data Labels and Markers')
|
@@ -5502,16 +5990,16 @@ def test_chart_data_tools
|
|
5502
5990
|
|
5503
5991
|
# Configure the first series.
|
5504
5992
|
chart3.add_series(
|
5505
|
-
|
5506
|
-
|
5507
|
-
|
5508
|
-
|
5993
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
5994
|
+
:values => '=Sheet1!$B$2:$B$7',
|
5995
|
+
:y_error_bars => { :type => 'standard_error' }
|
5996
|
+
)
|
5509
5997
|
|
5510
5998
|
# Configure the second series.
|
5511
5999
|
chart3.add_series(
|
5512
|
-
|
5513
|
-
|
5514
|
-
|
6000
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
6001
|
+
:values => '=Sheet1!$C$2:$C$7'
|
6002
|
+
)
|
5515
6003
|
|
5516
6004
|
# Add a chart title. and some axis labels.
|
5517
6005
|
chart3.set_title(:name => 'Chart with Error Bars')
|
@@ -5532,15 +6020,15 @@ def test_chart_data_tools
|
|
5532
6020
|
|
5533
6021
|
# Configure the first series.
|
5534
6022
|
chart4.add_series(
|
5535
|
-
|
5536
|
-
|
5537
|
-
|
6023
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
6024
|
+
:values => '=Sheet1!$B$2:$B$7'
|
6025
|
+
)
|
5538
6026
|
|
5539
6027
|
# Configure the second series.
|
5540
6028
|
chart4.add_series(
|
5541
|
-
|
5542
|
-
|
5543
|
-
|
6029
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
6030
|
+
:values => '=Sheet1!$C$2:$C$7'
|
6031
|
+
)
|
5544
6032
|
|
5545
6033
|
# Add a chart title. and some axis labels.
|
5546
6034
|
chart4.set_title(:name => 'Chart with Up-Down Bars')
|
@@ -5561,15 +6049,15 @@ def test_chart_data_tools
|
|
5561
6049
|
|
5562
6050
|
# Configure the first series.
|
5563
6051
|
chart5.add_series(
|
5564
|
-
|
5565
|
-
|
5566
|
-
|
6052
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
6053
|
+
:values => '=Sheet1!$B$2:$B$7'
|
6054
|
+
)
|
5567
6055
|
|
5568
6056
|
# Configure the second series.
|
5569
6057
|
chart5.add_series(
|
5570
|
-
|
5571
|
-
|
5572
|
-
|
6058
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
6059
|
+
:values => '=Sheet1!$C$2:$C$7'
|
6060
|
+
)
|
5573
6061
|
|
5574
6062
|
# Add a chart title. and some axis labels.
|
5575
6063
|
chart5.set_title(:name => 'Chart with High-Low Lines')
|
@@ -5590,15 +6078,15 @@ def test_chart_data_tools
|
|
5590
6078
|
|
5591
6079
|
# Configure the first series.
|
5592
6080
|
chart6.add_series(
|
5593
|
-
|
5594
|
-
|
5595
|
-
|
6081
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
6082
|
+
:values => '=Sheet1!$B$2:$B$7'
|
6083
|
+
)
|
5596
6084
|
|
5597
6085
|
# Configure the second series.
|
5598
6086
|
chart6.add_series(
|
5599
|
-
|
5600
|
-
|
5601
|
-
|
6087
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
6088
|
+
:values => '=Sheet1!$C$2:$C$7'
|
6089
|
+
)
|
5602
6090
|
|
5603
6091
|
# Add a chart title. and some axis labels.
|
5604
6092
|
chart6.set_title(:name => 'Chart with Drop Lines')
|