write_xlsx 0.90.0 → 0.97.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/Changes +37 -0
  3. data/README.md +1 -1
  4. data/examples/a_simple.rb +1 -6
  5. data/examples/conditional_format.rb +73 -46
  6. data/examples/demo.rb +1 -7
  7. data/examples/hyperlink1.rb +4 -11
  8. data/lib/write_xlsx/chart.rb +81 -205
  9. data/lib/write_xlsx/chart/axis.rb +2 -2
  10. data/lib/write_xlsx/chart/caption.rb +3 -1
  11. data/lib/write_xlsx/chart/pie.rb +2 -0
  12. data/lib/write_xlsx/chart/series.rb +11 -7
  13. data/lib/write_xlsx/format.rb +15 -11
  14. data/lib/write_xlsx/package/conditional_format.rb +351 -38
  15. data/lib/write_xlsx/package/content_types.rb +10 -0
  16. data/lib/write_xlsx/package/custom.rb +125 -0
  17. data/lib/write_xlsx/package/packager.rb +26 -0
  18. data/lib/write_xlsx/package/styles.rb +53 -21
  19. data/lib/write_xlsx/package/table.rb +11 -4
  20. data/lib/write_xlsx/utility.rb +234 -34
  21. data/lib/write_xlsx/version.rb +1 -1
  22. data/lib/write_xlsx/workbook.rb +88 -1
  23. data/lib/write_xlsx/worksheet.rb +247 -23
  24. data/test/helper.rb +6 -1
  25. data/test/regression/_test_hyperlink31.rb +26 -0
  26. data/test/regression/images/zero_dpi.jpg +0 -0
  27. data/test/regression/test_chart_bar08.rb +3 -0
  28. data/test/regression/test_chart_bar11.rb +3 -0
  29. data/test/regression/test_chart_bar14.rb +3 -0
  30. data/test/regression/test_chart_chartarea05.rb +16 -17
  31. data/test/regression/test_chart_chartarea06.rb +49 -0
  32. data/test/regression/test_chart_data_labels25.rb +61 -0
  33. data/test/regression/test_chart_format26.rb +48 -0
  34. data/test/regression/test_chart_format27.rb +58 -0
  35. data/test/regression/test_chart_format28.rb +52 -0
  36. data/test/regression/test_chart_format29.rb +59 -0
  37. data/test/regression/test_chart_format30.rb +53 -0
  38. data/test/regression/test_chart_format31.rb +60 -0
  39. data/test/regression/test_chart_table03.rb +56 -0
  40. data/test/regression/test_cond_format14.rb +42 -0
  41. data/test/regression/test_cond_format15.rb +53 -0
  42. data/test/regression/test_cond_format16.rb +53 -0
  43. data/test/regression/test_cond_format17.rb +37 -0
  44. data/test/regression/test_cond_format18.rb +136 -0
  45. data/test/regression/test_date_1904_01.rb +1 -1
  46. data/test/regression/test_escapes04.rb +3 -0
  47. data/test/regression/test_escapes05.rb +3 -0
  48. data/test/regression/test_escapes07.rb +3 -0
  49. data/test/regression/test_escapes08.rb +3 -0
  50. data/test/regression/test_hyperlink01.rb +3 -0
  51. data/test/regression/test_hyperlink02.rb +3 -0
  52. data/test/regression/test_hyperlink03.rb +4 -0
  53. data/test/regression/test_hyperlink04.rb +3 -0
  54. data/test/regression/test_hyperlink05.rb +3 -0
  55. data/test/regression/test_hyperlink06.rb +3 -0
  56. data/test/regression/test_hyperlink07.rb +3 -0
  57. data/test/regression/test_hyperlink08.rb +3 -0
  58. data/test/regression/test_hyperlink09.rb +3 -0
  59. data/test/regression/test_hyperlink10.rb +3 -0
  60. data/test/regression/test_hyperlink11.rb +3 -0
  61. data/test/regression/test_hyperlink12.rb +3 -0
  62. data/test/regression/test_hyperlink13.rb +3 -0
  63. data/test/regression/test_hyperlink14.rb +3 -0
  64. data/test/regression/test_hyperlink15.rb +3 -0
  65. data/test/regression/test_hyperlink16.rb +3 -0
  66. data/test/regression/test_hyperlink17.rb +3 -0
  67. data/test/regression/test_hyperlink18.rb +3 -0
  68. data/test/regression/test_hyperlink20.rb +3 -0
  69. data/test/regression/test_hyperlink21.rb +3 -0
  70. data/test/regression/test_hyperlink22.rb +3 -0
  71. data/test/regression/test_hyperlink23.rb +3 -0
  72. data/test/regression/test_hyperlink24.rb +3 -0
  73. data/test/regression/test_hyperlink25.rb +3 -0
  74. data/test/regression/test_hyperlink26.rb +3 -0
  75. data/test/regression/test_hyperlink27.rb +3 -0
  76. data/test/regression/test_hyperlink28.rb +50 -0
  77. data/test/regression/test_hyperlink29.rb +27 -0
  78. data/test/regression/test_hyperlink30.rb +36 -0
  79. data/test/regression/test_image35.rb +26 -0
  80. data/test/regression/test_properties01.rb +1 -4
  81. data/test/regression/test_properties02.rb +1 -4
  82. data/test/regression/test_properties03.rb +26 -0
  83. data/test/regression/test_properties04.rb +61 -0
  84. data/test/regression/test_properties05.rb +30 -0
  85. data/test/regression/test_table03.rb +3 -0
  86. data/test/regression/test_table04.rb +3 -0
  87. data/test/regression/test_table05.rb +3 -0
  88. data/test/regression/test_table06.rb +3 -0
  89. data/test/regression/test_table20.rb +34 -0
  90. data/test/regression/test_table21.rb +36 -0
  91. data/test/regression/test_table22.rb +32 -0
  92. data/test/regression/xlsx_files/chart_chartarea05.xlsx +0 -0
  93. data/test/regression/xlsx_files/chart_chartarea06.xlsx +0 -0
  94. data/test/regression/xlsx_files/chart_data_labels25.xlsx +0 -0
  95. data/test/regression/xlsx_files/chart_format26.xlsx +0 -0
  96. data/test/regression/xlsx_files/chart_format27.xlsx +0 -0
  97. data/test/regression/xlsx_files/chart_format28.xlsx +0 -0
  98. data/test/regression/xlsx_files/chart_format29.xlsx +0 -0
  99. data/test/regression/xlsx_files/chart_format30.xlsx +0 -0
  100. data/test/regression/xlsx_files/chart_format31.xlsx +0 -0
  101. data/test/regression/xlsx_files/chart_table03.xlsx +0 -0
  102. data/test/regression/xlsx_files/cond_format14.xlsx +0 -0
  103. data/test/regression/xlsx_files/cond_format15.xlsx +0 -0
  104. data/test/regression/xlsx_files/cond_format16.xlsx +0 -0
  105. data/test/regression/xlsx_files/cond_format17.xlsx +0 -0
  106. data/test/regression/xlsx_files/cond_format18.xlsx +0 -0
  107. data/test/regression/xlsx_files/date_1904_01.xlsx +0 -0
  108. data/test/regression/xlsx_files/hyperlink28.xlsx +0 -0
  109. data/test/regression/xlsx_files/hyperlink29.xlsx +0 -0
  110. data/test/regression/xlsx_files/hyperlink30.xlsx +0 -0
  111. data/test/regression/xlsx_files/hyperlink31.xlsx +0 -0
  112. data/test/regression/xlsx_files/image35.xlsx +0 -0
  113. data/test/regression/xlsx_files/properties03.xlsx +0 -0
  114. data/test/regression/xlsx_files/properties04.xlsx +0 -0
  115. data/test/regression/xlsx_files/properties05.xlsx +0 -0
  116. data/test/regression/xlsx_files/table21.xlsx +0 -0
  117. data/test/regression/xlsx_files/table22.xlsx +0 -0
  118. data/test/workbook/test_write_workbook_view.rb +81 -0
  119. data/test/worksheet/test_cond_format_22.rb +266 -0
  120. data/test/worksheet/test_cond_format_23.rb +242 -0
  121. data/test/worksheet/test_cond_format_24.rb +303 -0
  122. data/test/worksheet/test_data_bar_01.rb +53 -0
  123. data/test/worksheet/test_data_bar_02.rb +79 -0
  124. data/test/worksheet/test_data_bar_03.rb +147 -0
  125. data/test/worksheet/test_data_bar_04.rb +145 -0
  126. data/test/worksheet/test_data_bar_05.rb +147 -0
  127. data/test/worksheet/test_data_bar_06.rb +145 -0
  128. data/test/worksheet/test_data_bar_07.rb +146 -0
  129. data/test/worksheet/test_data_bar_08.rb +54 -0
  130. data/test/worksheet/test_data_bar_09.rb +80 -0
  131. data/test/worksheet/test_data_bar_10.rb +165 -0
  132. data/test/worksheet/test_data_bar_11.rb +167 -0
  133. data/test/worksheet/test_data_bar_12.rb +104 -0
  134. data/test/worksheet/test_write_data_validation_02.rb +27 -0
  135. metadata +135 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94c163c93be013a57cc4a4edba4cea1ac35f91ecbed56443d535fa1d6e1a464f
4
- data.tar.gz: 29fecf270f9b3382e0adae5f9f8ffd3b15ca97a84fc9da8bc24d0402de9a7ce7
3
+ metadata.gz: d1ecd38fb615885768458a04b082d759437fbaf7fb2e07900cc558d18e400e51
4
+ data.tar.gz: d1fa5e1696685c9bba199b4ee922c488144f5a2f852644e24fcedd38fed29035
5
5
  SHA512:
6
- metadata.gz: da03548ba5d54019f9a69b2aa6ca70042b4d27824d784996ebdd7109f8c54626609f007d099acffb8a0d09448d5fdd2ea49e491e729b2b075d2e142fd0b36dc7
7
- data.tar.gz: ba23f9b7be254784821b0bae59134bfa53a1cb2afa22e21576a054c718532f34753701d001d46f52871d770db0af4a6027705c22d28c18f658eb082b49172eeb
6
+ metadata.gz: 1162adaf9f347ef7f9e986b0596877edc9a4e059b1055e5913c576583017af41b78710c44252c2ced77b06dcdd818af269f3c98282e9bc767f211237e8313fac
7
+ data.tar.gz: cd4eb41156f364e4685487ae32876d8b35d7907f7f7068442fb22d2afc6a24217794bea5e571720d6db14b80b7c7368ac08502071d5290cc696cd80588901cdd
data/Changes CHANGED
@@ -1,5 +1,42 @@
1
1
  Change history of write_xlsx rubygem.
2
2
 
3
+ 2021-01-02 v0.97.0
4
+
5
+ Added Excel 2010 data bar features such as solid fills and control over
6
+ the display of negative values.
7
+
8
+ Added default formatting for hyperlinks if none is specified. The format
9
+ is the Excel hyperlink style so links change colour after they are
10
+ clicked.
11
+
12
+ Fixed missing plotarea formatting in pie/doughnut charts.
13
+
14
+ 2020-12-31 v0.96.0
15
+
16
+ Added icon sets to conditional formatting.
17
+
18
+ 2020-12-30 v0.95.0
19
+
20
+ Added workbook set_size() method.
21
+
22
+ 2020-12-30 v0.94.0
23
+
24
+ Added font support to chart tables.
25
+
26
+ 2020-12-30 v0.93.0
27
+
28
+ Added trendline properties: intercept, display_equation and
29
+ display_r_squared.
30
+
31
+ 2020-12-30 v0.92.0
32
+
33
+ Fix for insert_image issue when handling images with zero dpi.
34
+
35
+ 2020-12-30 v0.91.0
36
+
37
+ Add set_custom_property() workbook method to set custom document
38
+ properties.
39
+
3
40
  2020-12-28 v0.90.0
4
41
 
5
42
  Added worksheet_by_name() workbook method to retrieve a worksheet
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  gem to create a new file in the Excel 2007+ XLSX format, and you can use the
7
7
  same interface as writeexcel gem. write_xlsx is converted from Perl's module
8
- [Excel::Writer::XLSX-0.90](https://github.com/jmcnamara/excel-writer-xlsx) .
8
+ [Excel::Writer::XLSX-0.97](https://github.com/jmcnamara/excel-writer-xlsx) .
9
9
 
10
10
  ## Description
11
11
 
@@ -34,11 +34,6 @@
34
34
  worksheet.write(8, 0, '=IF(A5>3,"Yes", "No")')
35
35
 
36
36
  # Write a hyperlink
37
- hyperlink_format = workbook.add_format(
38
- :color => 'blue',
39
- :underline => 1
40
- )
41
-
42
- worksheet.write(10, 0, 'http://www.ruby-lang.org/', hyperlink_format)
37
+ worksheet.write(10, 0, 'http://www.ruby-lang.org/')
43
38
 
44
39
  workbook.close
@@ -26,12 +26,6 @@
26
26
  :color => '#006100'
27
27
  )
28
28
 
29
- # Blue fill with dark blue text.
30
- format3 = workbook.add_format(
31
- :bg_color => '#C6CEFF',
32
- :color => '#0000FF'
33
- )
34
-
35
29
  # Some sample data to run the conditional formatting against.
36
30
  data = [
37
31
  [ 34, 72, 38, 30, 75, 48, 75, 66, 84, 86 ],
@@ -226,19 +220,18 @@
226
220
  #
227
221
  caption = 'Examples of color scales and data bars. Default colors.'
228
222
 
229
- # Use different sample data for examples 7 and 8
230
- data7 = 1 .. 12
223
+ data = 1 .. 12
231
224
 
232
225
  worksheet7.write('A1', caption)
233
226
 
234
227
  worksheet7.write('B2', "2 Color Scale")
235
- worksheet7.write_col('B3', data7)
228
+ worksheet7.write_col('B3', data)
236
229
 
237
230
  worksheet7.write('D2', "3 Color Scale")
238
- worksheet7.write_col('D3', data7)
231
+ worksheet7.write_col('D3', data)
239
232
 
240
233
  worksheet7.write('F2', "Data Bars")
241
- worksheet7.write_col('F3', data7)
234
+ worksheet7.write_col('F3', data)
242
235
 
243
236
 
244
237
  worksheet7.conditional_formatting('B3:B14',
@@ -266,16 +259,18 @@
266
259
  #
267
260
  caption = 'Examples of color scales and data bars. Modified colors.'
268
261
 
262
+ data = 1..12
263
+
269
264
  worksheet8.write('A1', caption)
270
265
 
271
266
  worksheet8.write('B2', "2 Color Scale")
272
- worksheet8.write_col('B3', data7)
267
+ worksheet8.write_col('B3', data)
273
268
 
274
269
  worksheet8.write('D2', "3 Color Scale")
275
- worksheet8.write_col('D3', data7)
270
+ worksheet8.write_col('D3', data)
276
271
 
277
272
  worksheet8.write('F2', "Data Bars")
278
- worksheet8.write_col('F3', data7)
273
+ worksheet8.write_col('F3', data)
279
274
 
280
275
 
281
276
  worksheet8.conditional_formatting('B3:B14',
@@ -304,47 +299,79 @@
304
299
 
305
300
  ###############################################################################
306
301
  #
307
- # Example 9
302
+ # Example 9.
308
303
  #
309
- caption = 'Cells with values >= 100 are always in blue. ' +
310
- 'Otherwise, cells with values >= 50 are in light red ' +
311
- 'and values < 50 are in light green.'
304
+ caption = 'Examples of conditional formats with icon sets.'
305
+
306
+ data = [
307
+ [1, 2, 3],
308
+ [1, 2, 3],
309
+ [1, 2, 3],
310
+ [1, 2, 3],
311
+ [1, 2, 3, 4],
312
+ [1, 2, 3, 4, 5],
313
+ [1, 2, 3, 4, 5]
314
+ ]
312
315
 
313
- # Write the data.
314
316
  worksheet9.write('A1', caption)
315
317
  worksheet9.write_col('B3', data)
316
318
 
317
- # Write a conditional format over a range.
318
- # Use stopIfTrue to prevent previous formats from being used
319
- # if the conditions of this format are met.
320
- worksheet9.conditional_formatting('B3:K12',
321
- {
322
- :type => 'cell',
323
- :criteria => '>=',
324
- :value => 100,
325
- :format => format3,
326
- :stop_if_true => 1
327
- }
319
+ worksheet9.conditional_formatting(
320
+ 'B3:D3',
321
+ {
322
+ :type => 'icon_set',
323
+ :icon_style => '3_traffic_lights'
324
+ }
328
325
  )
329
326
 
330
- # Write another conditional format over the same range.
331
- worksheet9.conditional_formatting('B3:K12',
332
- {
333
- :type => 'cell',
334
- :criteria => '>=',
335
- :value => 50,
336
- :format => format1
337
- }
327
+ worksheet9.conditional_formatting(
328
+ 'B4:D4',
329
+ {
330
+ :type => 'icon_set',
331
+ :icon_style => '3_traffic_lights',
332
+ :reverse_icons => 1
333
+ }
338
334
  )
339
335
 
340
- # Write another conditional format over the same range.
341
- worksheet9.conditional_formatting('B3:K12',
342
- {
343
- :type => 'cell',
344
- :criteria => '<',
345
- :value => 50,
346
- :format => format2
347
- }
336
+ worksheet9.conditional_formatting(
337
+ 'B5:D5',
338
+ {
339
+ :type => 'icon_set',
340
+ :icon_style => '3_traffic_lights',
341
+ :icons_only => 1
342
+ }
343
+ )
344
+
345
+ worksheet9.conditional_formatting(
346
+ 'B6:D6',
347
+ {
348
+ :type => 'icon_set',
349
+ :icon_style => '3_arrows'
350
+ }
351
+ )
352
+
353
+ worksheet9.conditional_formatting(
354
+ 'B7:E8',
355
+ {
356
+ :type => 'icon_set',
357
+ :icon_style => '4_arrows'
358
+ }
359
+ )
360
+
361
+ worksheet9.conditional_formatting(
362
+ 'B8:F8',
363
+ {
364
+ :type => 'icon_set',
365
+ :icon_style => '5_arrows'
366
+ }
367
+ )
368
+
369
+ worksheet9.conditional_formatting(
370
+ 'B9:F9',
371
+ {
372
+ :type => 'icon_set',
373
+ :icon_style => '5_ratings'
374
+ }
348
375
  )
349
376
 
350
377
  workbook.close
@@ -27,11 +27,6 @@
27
27
  :align => 'vcenter'
28
28
  )
29
29
 
30
- hyperlink_format = workbook.add_format(
31
- :color => 'blue',
32
- :underline => 1
33
- )
34
-
35
30
  headings = ['Features of WriteXLSX', '']
36
31
  worksheet.write_row('A1', headings, heading)
37
32
 
@@ -81,7 +76,7 @@
81
76
  # Hyperlinks
82
77
  #
83
78
  worksheet.write('A9', "Hyperlinks")
84
- worksheet.write('B9', 'http://www.ruby-lang.org/', hyperlink_format)
79
+ worksheet.write('B9', 'http://www.ruby-lang.org/')
85
80
 
86
81
  #######################################################################
87
82
  #
@@ -99,4 +94,3 @@
99
94
  worksheet.write('A19', "Multiple worksheets")
100
95
 
101
96
  workbook.close
102
-
@@ -22,13 +22,6 @@
22
22
  worksheet.set_column('A:A', 30)
23
23
  worksheet.set_selection('B1')
24
24
 
25
-
26
- # Add the standard url link format.
27
- url_format = workbook.add_format(
28
- :color => 'blue',
29
- :underline => 1
30
- )
31
-
32
25
  # Add a sample format.
33
26
  red_format = workbook.add_format(
34
27
  :color => 'red',
@@ -45,11 +38,11 @@
45
38
 
46
39
 
47
40
  # Write some hyperlinks
48
- worksheet.write('A1', 'http://www.perl.com/', url_format)
49
- worksheet.write('A3', 'http://www.perl.com/', url_format, str)
50
- worksheet.write('A5', 'http://www.perl.com/', url_format, str, tip)
41
+ worksheet.write('A1', 'http://www.perl.com/')
42
+ worksheet.write('A3', 'http://www.perl.com/', nil, str)
43
+ worksheet.write('A5', 'http://www.perl.com/', nil, str, tip)
51
44
  worksheet.write('A7', 'http://www.perl.com/', red_format)
52
- worksheet.write('A9', 'mailto:jmcnamara@cpan.org', url_format, 'Mail me')
45
+ worksheet.write('A9', 'mailto:jmcnamara@cpan.org', nil, 'Mail me')
53
46
 
54
47
  # Write a URL that isn't a hyperlink
55
48
  worksheet.write_string('A11', 'http://www.perl.com/')
@@ -10,7 +10,7 @@ module Writexlsx
10
10
  class Table
11
11
  include Writexlsx::Utility
12
12
 
13
- attr_reader :horizontal, :vertical, :outline, :show_keys
13
+ attr_reader :horizontal, :vertical, :outline, :show_keys, :font
14
14
 
15
15
  def initialize(params = {})
16
16
  @horizontal, @vertical, @outline, @show_keys = true, true, true, false
@@ -18,14 +18,22 @@ def initialize(params = {})
18
18
  @vertical = params[:vertical] if params.has_key?(:vertical)
19
19
  @outline = params[:outline] if params.has_key?(:outline)
20
20
  @show_keys = params[:show_keys] if params.has_key?(:show_keys)
21
+ @font = convert_font_args(params[:font])
22
+ end
23
+
24
+ def palette=(palette)
25
+ @palette = palette
21
26
  end
22
27
 
23
28
  def write_d_table(writer)
24
- writer.tag_elements('c:dTable') do
25
- writer.empty_tag('c:showHorzBorder', attributes) if ptrue?(horizontal)
26
- writer.empty_tag('c:showVertBorder', attributes) if ptrue?(vertical)
27
- writer.empty_tag('c:showOutline', attributes) if ptrue?(outline)
28
- writer.empty_tag('c:showKeys', attributes) if ptrue?(show_keys)
29
+ @writer = writer
30
+ @writer.tag_elements('c:dTable') do
31
+ @writer.empty_tag('c:showHorzBorder', attributes) if ptrue?(horizontal)
32
+ @writer.empty_tag('c:showVertBorder', attributes) if ptrue?(vertical)
33
+ @writer.empty_tag('c:showOutline', attributes) if ptrue?(outline)
34
+ @writer.empty_tag('c:showKeys', attributes) if ptrue?(show_keys)
35
+ # Write the table font.
36
+ write_tx_pr(nil, font) if ptrue?(font)
29
37
  end
30
38
  end
31
39
 
@@ -264,6 +272,10 @@ def add_series(params)
264
272
  raise "Must specify ':categories' in add_series for this chart type"
265
273
  end
266
274
 
275
+ if @series.size == 255
276
+ raise "The maximum number of series that can be added to an Excel Chart is 255."
277
+ end
278
+
267
279
  @series << Series.new(self, params)
268
280
 
269
281
  # Set the secondary axis properties.
@@ -417,6 +429,7 @@ def set_size(params = {})
417
429
  #
418
430
  def set_table(params = {})
419
431
  @table = Table.new(params)
432
+ @table.palette = @palette
420
433
  end
421
434
 
422
435
  #
@@ -517,39 +530,6 @@ def write_bar_chart(params) # :nodoc:
517
530
  end
518
531
  end
519
532
 
520
- #
521
- # Convert user defined font values into private hash values.
522
- #
523
- def convert_font_args(params)
524
- return unless params
525
- font = params_to_font(params)
526
-
527
- # Convert font size units.
528
- font[:_size] *= 100 if font[:_size] && font[:_size] != 0
529
-
530
- # Convert rotation into 60,000ths of a degree.
531
- if ptrue?(font[:_rotation])
532
- font[:_rotation] = 60_000 * font[:_rotation].to_i
533
- end
534
-
535
- font
536
- end
537
-
538
- def params_to_font(params)
539
- {
540
- :_name => params[:name],
541
- :_color => params[:color],
542
- :_size => params[:size],
543
- :_bold => params[:bold],
544
- :_italic => params[:italic],
545
- :_underline => params[:underline],
546
- :_pitch_family => params[:pitch_family],
547
- :_charset => params[:charset],
548
- :_baseline => params[:baseline] || 0,
549
- :_rotation => params[:rotation]
550
- }
551
- end
552
-
553
533
  #
554
534
  # Switch name and name_formula parameters if required.
555
535
  #
@@ -672,20 +652,6 @@ def get_data_type(data) # :nodoc:
672
652
  'num'
673
653
  end
674
654
 
675
- #
676
- # Convert the user specified colour index or string to a rgb colour.
677
- #
678
- def color(color_code) # :nodoc:
679
- if color_code and color_code =~ /^#[0-9a-fA-F]{6}$/
680
- # Convert a HTML style #RRGGBB color.
681
- color_code.sub(/^#/, '').upcase
682
- else
683
- index = Format.color(color_code)
684
- raise "Unknown color '#{color_code}' used in chart formatting." unless index
685
- palette_color(index)
686
- end
687
- end
688
-
689
655
  #
690
656
  # Returns series which use the primary axes.
691
657
  #
@@ -723,38 +689,6 @@ def ids
723
689
  [id1, id2]
724
690
  end
725
691
 
726
- #
727
- # Get the font style attributes from a font hash.
728
- #
729
- def get_font_style_attributes(font)
730
- return [] unless font
731
-
732
- attributes = []
733
- attributes << ['sz', font[:_size]] if ptrue?(font[:_size])
734
- attributes << ['b', font[:_bold]] if font[:_bold]
735
- attributes << ['i', font[:_italic]] if font[:_italic]
736
- attributes << ['u', 'sng'] if font[:_underline]
737
-
738
- # Turn off baseline when testing fonts that don't have it.
739
- if font[:_baseline] != -1
740
- attributes << ['baseline', font[:_baseline]]
741
- end
742
- attributes
743
- end
744
-
745
- #
746
- # Get the font latin attributes from a font hash.
747
- #
748
- def get_font_latin_attributes(font)
749
- return [] unless font
750
-
751
- attributes = []
752
- attributes << ['typeface', font[:_name]] if ptrue?(font[:_name])
753
- attributes << ['pitchFamily', font[:_pitch_family]] if font[:_pitch_family]
754
- attributes << ['charset', font[:_charset]] if font[:_charset]
755
-
756
- attributes
757
- end
758
692
  #
759
693
  # Setup the default properties for a chart.
760
694
  #
@@ -1938,26 +1872,6 @@ def write_rich(title, horiz) # :nodoc:
1938
1872
  write_a_p_rich(title)
1939
1873
  end
1940
1874
  end
1941
-
1942
- #
1943
- # Write the <a:bodyPr> element.
1944
- #
1945
- def write_a_body_pr(rot, horiz = nil) # :nodoc:
1946
- rot = -5400000 if !rot && ptrue?(horiz)
1947
- attributes = []
1948
- attributes << ['rot', rot] if rot
1949
- attributes << ['vert', 'horz'] if ptrue?(horiz)
1950
-
1951
- @writer.empty_tag('a:bodyPr', attributes)
1952
- end
1953
-
1954
- #
1955
- # Write the <a:lstStyle> element.
1956
- #
1957
- def write_a_lst_style # :nodoc:
1958
- @writer.empty_tag('a:lstStyle')
1959
- end
1960
-
1961
1875
  #
1962
1876
  # Write the <a:p> element for rich string titles.
1963
1877
  #
@@ -1970,18 +1884,6 @@ def write_a_p_rich(title) # :nodoc:
1970
1884
  end
1971
1885
  end
1972
1886
 
1973
- #
1974
- # Write the <a:p> element for formula titles.
1975
- #
1976
- def write_a_p_formula(font = nil) # :nodoc:
1977
- @writer.tag_elements('a:p') do
1978
- # Write the a:pPr element.
1979
- write_a_p_pr_formula(font)
1980
- # Write the a:endParaRPr element.
1981
- write_a_end_para_rpr
1982
- end
1983
- end
1984
-
1985
1887
  #
1986
1888
  # Write the <a:pPr> element for rich string titles.
1987
1889
  #
@@ -1989,30 +1891,6 @@ def write_a_p_pr_rich(font) # :nodoc:
1989
1891
  @writer.tag_elements('a:pPr') { write_a_def_rpr(font) }
1990
1892
  end
1991
1893
 
1992
- #
1993
- # Write the <a:pPr> element for formula titles.
1994
- #
1995
- def write_a_p_pr_formula(font) # :nodoc:
1996
- @writer.tag_elements('a:pPr') { write_a_def_rpr(font) }
1997
- end
1998
-
1999
- #
2000
- # Write the <a:defRPr> element.
2001
- #
2002
- def write_a_def_rpr(font = nil) # :nodoc:
2003
- write_def_rpr_r_pr_common(
2004
- font,
2005
- get_font_style_attributes(font),
2006
- 'a:defRPr')
2007
- end
2008
-
2009
- #
2010
- # Write the <a:endParaRPr> element.
2011
- #
2012
- def write_a_end_para_rpr # :nodoc:
2013
- @writer.empty_tag('a:endParaRPr', [ ['lang', 'en-US'] ])
2014
- end
2015
-
2016
1894
  #
2017
1895
  # Write the <a:r> element.
2018
1896
  #
@@ -2036,24 +1914,6 @@ def write_a_r_pr(font) # :nodoc:
2036
1914
  write_def_rpr_r_pr_common(font, attributes, 'a:rPr')
2037
1915
  end
2038
1916
 
2039
- def write_def_rpr_r_pr_common(font, style_attributes, tag) # :nodoc:
2040
- latin_attributes = get_font_latin_attributes(font)
2041
- has_color = ptrue?(font) && ptrue?(font[:_color])
2042
-
2043
- if !latin_attributes.empty? || has_color
2044
- @writer.tag_elements(tag, style_attributes) do
2045
- if has_color
2046
- write_a_solid_fill(:color => font[:_color])
2047
- end
2048
- if !latin_attributes.empty?
2049
- write_a_latin(latin_attributes)
2050
- end
2051
- end
2052
- else
2053
- @writer.empty_tag(tag, style_attributes)
2054
- end
2055
- end
2056
-
2057
1917
  #
2058
1918
  # Write the <a:t> element.
2059
1919
  #
@@ -2061,24 +1921,6 @@ def write_a_t(title) # :nodoc:
2061
1921
  @writer.data_element('a:t', title)
2062
1922
  end
2063
1923
 
2064
- #
2065
- # Write the <c:txPr> element.
2066
- #
2067
- def write_tx_pr(horiz, font) # :nodoc:
2068
- rotation = nil
2069
- if font && font[:_rotation]
2070
- rotation = font[:_rotation]
2071
- end
2072
- @writer.tag_elements('c:txPr') do
2073
- # Write the a:bodyPr element.
2074
- write_a_body_pr(rotation, horiz)
2075
- # Write the a:lstStyle element.
2076
- write_a_lst_style
2077
- # Write the a:p element.
2078
- write_a_p_formula(font)
2079
- end
2080
- end
2081
-
2082
1924
  #
2083
1925
  # Write the <c:marker> element.
2084
1926
  #
@@ -2199,34 +2041,6 @@ def write_a_no_fill # :nodoc:
2199
2041
  @writer.empty_tag('a:noFill')
2200
2042
  end
2201
2043
 
2202
- #
2203
- # Write the <a:solidFill> element.
2204
- #
2205
- def write_a_solid_fill(fill) # :nodoc:
2206
- @writer.tag_elements('a:solidFill') do
2207
- if fill[:color]
2208
- # Write the a:srgbClr element.
2209
- write_a_srgb_clr(color(fill[:color]), fill[:transparency])
2210
- end
2211
- end
2212
- end
2213
-
2214
- #
2215
- # Write the <a:srgbClr> element.
2216
- #
2217
- def write_a_srgb_clr(color, transparency = nil) # :nodoc:
2218
- tag = 'a:srgbClr'
2219
- attributes = [ ['val', color] ]
2220
-
2221
- if ptrue?(transparency)
2222
- @writer.tag_elements(tag, attributes) do
2223
- write_a_alpha(transparency)
2224
- end
2225
- else
2226
- @writer.empty_tag(tag, attributes)
2227
- end
2228
- end
2229
-
2230
2044
  #
2231
2045
  # Write the <a:alpha> element.
2232
2046
  #
@@ -2264,6 +2078,20 @@ def write_trendline(trendline) # :nodoc:
2264
2078
  write_forward(trendline.forward)
2265
2079
  # Write the c:backward element.
2266
2080
  write_backward(trendline.backward)
2081
+ if trendline.intercept
2082
+ # Write the c:intercept element.
2083
+ write_intercept(trendline.intercept)
2084
+ end
2085
+ if trendline.display_r_squared
2086
+ # Write the c:dispRSqr element.
2087
+ write_disp_rsqr
2088
+ end
2089
+ if trendline.display_equation
2090
+ # Write the c:dispEq element.
2091
+ write_disp_eq
2092
+ # Write the c:trendlineLbl element.
2093
+ write_trendline_lbl
2094
+ end
2267
2095
  end
2268
2096
  end
2269
2097
 
@@ -2315,6 +2143,54 @@ def write_backward(val) # :nodoc:
2315
2143
  @writer.empty_tag('c:backward', [ ['val', val] ])
2316
2144
  end
2317
2145
 
2146
+ #
2147
+ # Write the <c:intercept> element.
2148
+ #
2149
+ def write_intercept(val)
2150
+ @writer.empty_tag('c:intercept', [ ['val', val] ])
2151
+ end
2152
+
2153
+ #
2154
+ # Write the <c:dispEq> element.
2155
+ #
2156
+ def write_disp_eq
2157
+ @writer.empty_tag('c:dispEq', [ ['val', 1] ])
2158
+ end
2159
+
2160
+ #
2161
+ # Write the <c:dispRSqr> element.
2162
+ #
2163
+ def write_disp_rsqr
2164
+ @writer.empty_tag('c:dispRSqr', [ ['val', 1] ])
2165
+ end
2166
+
2167
+ #
2168
+ # Write the <c:trendlineLbl> element.
2169
+ #
2170
+ def write_trendline_lbl
2171
+ @writer.tag_elements('c:trendlineLbl') do
2172
+ # Write the c:layout element.
2173
+ write_layout
2174
+ # Write the c:numFmt element.
2175
+ write_trendline_num_fmt
2176
+ end
2177
+ end
2178
+
2179
+ #
2180
+ # Write the <c:numFmt> element.
2181
+ #
2182
+ def write_trendline_num_fmt
2183
+ format_code = 'General'
2184
+ source_linked = 0
2185
+
2186
+ attributes = [
2187
+ ['formatCode', format_code],
2188
+ ['sourceLinked', source_linked]
2189
+ ]
2190
+
2191
+ @writer.empty_tag('c:numFmt', attributes)
2192
+ end
2193
+
2318
2194
  #
2319
2195
  # Write the <c:hiLowLines> element.
2320
2196
  #