axlsx 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/README.md +18 -7
  2. data/examples/conditional_formatting/example_conditional_formatting.rb +72 -0
  3. data/examples/conditional_formatting/getting_barred.rb +37 -0
  4. data/examples/conditional_formatting/hitting_the_high_notes.rb +37 -0
  5. data/examples/conditional_formatting/scaled_colors.rb +39 -0
  6. data/examples/conditional_formatting/stop_and_go.rb +37 -0
  7. data/examples/example.rb +6 -2
  8. data/examples/{real_example.rb → skydrive/real_example.rb} +0 -0
  9. data/lib/axlsx.rb +1 -1
  10. data/lib/axlsx/drawing/axis.rb +16 -0
  11. data/lib/axlsx/stylesheet/dxf.rb +79 -0
  12. data/lib/axlsx/stylesheet/font.rb +2 -1
  13. data/lib/axlsx/stylesheet/styles.rb +141 -50
  14. data/lib/axlsx/stylesheet/xf.rb +2 -0
  15. data/lib/axlsx/util/constants.rb +8 -0
  16. data/lib/axlsx/util/validators.rb +44 -0
  17. data/lib/axlsx/version.rb +1 -1
  18. data/lib/axlsx/workbook/workbook.rb +6 -0
  19. data/lib/axlsx/workbook/worksheet/cfvo.rb +62 -0
  20. data/lib/axlsx/workbook/worksheet/cfvo.rb~ +0 -0
  21. data/lib/axlsx/workbook/worksheet/color_scale.rb +76 -0
  22. data/lib/axlsx/workbook/worksheet/color_scale.rb~ +46 -0
  23. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +82 -0
  24. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +216 -0
  25. data/lib/axlsx/workbook/worksheet/data_bar.rb +97 -0
  26. data/lib/axlsx/workbook/worksheet/data_bar.rb~ +0 -0
  27. data/lib/axlsx/workbook/worksheet/icon_set.rb +83 -0
  28. data/lib/axlsx/workbook/worksheet/icon_set.rb~ +95 -0
  29. data/lib/axlsx/workbook/worksheet/row.rb +2 -0
  30. data/lib/axlsx/workbook/worksheet/worksheet.rb +25 -3
  31. data/test/drawing/tc_axis.rb +8 -0
  32. data/test/stylesheet/tc_dxf.rb +81 -0
  33. data/test/stylesheet/tc_styles.rb +148 -2
  34. data/test/workbook/worksheet/tc_cfvo.rb +31 -0
  35. data/test/workbook/worksheet/tc_cfvo.rb~ +20 -0
  36. data/test/workbook/worksheet/tc_color_scale.rb +29 -0
  37. data/test/workbook/worksheet/tc_color_scale.rb~ +0 -0
  38. data/test/workbook/worksheet/tc_conditional_formatting.rb +173 -0
  39. data/test/workbook/worksheet/tc_data_bar.rb +39 -0
  40. data/test/workbook/worksheet/tc_data_bar.rb~ +0 -0
  41. data/test/workbook/worksheet/tc_icon_set.rb +45 -0
  42. data/test/workbook/worksheet/tc_icon_set.rb~ +0 -0
  43. data/test/workbook/worksheet/tc_row.rb +9 -2
  44. metadata +45 -27
  45. data/examples/axlsx.xlsx +0 -0
  46. data/examples/example.xlsx +0 -0
  47. data/examples/example_streamed.xlsx +0 -0
  48. data/examples/no-use_autowidth.xlsx +0 -0
  49. data/examples/shared_strings_example.xlsx +0 -0
  50. data/lib/axlsx/util/doc/_index.html +0 -84
  51. data/lib/axlsx/util/doc/class_list.html +0 -47
  52. data/lib/axlsx/util/doc/css/common.css +0 -1
  53. data/lib/axlsx/util/doc/css/full_list.css +0 -55
  54. data/lib/axlsx/util/doc/css/style.css +0 -322
  55. data/lib/axlsx/util/doc/file_list.html +0 -46
  56. data/lib/axlsx/util/doc/frames.html +0 -13
  57. data/lib/axlsx/util/doc/index.html +0 -84
  58. data/lib/axlsx/util/doc/js/app.js +0 -205
  59. data/lib/axlsx/util/doc/js/full_list.js +0 -173
  60. data/lib/axlsx/util/doc/js/jquery.js +0 -16
  61. data/lib/axlsx/util/doc/method_list.html +0 -46
  62. data/lib/axlsx/util/doc/top-level-namespace.html +0 -95
data/README.md CHANGED
@@ -16,11 +16,13 @@ Axlsx: Office Open XML Spreadsheet Generation
16
16
 
17
17
  **License**: MIT License
18
18
 
19
- **Latest Version**: 1.1.1
19
+ **Latest Version**: 1.1.2
20
20
 
21
21
  **Ruby Version**: 1.8.7, 1.9.2, 1.9.3
22
22
 
23
- **JRuby Version**: 1.6.7
23
+ **JRuby Version**: 1.6.7 1.8 and 1.9 modes
24
+
25
+ **Rubinius Version**: rubinius 2.0.0dev * lower versions may run, this gem always tests against head.
24
26
 
25
27
  **Release Date**: April 18th 2012
26
28
 
@@ -283,6 +285,8 @@ wb.add_worksheet(:name => "Bar Chart") do |sheet|
283
285
  sheet.add_row [1, 2, 3]
284
286
  sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A4", :end_at => "F17") do |chart|
285
287
  chart.add_series :data => sheet["A3:C3"], :labels => sheet["A2:C2"], :title => sheet["A1"]
288
+ chart.valAxis.label_rotation = -45
289
+ chart.catAxis.label_rotation = 45
286
290
  end
287
291
  end
288
292
  ```
@@ -443,15 +447,14 @@ p.use_shared_strings = true
443
447
  p.serialize("shared_strings_example.xlsx")
444
448
  ```
445
449
 
446
-
447
450
  ##Disabling Autowidth
448
451
 
449
452
  ```ruby
450
453
  p = Axlsx::Package.new
451
454
  p.use_autowidth = false
452
455
  wb = p.workbook
453
- wb.add_worksheet(:name => "No Magick") do | sheet |
454
- sheet.add_row ['oh look! no autowidth - and no magick loaded in your process']
456
+ wb.add_worksheet(:name => "Manual Widths") do | sheet |
457
+ sheet.add_row ['oh look! no autowidth']
455
458
  end
456
459
  p.validate.each { |e| puts e.message }
457
460
  p.serialize("no-use_autowidth.xlsx")
@@ -471,6 +474,12 @@ This gem has 100% test coverage using test/unit. To execute tests for this gem,
471
474
 
472
475
  #Change log
473
476
  ---------
477
+ - ** April.25.12:*: 1.1.2 release
478
+ - Conditional Formatting completely implemented.
479
+ - refactoring / documentation for Style#add_style
480
+ - added in label rotation for chart axis labels
481
+ - bugfix to porperly assign style and type info to cells when only partial information is provided in the types/style option
482
+
474
483
  - ** April.18.12**: 1.1.1 release
475
484
  - bugfix for autowidth calculations across multiple rows
476
485
  - bugfix for dimension calculations with nil cells.
@@ -491,7 +500,7 @@ This gem has 100% test coverage using test/unit. To execute tests for this gem,
491
500
  - Support for tables added in - Note: Pre 2011 versions of Mac office do not support this feature and will warn.
492
501
  - Support for splatter charts added
493
502
  - Major (like 7x faster!) performance updates.
494
- - Gem now supports for JRuby 1.6.7, as well as expirimental support for Rubinius
503
+ - Gem now supports for JRuby 1.6.7, as well as experimental support for Rubinius
495
504
 
496
505
  Please see the {file:CHANGELOG.md} document for past release information.
497
506
 
@@ -515,8 +524,10 @@ Please see the {file:CHANGELOG.md} document for past release information.
515
524
 
516
525
  [moskrin](https://github.com/moskrin) - for keeping border creation on the edge.
517
526
 
527
+ [scpike](https://github.com/scpike) - for keeping numbers fixed even when they are rational and a super clean implementation of conditional formatting.
528
+
518
529
  #Copyright and License
519
530
  ----------
520
531
 
521
532
  Axlsx © 2011-2012 by [Randy Morgan](mailto:digial.ipseity@gmail.com). Axlsx is
522
- licensed under the MIT license. Please see the {file:LICENSE} document for more information.
533
+ licensed under the MIT license. Please see the LICENSE document for more information.
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env ruby -w -s
2
+ # -*- coding: utf-8 -*-
3
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
4
+ require 'axlsx'
5
+
6
+ p = Axlsx::Package.new
7
+ book = p.workbook
8
+
9
+ # define your regular styles
10
+ percent = book.styles.add_style(:format_code => "0.00%", :border => Axlsx::STYLE_THIN_BORDER)
11
+ money = book.styles.add_style(:format_code => '0,000', :border => Axlsx::STYLE_THIN_BORDER)
12
+
13
+ # define the style for conditional formatting
14
+ profitable = book.styles.add_style( :fg_color=>"FF428751",
15
+ :type => :dxf)
16
+
17
+ book.add_worksheet(:name => "Cell Is") do |ws|
18
+
19
+ # Generate 20 rows of data
20
+ ws.add_row ["Previous Year Quarterly Profits (JPY)"]
21
+ ws.add_row ["Quarter", "Profit", "% of Total"]
22
+ offset = 3
23
+ rows = 20
24
+ offset.upto(rows + offset) do |i|
25
+ ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent]
26
+ end
27
+
28
+ # Apply conditional formatting to range B3:B100 in the worksheet
29
+ ws.add_conditional_formatting("B3:B100", { :type => :cellIs, :operator => :greaterThan, :formula => "100000", :dxfId => profitable, :priority => 1 })
30
+ end
31
+
32
+ book.add_worksheet(:name => "Color Scale") do |ws|
33
+ ws.add_row ["Previous Year Quarterly Profits (JPY)"]
34
+ ws.add_row ["Quarter", "Profit", "% of Total"]
35
+ offset = 3
36
+ rows = 20
37
+ offset.upto(rows + offset) do |i|
38
+ ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent]
39
+ end
40
+ # Apply conditional formatting to range B3:B100 in the worksheet
41
+ color_scale = Axlsx::ColorScale.new
42
+ ws.add_conditional_formatting("B3:B100", { :type => :colorScale, :operator => :greaterThan, :formula => "100000", :dxfId => profitable, :priority => 1, :color_scale => color_scale })
43
+ end
44
+
45
+
46
+ book.add_worksheet(:name => "Data Bar") do |ws|
47
+ ws.add_row ["Previous Year Quarterly Profits (JPY)"]
48
+ ws.add_row ["Quarter", "Profit", "% of Total"]
49
+ offset = 3
50
+ rows = 20
51
+ offset.upto(rows + offset) do |i|
52
+ ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent]
53
+ end
54
+ # Apply conditional formatting to range B3:B100 in the worksheet
55
+ data_bar = Axlsx::DataBar.new
56
+ ws.add_conditional_formatting("B3:B100", { :type => :dataBar, :dxfId => profitable, :priority => 1, :data_bar => data_bar })
57
+ end
58
+
59
+ book.add_worksheet(:name => "Icon Set") do |ws|
60
+ ws.add_row ["Previous Year Quarterly Profits (JPY)"]
61
+ ws.add_row ["Quarter", "Profit", "% of Total"]
62
+ offset = 3
63
+ rows = 20
64
+ offset.upto(rows + offset) do |i|
65
+ ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent]
66
+ end
67
+ # Apply conditional formatting to range B3:B100 in the worksheet
68
+ icon_set = Axlsx::IconSet.new
69
+ ws.add_conditional_formatting("B3:B100", { :type => :iconSet, :dxfId => profitable, :priority => 1, :icon_set => icon_set })
70
+ end
71
+
72
+ p.serialize('example_conditional_formatting.xlsx')
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby -w -s
2
+ # -*- coding: utf-8 -*-
3
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
4
+ require 'axlsx'
5
+ p = Axlsx::Package.new
6
+ p.workbook do |wb|
7
+ # define your regular styles
8
+ styles = wb.styles
9
+ title = styles.add_style :sz => 15, :b => true, :u => true
10
+ default = styles.add_style :border => Axlsx::STYLE_THIN_BORDER
11
+ header = styles.add_style :bg_color => '00', :fg_color => 'FF', :b => true
12
+ money = styles.add_style :format_code => '#,###,##0', :border => Axlsx::STYLE_THIN_BORDER
13
+ percent = styles.add_style :num_fmt => Axlsx::NUM_FMT_PERCENT, :border => Axlsx::STYLE_THIN_BORDER
14
+
15
+ # define the style for conditional formatting - its the :dxf bit that counts!
16
+ profitable = styles.add_style :fg_color => 'FF428751', :sz => 12, :type => :dxf, :b => true
17
+
18
+ wb.add_worksheet(:name => 'Data Bar Conditional Formatting') do |ws|
19
+ ws.add_row ['A$$le Q1 Revenue Historical Analysis (USD)'], :style => title
20
+ ws.add_row
21
+ ws.add_row ['Quarter', 'Profit', '% of Total'], :style => header
22
+ ws.add_row ['Q1-2010', '15680000000', '=B4/SUM(B4:B7)'], :style => [default, money, percent]
23
+ ws.add_row ['Q1-2011', '26740000000', '=B5/SUM(B4:B7)'], :style => [default, money, percent]
24
+ ws.add_row ['Q1-2012', '46330000000', '=B6/SUM(B4:B7)'], :style => [default, money, percent]
25
+ ws.add_row ['Q1-2013(est)', '72230000000', '=B7/SUM(B4:B7)'], :style => [default, money, percent]
26
+
27
+ ws.merge_cells 'A1:C1'
28
+
29
+ # Apply conditional formatting to range B4:B7 in the worksheet
30
+ data_bar = Axlsx::DataBar.new
31
+ ws.add_conditional_formatting 'B4:B7', { :type => :dataBar,
32
+ :dxfId => profitable,
33
+ :priority => 1,
34
+ :data_bar => data_bar }
35
+ end
36
+ end
37
+ p.serialize 'getting_barred.xlsx'
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby -w -s
2
+ # -*- coding: utf-8 -*-
3
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
4
+ require 'axlsx'
5
+ p = Axlsx::Package.new
6
+ p.workbook do |wb|
7
+ # define your regular styles
8
+ styles = wb.styles
9
+ title = styles.add_style :sz => 15, :b => true, :u => true
10
+ default = styles.add_style :border => Axlsx::STYLE_THIN_BORDER
11
+ header = styles.add_style :bg_color => '00', :fg_color => 'FF', :b => true
12
+ money = styles.add_style :format_code => '###,###,###,##0', :border => Axlsx::STYLE_THIN_BORDER
13
+ percent = styles.add_style :num_fmt => Axlsx::NUM_FMT_PERCENT, :border => Axlsx::STYLE_THIN_BORDER
14
+
15
+ # define the style for conditional formatting - its the :dxf bit that counts!
16
+ profitable = styles.add_style :fg_color => 'FF428751', :sz => 12, :type => :dxf, :b => true
17
+
18
+ wb.add_worksheet(:name => 'The High Notes') do |ws|
19
+ ws.add_row ['A$$le Q1 Revenue Historical Analysis (USD)'], :style => title
20
+ ws.add_row
21
+ ws.add_row ['Quarter', 'Profit', '% of Total'], :style => header
22
+ ws.add_row ['Q1-2010', '15680000000', '=B4/SUM(B4:B7)'], :style => [default, money, percent]
23
+ ws.add_row ['Q1-2011', '26740000000', '=B5/SUM(B4:B7)'], :style => [default, money, percent]
24
+ ws.add_row ['Q1-2012', '46330000000', '=B6/SUM(B4:B7)'], :style => [default, money, percent]
25
+ ws.add_row ['Q1-2013(est)', '72230000000', '=B7/SUM(B4:B7)'], :style => [default, money, percent]
26
+
27
+ ws.merge_cells 'A1:C1'
28
+
29
+ # Apply conditional formatting to range B4:B7 in the worksheet
30
+ ws.add_conditional_formatting 'B4:B7', { :type => :cellIs,
31
+ :operator => :greaterThan,
32
+ :formula => '27000000000',
33
+ :dxfId => profitable,
34
+ :priority => 1 }
35
+ end
36
+ end
37
+ p.serialize 'the_high_notes.xlsx'
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby -w -s
2
+ # -*- coding: utf-8 -*-
3
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
4
+ require 'axlsx'
5
+ p = Axlsx::Package.new
6
+ p.workbook do |wb|
7
+ # define your regular styles
8
+ styles = wb.styles
9
+ title = styles.add_style :sz => 15, :b => true, :u => true
10
+ default = styles.add_style :border => Axlsx::STYLE_THIN_BORDER
11
+ header = styles.add_style :bg_color => '00', :fg_color => 'FF', :b => true
12
+ money = styles.add_style :format_code => '#,###,##0', :border => Axlsx::STYLE_THIN_BORDER
13
+ percent = styles.add_style :num_fmt => Axlsx::NUM_FMT_PERCENT, :border => Axlsx::STYLE_THIN_BORDER
14
+
15
+ # define the style for conditional formatting - its the :dxf bit that counts!
16
+ profitable = styles.add_style :fg_color => 'FF428751', :sz => 12, :type => :dxf, :b => true
17
+
18
+ wb.add_worksheet(:name => 'Scaled Colors') do |ws|
19
+ ws.add_row ['A$$le Q1 Revenue Historical Analysis (USD)'], :style => title
20
+ ws.add_row
21
+ ws.add_row ['Quarter', 'Profit', '% of Total'], :style => header
22
+ ws.add_row ['Q1-2010', '15680000000', '=B4/SUM(B4:B7)'], :style => [default, money, percent]
23
+ ws.add_row ['Q1-2011', '26740000000', '=B5/SUM(B4:B7)'], :style => [default, money, percent]
24
+ ws.add_row ['Q1-2012', '46330000000', '=B6/SUM(B4:B7)'], :style => [default, money, percent]
25
+ ws.add_row ['Q1-2013(est)', '72230000000', '=B7/SUM(B4:B7)'], :style => [default, money, percent]
26
+
27
+ ws.merge_cells 'A1:C1'
28
+
29
+ # Apply conditional formatting to range B4:B7 in the worksheet
30
+ color_scale = Axlsx::ColorScale.new
31
+ ws.add_conditional_formatting 'B4:B7', { :type => :colorScale,
32
+ :operator => :greaterThan,
33
+ :formula => '27000000000',
34
+ :dxfId => profitable,
35
+ :priority => 1,
36
+ :color_scale => color_scale }
37
+ end
38
+ end
39
+ p.serialize 'scaled_colors.xlsx'
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby -w -s
2
+ # -*- coding: utf-8 -*-
3
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
4
+ require 'axlsx'
5
+ p = Axlsx::Package.new
6
+ p.workbook do |wb|
7
+ # define your regular styles
8
+ styles = wb.styles
9
+ title = styles.add_style :sz => 15, :b => true, :u => true
10
+ default = styles.add_style :border => Axlsx::STYLE_THIN_BORDER
11
+ header = styles.add_style :bg_color => '00', :fg_color => 'FF', :b => true
12
+ money = styles.add_style :format_code => '#,###,##0', :border => Axlsx::STYLE_THIN_BORDER
13
+ percent = styles.add_style :num_fmt => Axlsx::NUM_FMT_PERCENT, :border => Axlsx::STYLE_THIN_BORDER
14
+
15
+ # define the style for conditional formatting - its the :dxf bit that counts!
16
+ profitable = styles.add_style :fg_color => 'FF428751', :sz => 12, :type => :dxf, :b => true
17
+
18
+ wb.add_worksheet(:name => 'Downtown traffic') do |ws|
19
+ ws.add_row ['A$$le Q1 Revenue Historical Analysis (USD)'], :style => title
20
+ ws.add_row
21
+ ws.add_row ['Quarter', 'Profit', '% of Total'], :style => header
22
+ ws.add_row ['Q1-2010', '15680000000', '=B4/SUM(B4:B7)'], :style => [default, money, percent]
23
+ ws.add_row ['Q1-2011', '26740000000', '=B5/SUM(B4:B7)'], :style => [default, money, percent]
24
+ ws.add_row ['Q1-2012', '46330000000', '=B6/SUM(B4:B7)'], :style => [default, money, percent]
25
+ ws.add_row ['Q1-2013(est)', '72230000000', '=B7/SUM(B4:B7)'], :style => [default, money, percent]
26
+
27
+ ws.merge_cells 'A1:C1'
28
+
29
+ # Apply conditional formatting to range B3:B7 in the worksheet
30
+ icon_set = Axlsx::IconSet.new
31
+ ws.add_conditional_formatting 'B3:B7', { :type => :iconSet,
32
+ :dxfId => profitable,
33
+ :priority => 1,
34
+ :icon_set => icon_set }
35
+ end
36
+ end
37
+ p.serialize 'stop_and_go.xlsx'
@@ -42,7 +42,7 @@ require 'date'
42
42
  wb.styles do |s|
43
43
  date = s.add_style(:format_code => "yyyy-mm-dd", :border => Axlsx::STYLE_THIN_BORDER)
44
44
  padded = s.add_style(:format_code => "00#", :border => Axlsx::STYLE_THIN_BORDER)
45
- percent = s.add_style(:format_code => "0000%", :border => Axlsx::STYLE_THIN_BORDER)
45
+ percent = s.add_style(:format_code => "###0%", :border => Axlsx::STYLE_THIN_BORDER)
46
46
  # wb.date1904 = true # Use the 1904 date system (Used by Excel for Mac < 2011)
47
47
  wb.add_worksheet(:name => "Formatting Data") do |sheet|
48
48
  sheet.add_row ["Custom Formatted Date", "Percent Formatted Float", "Padded Numbers"], :style => Axlsx::STYLE_THIN_BORDER
@@ -146,7 +146,9 @@ end
146
146
 
147
147
  wb.add_worksheet(:name => "Automatic cell types") do |sheet|
148
148
  sheet.add_row ["Date", "Time", "String", "Boolean", "Float", "Integer"]
149
- sheet.add_row [Date.today, Time.now, "value", true, 0.1, 1]
149
+ date_format = wb.styles.add_style :format_code => 'YYYY-MMM-DD'
150
+ time_format = wb.styles.add_style :format_code => 'HH:MM:SS'
151
+ sheet.add_row [Date.today, Time.now, "value", true, 0.1, 1], :style => [date_format, time_format]
150
152
  end
151
153
 
152
154
  ##Merging Cells.
@@ -170,6 +172,8 @@ wb.add_worksheet(:name => "Bar Chart") do |sheet|
170
172
  sheet.add_row [1, 2, 3]
171
173
  sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A4", :end_at => "F17") do |chart|
172
174
  chart.add_series :data => sheet["A3:C3"], :labels => sheet["A2:C2"], :title => sheet["A1"]
175
+ chart.valAxis.label_rotation = -45
176
+ chart.catAxis.label_rotation = 45
173
177
  end
174
178
  end
175
179
 
@@ -71,7 +71,7 @@ module Axlsx
71
71
  chars = []
72
72
  while index >= 26 do
73
73
  chars << ((index % 26) + 65).chr
74
- index = index / 26 - 1
74
+ index = (index / 26).to_i - 1
75
75
  end
76
76
  chars << (index + 65).chr
77
77
  chars.reverse.join
@@ -36,6 +36,10 @@ module Axlsx
36
36
  # @return [Symbol]
37
37
  attr_reader :crosses
38
38
 
39
+ # specifies how the degree of label rotation
40
+ # @return [Integer]
41
+ attr_reader :label_rotation
42
+
39
43
  # specifies if gridlines should be shown in the chart
40
44
  # @return [Boolean]
41
45
  attr_reader :gridlines
@@ -53,6 +57,7 @@ module Axlsx
53
57
  @axId = axId
54
58
  @crossAx = crossAx
55
59
  @format_code = "General"
60
+ @label_rotation = 0
56
61
  @scaling = Scaling.new(:orientation=>:minMax)
57
62
  self.axPos = :b
58
63
  self.tickLblPos = :nextTo
@@ -83,6 +88,15 @@ module Axlsx
83
88
  # must be one of [:autoZero, :min, :max]
84
89
  def crosses=(v) RestrictionValidator.validate "#{self.class}.crosses", [:autoZero, :min, :max], v; @crosses = v; end
85
90
 
91
+ # Specify the degree of label rotation to apply to labels
92
+ # default true
93
+ def label_rotation=(v)
94
+ Axlsx::validate_int(v)
95
+ adjusted = v.to_i * 60000
96
+ Axlsx::validate_angle(adjusted)
97
+ @label_rotation = adjusted
98
+ end
99
+
86
100
 
87
101
  # Serializes the object
88
102
  # @param [String] str
@@ -105,6 +119,8 @@ module Axlsx
105
119
  str << '<c:majorTickMark val="none"/>'
106
120
  str << '<c:minorTickMark val="none"/>'
107
121
  str << '<c:tickLblPos val="' << @tickLblPos.to_s << '"/>'
122
+ # some potential value in implementing this in full. Very detailed!
123
+ str << "<c:txPr><a:bodyPr rot='#{@label_rotation}'/><a:lstStyle/><a:p><a:pPr><a:defRPr/></a:pPr><a:endParaRPr/></a:p></c:txPr>"
108
124
  str << '<c:crossAx val="' << @crossAx.to_s << '"/>'
109
125
  str << '<c:crosses val="' << @crosses.to_s << '"/>'
110
126
  end
@@ -0,0 +1,79 @@
1
+ # encoding: UTF-8
2
+ module Axlsx
3
+ # The Dxf class defines an incremental formatting record for use in Styles. The recommended way to manage styles for your workbook is with Styles#add_style
4
+ # @see Styles#add_style
5
+ class Dxf
6
+ # The order in which the child elements is put in the XML seems to
7
+ # be important for Excel
8
+ CHILD_ELEMENTS = [:font, :numFmt, :fill, :alignment, :border, :protection]
9
+ #does not support extList (ExtensionList)
10
+
11
+ # The cell alignment for this style
12
+ # @return [CellAlignment]
13
+ # @see CellAlignment
14
+ attr_reader :alignment
15
+
16
+ # The cell protection for this style
17
+ # @return [CellProtection]
18
+ # @see CellProtection
19
+ attr_reader :protection
20
+
21
+ # the child NumFmt to be used to this style
22
+ # @return [NumFmt]
23
+ attr_reader :numFmt
24
+
25
+ # the child font to be used for this style
26
+ # @return [Font]
27
+ attr_reader :font
28
+
29
+ # the child fill to be used in this style
30
+ # @return [Fill]
31
+ attr_reader :fill
32
+
33
+ # the border to be used in this style
34
+ # @return [Border]
35
+ attr_reader :border
36
+
37
+ # Creates a new Xf object
38
+ # @option options [Border] border
39
+ # @option options [NumFmt] numFmt
40
+ # @option options [Fill] fill
41
+ # @option options [Font] font
42
+ # @option options [CellAlignment] alignment
43
+ # @option options [CellProtection] protection
44
+ def initialize(options={})
45
+ options.each do |o|
46
+ next if o[1].nil?
47
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
48
+ end
49
+ end
50
+
51
+ # @see Dxf#alignment
52
+ def alignment=(v) DataTypeValidator.validate "Dxf.alignment", CellAlignment, v; @alignment = v end
53
+ # @see protection
54
+ def protection=(v) DataTypeValidator.validate "Dxf.protection", CellProtection, v; @protection = v end
55
+ # @see numFmt
56
+ def numFmt=(v) DataTypeValidator.validate "Dxf.numFmt", NumFmt, v; @numFmt = v end
57
+ # @see font
58
+ def font=(v) DataTypeValidator.validate "Dxf.font", Font, v; @font = v end
59
+ # @see border
60
+ def border=(v) DataTypeValidator.validate "Dxf.border", Border, v; @border = v end
61
+ # @see fill
62
+ def fill=(v) DataTypeValidator.validate "Dxf.fill", Fill, v; @fill = v end
63
+
64
+ # Serializes the object
65
+ # @param [String] str
66
+ # @return [String]
67
+ def to_xml_string(str = '')
68
+ str << '<dxf>'
69
+ # Dxf elements have no attributes. All of the instance variables
70
+ # are child elements.
71
+ CHILD_ELEMENTS.each do |element|
72
+ self.send(element).to_xml_string(str) if self.send(element)
73
+ end
74
+ str << '</dxf>'
75
+ end
76
+
77
+ end
78
+
79
+ end