write_xlsx 1.02.0 → 1.08.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/Changes +72 -0
- data/README.md +1 -1
- data/examples/chart_data_labels.rb +320 -0
- data/examples/chart_line.rb +85 -10
- data/examples/tables.rb +77 -42
- data/lib/write_xlsx/chart/line.rb +15 -1
- data/lib/write_xlsx/chart/series.rb +100 -0
- data/lib/write_xlsx/chart.rb +155 -33
- data/lib/write_xlsx/drawing.rb +80 -17
- data/lib/write_xlsx/format.rb +5 -5
- data/lib/write_xlsx/package/app.rb +3 -3
- data/lib/write_xlsx/package/comments.rb +4 -4
- data/lib/write_xlsx/package/conditional_format.rb +2 -8
- data/lib/write_xlsx/package/packager.rb +1 -0
- data/lib/write_xlsx/package/relationships.rb +2 -2
- data/lib/write_xlsx/package/styles.rb +42 -11
- data/lib/write_xlsx/package/table.rb +16 -7
- data/lib/write_xlsx/package/vml.rb +20 -19
- data/lib/write_xlsx/sheets.rb +12 -20
- data/lib/write_xlsx/utility.rb +9 -3
- data/lib/write_xlsx/version.rb +1 -1
- data/lib/write_xlsx/workbook.rb +76 -35
- data/lib/write_xlsx/worksheet/data_validation.rb +1 -6
- data/lib/write_xlsx/worksheet.rb +197 -57
- data/test/drawing/{test_write_ext.rb → test_write_xdr_ext.rb} +2 -2
- data/test/perl_output/chart_data_labels.xlsx +0 -0
- data/test/perl_output/chart_line.xlsx +0 -0
- data/test/perl_output/comments2.xlsx +0 -0
- data/test/perl_output/tables.xlsx +0 -0
- data/test/regression/images/red2.png +0 -0
- data/test/regression/test_array_formula04.rb +31 -0
- data/test/regression/test_chart_crossing01.rb +1 -1
- data/test/regression/test_chart_crossing05.rb +46 -0
- data/test/regression/test_chart_crossing06.rb +46 -0
- data/test/regression/test_chart_data_labels26.rb +44 -0
- data/test/regression/test_chart_data_labels27.rb +44 -0
- data/test/regression/test_chart_data_labels28.rb +52 -0
- data/test/regression/test_chart_data_labels29.rb +43 -0
- data/test/regression/test_chart_data_labels30.rb +46 -0
- data/test/regression/test_chart_data_labels31.rb +49 -0
- data/test/regression/test_chart_data_labels32.rb +54 -0
- data/test/regression/test_chart_data_labels33.rb +52 -0
- data/test/regression/test_chart_data_labels34.rb +54 -0
- data/test/regression/test_chart_data_labels35.rb +46 -0
- data/test/regression/test_chart_data_labels36.rb +54 -0
- data/test/regression/test_chart_data_labels37.rb +51 -0
- data/test/regression/test_chart_data_labels38.rb +54 -0
- data/test/regression/test_chart_data_labels39.rb +53 -0
- data/test/regression/test_chart_data_labels40.rb +53 -0
- data/test/regression/test_chart_data_labels41.rb +54 -0
- data/test/regression/test_chart_data_labels42.rb +58 -0
- data/test/regression/test_chart_data_labels43.rb +58 -0
- data/test/regression/test_chart_data_labels44.rb +56 -0
- data/test/regression/test_chart_data_labels45.rb +57 -0
- data/test/regression/test_chart_data_labels46.rb +61 -0
- data/test/regression/test_chart_data_labels47.rb +61 -0
- data/test/regression/test_chart_data_labels48.rb +55 -0
- data/test/regression/test_chart_data_labels49.rb +55 -0
- data/test/regression/test_chart_data_labels50.rb +57 -0
- data/test/regression/test_chart_line05.rb +43 -0
- data/test/regression/test_chart_line06.rb +43 -0
- data/test/regression/test_comment15.rb +28 -0
- data/test/regression/test_comment16.rb +34 -0
- data/test/regression/test_format16.rb +24 -0
- data/test/regression/test_format17.rb +24 -0
- data/test/regression/test_header04.rb +30 -0
- data/test/regression/test_header_image15.rb +36 -0
- data/test/regression/test_header_image16.rb +42 -0
- data/test/regression/test_header_image17.rb +46 -0
- data/test/regression/test_header_image18.rb +48 -0
- data/test/regression/test_header_image19.rb +36 -0
- data/test/regression/test_hyperlink48.rb +31 -0
- data/test/regression/test_hyperlink49.rb +29 -0
- data/test/regression/test_hyperlink50.rb +27 -0
- data/test/regression/test_hyperlink51.rb +27 -0
- data/test/regression/test_ignore_error01.rb +23 -0
- data/test/regression/test_ignore_error02.rb +24 -0
- data/test/regression/test_ignore_error03.rb +26 -0
- data/test/regression/test_ignore_error04.rb +26 -0
- data/test/regression/test_ignore_error05.rb +32 -0
- data/test/regression/test_ignore_error06.rb +32 -0
- data/test/regression/test_image45.rb +2 -1
- data/test/regression/test_image46.rb +1 -1
- data/test/regression/test_image48.rb +32 -0
- data/test/regression/test_image49.rb +38 -0
- data/test/regression/test_image50.rb +24 -0
- data/test/regression/test_image51.rb +30 -0
- data/test/regression/test_image52.rb +26 -0
- data/test/regression/test_image53.rb +26 -0
- data/test/regression/test_image54.rb +26 -0
- data/test/regression/test_image55.rb +27 -0
- data/test/regression/test_object_position12.rb +25 -0
- data/test/regression/test_object_position13.rb +25 -0
- data/test/regression/test_object_position14.rb +25 -0
- data/test/regression/test_object_position15.rb +29 -0
- data/test/regression/test_object_position16.rb +29 -0
- data/test/regression/test_object_position17.rb +29 -0
- data/test/regression/test_object_position18.rb +29 -0
- data/test/regression/test_object_position19.rb +29 -0
- data/test/regression/test_object_position20.rb +29 -0
- data/test/regression/test_protect04.rb +32 -0
- data/test/regression/test_protect05.rb +35 -0
- data/test/regression/test_protect06.rb +35 -0
- data/test/regression/test_protect07.rb +23 -0
- data/test/regression/test_table24.rb +27 -0
- data/test/regression/test_table25.rb +27 -0
- data/test/regression/test_table26.rb +38 -0
- data/test/regression/xlsx_files/array_formula04.xlsx +0 -0
- data/test/regression/xlsx_files/chart_crossing05.xlsx +0 -0
- data/test/regression/xlsx_files/chart_crossing06.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels26.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels27.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels28.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels29.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels30.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels31.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels32.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels33.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels34.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels35.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels36.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels37.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels38.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels39.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels40.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels41.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels42.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels43.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels44.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels45.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels46.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels47.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels48.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels49.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels50.xlsx +0 -0
- data/test/regression/xlsx_files/chart_line05.xlsx +0 -0
- data/test/regression/xlsx_files/chart_line06.xlsx +0 -0
- data/test/regression/xlsx_files/comment15.xlsx +0 -0
- data/test/regression/xlsx_files/comment16.xlsx +0 -0
- data/test/regression/xlsx_files/format16.xlsx +0 -0
- data/test/regression/xlsx_files/format17.xlsx +0 -0
- data/test/regression/xlsx_files/header04.xlsx +0 -0
- data/test/regression/xlsx_files/header_image15.xlsx +0 -0
- data/test/regression/xlsx_files/header_image16.xlsx +0 -0
- data/test/regression/xlsx_files/header_image17.xlsx +0 -0
- data/test/regression/xlsx_files/header_image18.xlsx +0 -0
- data/test/regression/xlsx_files/header_image19.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink46.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink50.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink51.xlsx +0 -0
- data/test/regression/xlsx_files/ignore_error01.xlsx +0 -0
- data/test/regression/xlsx_files/ignore_error02.xlsx +0 -0
- data/test/regression/xlsx_files/ignore_error03.xlsx +0 -0
- data/test/regression/xlsx_files/ignore_error04.xlsx +0 -0
- data/test/regression/xlsx_files/ignore_error05.xlsx +0 -0
- data/test/regression/xlsx_files/ignore_error06.xlsx +0 -0
- data/test/regression/xlsx_files/image45.xlsx +0 -0
- data/test/regression/xlsx_files/image46.xlsx +0 -0
- data/test/regression/xlsx_files/image48.xlsx +0 -0
- data/test/regression/xlsx_files/image49.xlsx +0 -0
- data/test/regression/xlsx_files/image50.xlsx +0 -0
- data/test/regression/xlsx_files/image51.xlsx +0 -0
- data/test/regression/xlsx_files/image52.xlsx +0 -0
- data/test/regression/xlsx_files/image53.xlsx +0 -0
- data/test/regression/xlsx_files/image54.xlsx +0 -0
- data/test/regression/xlsx_files/image55.xlsx +0 -0
- data/test/regression/xlsx_files/object_position12.xlsx +0 -0
- data/test/regression/xlsx_files/object_position13.xlsx +0 -0
- data/test/regression/xlsx_files/object_position14.xlsx +0 -0
- data/test/regression/xlsx_files/object_position15.xlsx +0 -0
- data/test/regression/xlsx_files/object_position16.xlsx +0 -0
- data/test/regression/xlsx_files/object_position17.xlsx +0 -0
- data/test/regression/xlsx_files/object_position18.xlsx +0 -0
- data/test/regression/xlsx_files/object_position19.xlsx +0 -0
- data/test/regression/xlsx_files/object_position20.xlsx +0 -0
- data/test/regression/xlsx_files/protect04.xlsx +0 -0
- data/test/regression/xlsx_files/protect05.xlsx +0 -0
- data/test/regression/xlsx_files/protect06.xlsx +0 -0
- data/test/regression/xlsx_files/protect07.xlsx +0 -0
- data/test/regression/xlsx_files/table24.xlsx +0 -0
- data/test/regression/xlsx_files/table25.xlsx +0 -0
- data/test/regression/xlsx_files/table26.xlsx +0 -0
- data/test/test_example_match.rb +433 -10
- data/test/utility/test_range.rb +20 -0
- data/test/workbook/test_check_sheetname.rb +0 -10
- data/write_xlsx.gemspec +1 -0
- metadata +323 -8
data/test/test_example_match.rb
CHANGED
@@ -242,6 +242,319 @@ class TestExampleMatch < Minitest::Test
|
|
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
|
+
|
245
558
|
def test_chart_gauge
|
246
559
|
@xlsx = 'chart_gauge.xlsx'
|
247
560
|
workbook = WriteXLSX.new(@io)
|
@@ -577,7 +890,7 @@ EOS
|
|
577
890
|
:name => 'Doughnut sales data',
|
578
891
|
:categories => [ 'Sheet1', 1, 3, 0, 0 ],
|
579
892
|
:values => [ 'Sheet1', 1, 3, 1, 1 ]
|
580
|
-
)
|
893
|
+
)
|
581
894
|
|
582
895
|
# Add a title.
|
583
896
|
chart1.set_title(:name => 'Popular Doughnut Types')
|
@@ -714,6 +1027,81 @@ EOS
|
|
714
1027
|
# Insert the chart into the worksheet (with an offset).
|
715
1028
|
worksheet.insert_chart('D2', chart, 25, 10)
|
716
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
|
+
|
717
1105
|
workbook.close
|
718
1106
|
store_to_tempfile
|
719
1107
|
compare_xlsx(File.join(@perl_output, @xlsx), @tempfile.path)
|
@@ -1320,7 +1708,7 @@ EOS
|
|
1320
1708
|
comment = 'Hello.'
|
1321
1709
|
|
1322
1710
|
worksheet6.write( 'C9', cell_text, text_wrap )
|
1323
|
-
worksheet6.write_comment( 'C9', comment, :color =>
|
1711
|
+
worksheet6.write_comment( 'C9', comment, :color => '#FF6600' )
|
1324
1712
|
|
1325
1713
|
|
1326
1714
|
###############################################################################
|
@@ -4595,6 +4983,7 @@ EOS
|
|
4595
4983
|
worksheet10 = workbook.add_worksheet
|
4596
4984
|
worksheet11 = workbook.add_worksheet
|
4597
4985
|
worksheet12 = workbook.add_worksheet
|
4986
|
+
worksheet13 = workbook.add_worksheet
|
4598
4987
|
|
4599
4988
|
currency_format = workbook.add_format(:num_format => '$#,##0')
|
4600
4989
|
|
@@ -4626,7 +5015,7 @@ EOS
|
|
4626
5015
|
#
|
4627
5016
|
# Example 2.
|
4628
5017
|
#
|
4629
|
-
caption = 'Default table with data.'
|
5018
|
+
caption = 'Default table with data.'
|
4630
5019
|
|
4631
5020
|
# Set the columns widths.
|
4632
5021
|
worksheet2.set_column('B:G', 12)
|
@@ -4695,7 +5084,7 @@ EOS
|
|
4695
5084
|
#
|
4696
5085
|
# Example 6.
|
4697
5086
|
#
|
4698
|
-
caption = 'Table with banded columns but without default banded rows.'
|
5087
|
+
caption = 'Table with banded columns but without default banded rows.'
|
4699
5088
|
|
4700
5089
|
# Set the columns widths.
|
4701
5090
|
worksheet6.set_column('B:G', 12)
|
@@ -4713,7 +5102,7 @@ EOS
|
|
4713
5102
|
#
|
4714
5103
|
# Example 7.
|
4715
5104
|
#
|
4716
|
-
caption = 'Table with user defined column headers'
|
5105
|
+
caption = 'Table with user defined column headers'
|
4717
5106
|
|
4718
5107
|
# Set the columns widths.
|
4719
5108
|
worksheet7.set_column('B:G', 12)
|
@@ -4740,7 +5129,7 @@ EOS
|
|
4740
5129
|
#
|
4741
5130
|
# Example 8.
|
4742
5131
|
#
|
4743
|
-
caption = 'Table with user defined column headers'
|
5132
|
+
caption = 'Table with user defined column headers'
|
4744
5133
|
|
4745
5134
|
# Set the columns widths.
|
4746
5135
|
worksheet8.set_column('B:G', 12)
|
@@ -4772,7 +5161,7 @@ EOS
|
|
4772
5161
|
#
|
4773
5162
|
# Example 9.
|
4774
5163
|
#
|
4775
|
-
caption = 'Table with totals row (but no caption or totals).'
|
5164
|
+
caption = 'Table with totals row (but no caption or totals).'
|
4776
5165
|
|
4777
5166
|
# Set the columns widths.
|
4778
5167
|
worksheet9.set_column('B:G', 12)
|
@@ -4804,7 +5193,7 @@ EOS
|
|
4804
5193
|
#
|
4805
5194
|
# Example 10.
|
4806
5195
|
#
|
4807
|
-
caption = 'Table with totals row with user captions and functions.'
|
5196
|
+
caption = 'Table with totals row with user captions and functions.'
|
4808
5197
|
|
4809
5198
|
# Set the columns widths.
|
4810
5199
|
worksheet10.set_column('B:G', 12)
|
@@ -4837,7 +5226,7 @@ EOS
|
|
4837
5226
|
#
|
4838
5227
|
# Example 11.
|
4839
5228
|
#
|
4840
|
-
caption = 'Table with alternative Excel style.'
|
5229
|
+
caption = 'Table with alternative Excel style.'
|
4841
5230
|
|
4842
5231
|
# Set the columns widths.
|
4843
5232
|
worksheet11.set_column('B:G', 12)
|
@@ -4871,7 +5260,7 @@ EOS
|
|
4871
5260
|
#
|
4872
5261
|
# Example 12.
|
4873
5262
|
#
|
4874
|
-
caption = 'Table with
|
5263
|
+
caption = 'Table with no Excel style.'
|
4875
5264
|
|
4876
5265
|
# Set the columns widths.
|
4877
5266
|
worksheet12.set_column('B:G', 12)
|
@@ -4881,6 +5270,40 @@ EOS
|
|
4881
5270
|
|
4882
5271
|
# Add a table to the worksheet.
|
4883
5272
|
worksheet12.add_table(
|
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(
|
4884
5307
|
'B3:G8',
|
4885
5308
|
{
|
4886
5309
|
:data => data,
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestRange < Minitest::Test
|
5
|
+
include Writexlsx::Utility
|
6
|
+
|
7
|
+
def test_range_0_0_1_1
|
8
|
+
assert_equal(
|
9
|
+
'B1',
|
10
|
+
xl_range(0, 0, 1, 1)
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_range_0_0_1_1_1_1_1_1
|
15
|
+
assert_equal(
|
16
|
+
'$B$1',
|
17
|
+
xl_range(0, 0, 1, 1, 1, 1, 1, 1)
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
@@ -48,14 +48,4 @@ class TestCheckSheetname < Minitest::Test
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
52
|
-
def test_check_sheetname_reserved_name
|
53
|
-
reserved_names = ['History', 'history', 'HISTORY', 'HisTory']
|
54
|
-
|
55
|
-
reserved_names.each do |sheetname|
|
56
|
-
assert_raises RuntimeError, "'#{sheetname}' passed incorrectly" do
|
57
|
-
@workbook.add_worksheet(sheetname)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
51
|
end
|
data/write_xlsx.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |gem|
|
|
20
20
|
gem.add_runtime_dependency 'rubyzip', '>= 1.0.0'
|
21
21
|
gem.add_runtime_dependency 'zip-zip'
|
22
22
|
gem.add_development_dependency 'minitest'
|
23
|
+
gem.add_development_dependency 'byebug'
|
23
24
|
gem.add_development_dependency 'rake'
|
24
25
|
gem.extra_rdoc_files = [
|
25
26
|
"LICENSE.txt",
|