axlsx 1.3.3 → 1.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. data/CHANGELOG.md +14 -0
  2. data/README.md +15 -15
  3. data/Rakefile +1 -1
  4. data/examples/example.rb +106 -35
  5. data/examples/wrap_text.rb +21 -0
  6. data/lib/axlsx/drawing/chart.rb +1 -1
  7. data/lib/axlsx/rels/relationship.rb +1 -1
  8. data/lib/axlsx/util/serialized_attributes.rb +32 -1
  9. data/lib/axlsx/util/validators.rb +1 -0
  10. data/lib/axlsx/version.rb +1 -1
  11. data/lib/axlsx/workbook/workbook.rb +1 -0
  12. data/lib/axlsx/workbook/worksheet/cell.rb +5 -2
  13. data/lib/axlsx/workbook/worksheet/cfvos.rb +0 -3
  14. data/lib/axlsx/workbook/worksheet/color_scale.rb +56 -16
  15. data/lib/axlsx/workbook/worksheet/data_bar.rb +42 -18
  16. data/lib/axlsx/workbook/worksheet/header_footer.rb +54 -0
  17. data/lib/axlsx/workbook/worksheet/worksheet.rb +29 -11
  18. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +1 -1
  19. data/test/benchmark.rb +1 -2
  20. data/test/example.xlsx +0 -0
  21. data/test/profile.rb +4 -13
  22. data/test/rels/tc_relationship.rb +5 -0
  23. data/test/tc_helper.rb +5 -1
  24. data/test/workbook/worksheet/tc_color_scale.rb +31 -2
  25. data/test/workbook/worksheet/tc_data_bar.rb +7 -0
  26. data/test/workbook/worksheet/tc_header_footer.rb +151 -0
  27. data/test/workbook/worksheet/tc_worksheet.rb +31 -6
  28. data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +1 -1
  29. metadata +11 -49
  30. data/examples/doc/_index.html +0 -88
  31. data/examples/doc/class_list.html +0 -53
  32. data/examples/doc/css/common.css +0 -1
  33. data/examples/doc/css/full_list.css +0 -57
  34. data/examples/doc/css/style.css +0 -328
  35. data/examples/doc/file_list.html +0 -52
  36. data/examples/doc/frames.html +0 -28
  37. data/examples/doc/index.html +0 -88
  38. data/examples/doc/js/app.js +0 -214
  39. data/examples/doc/js/full_list.js +0 -173
  40. data/examples/doc/js/jquery.js +0 -4
  41. data/examples/doc/method_list.html +0 -52
  42. data/examples/doc/top-level-namespace.html +0 -102
  43. data/examples/extractive.pdf +0 -0
  44. data/examples/finance.rb +0 -82
  45. data/examples/hyperlinks.rb +0 -23
  46. data/examples/image1.gif +0 -0
  47. data/examples/image1.jpg +0 -0
  48. data/examples/image1.png +0 -0
  49. data/examples/sample.png +0 -0
  50. data/examples/scraping_html.rb +0 -91
  51. data/examples/sheet_view.rb +0 -34
  52. data/examples/skydrive/axlsx.csv +0 -1
  53. data/examples/skydrive/axlsx.xlsx +0 -0
  54. data/examples/sprk2012/Screen Shot 2012-09-11 at 10.42.06 PM.png +0 -0
  55. data/examples/sprk2012/Screen Shot 2012-09-11 at 11.07.48 PM.png +0 -0
  56. data/examples/sprk2012/Screen Shot 2012-09-11 at 8.31.50 PM.png +0 -0
  57. data/examples/sprk2012/Screen Shot 2012-09-11 at 9.23.27 PM.png +0 -0
  58. data/examples/sprk2012/Screen Shot 2012-09-11 at 9.32.06 PM.png +0 -0
  59. data/examples/sprk2012/Screen Shot 2012-09-11 at 9.33.35 PM.png +0 -0
  60. data/examples/sprk2012/Screen Shot 2012-09-11 at 9.46.44 PM.png +0 -0
  61. data/examples/sprk2012/Screen Shot 2012-09-12 at 5.07.23 PM.png +0 -0
  62. data/examples/sprk2012/basics.rb +0 -11
  63. data/examples/sprk2012/basics.xlsx +0 -0
  64. data/examples/sprk2012/gravatar.jpeg +0 -0
  65. data/examples/sprk2012/hair_club.jpg +0 -0
  66. data/examples/sprk2012/images.rb +0 -9
  67. data/examples/sprk2012/images.xlsx +0 -0
  68. data/examples/sprk2012/line_chart.rb +0 -56
  69. data/examples/sprk2012/line_chart.xlsx +0 -0
  70. data/examples/sprk2012/sprk2012.key +0 -0
  71. data/examples/sprk2012/styles.rb +0 -20
  72. data/examples/sprk2012/styles.xlsx +0 -0
  73. data/examples/two_cell_anchor_image.rb +0 -11
@@ -1,5 +1,19 @@
1
1
  CHANGELOG
2
2
  ---------
3
+
4
+ - **September.30.12**: 1.3.1
5
+ - Improved control character handling
6
+ - Added stored auto filter values and date grouping items
7
+ - Improved support for autowidth when custom styles are applied
8
+ - Added support for table style info that lets you take advantage of
9
+ all the predefined table styles.
10
+ - Improved style management for fonts so they merge undefined values
11
+ from the initial master.
12
+ - **September.8.12**: 1.2.3
13
+ - enhance exponential float/bigdecimal values rendering as strings intead
14
+ of 'numbers' in excel.
15
+ - added support for :none option on chart axis labels
16
+ - added support for paper_size option on worksheet.page_setup
3
17
  - **August.27.12**: 1.2.2
4
18
  - minor patch for auto-filters
5
19
  - minor documentation improvements.
data/README.md CHANGED
@@ -21,7 +21,7 @@ appreciation for the gem, please don't hesitate to make a donation.
21
21
 
22
22
  **License**: MIT License
23
23
 
24
- **Latest Version**: 1.3.2
24
+ **Latest Version**: 1.3.4
25
25
 
26
26
  **Ruby Version**: 1.8.7, 1.9.2, 1.9.3
27
27
 
@@ -29,7 +29,7 @@ appreciation for the gem, please don't hesitate to make a donation.
29
29
 
30
30
  **Rubinius Version**: rubinius 2.0.0dev * lower versions may run, this gem always tests against head.
31
31
 
32
- **Release Date**: November 5th 2012
32
+ **Release Date**: November ??th 2012
33
33
 
34
34
  If you are working in rails, or with active record see:
35
35
  * http://github.com/randym/acts_as_xlsx
@@ -101,6 +101,9 @@ and Numbers
101
101
 
102
102
  **19. Data labels for charts as well as series color customization.
103
103
 
104
+ **20. Support for sheet headers and footers
105
+
106
+
104
107
  Installing
105
108
  ----------
106
109
 
@@ -149,6 +152,13 @@ This gem has 100% test coverage using test/unit. To execute tests for this gem,
149
152
 
150
153
  #Change log
151
154
  ---------
155
+ - **November.25.12**:1.3.4
156
+ - Support for headers and footers for worksheets
157
+ - bug fix: Properly escape hyperlink urls
158
+ - Improvements in color_scale generation for conditional formatting
159
+ - Improvements in autowidth calculation.
160
+ - **November.8.12**:1.3.3
161
+ - Patched cell run styles for u and validation for family
152
162
  - **November.5.12**:1.3.2
153
163
  - MASSIVE REFACTORING
154
164
  - Patch for apostrophes in worksheet names
@@ -157,19 +167,6 @@ This gem has 100% test coverage using test/unit. To execute tests for this gem,
157
167
  - added insert_worksheet so you can now add a worksheet to an
158
168
  arbitrary position in the worksheets list.
159
169
  - reduced memory consumption for package parts post serialization
160
- - **September.30.12**: 1.3.1
161
- - Improved control character handling
162
- - Added stored auto filter values and date grouping items
163
- - Improved support for autowidth when custom styles are applied
164
- - Added support for table style info that lets you take advantage of
165
- all the predefined table styles.
166
- - Improved style management for fonts so they merge undefined values
167
- from the initial master.
168
- - **September.8.12**: 1.2.3
169
- - enhance exponential float/bigdecimal values rendering as strings intead
170
- of 'numbers' in excel.
171
- - added support for :none option on chart axis labels
172
- - added support for paper_size option on worksheet.page_setup
173
170
 
174
171
  Please see the {file:CHANGELOG.md} document for past release information.
175
172
 
@@ -243,6 +240,9 @@ done without the help of the people below.
243
240
 
244
241
  [ebenoist](https://github.com/ebenoist) - For taking control of control characters and keeping what is between the lines, between the lines.
245
242
 
243
+ [adammathys](https://github.com/adammathys) - Fgr getting our head in the
244
+ air and our feet on the ground.
245
+
246
246
  #Copyright and License
247
247
  ----------
248
248
 
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ end
11
11
  task :gendoc do
12
12
  #puts 'yard doc generation disabled until JRuby build native extensions for redcarpet or yard removes the dependency.'
13
13
  system "yardoc"
14
- #system "yard stats --list-undoc"
14
+ system "yard stats --list-undoc"
15
15
  end
16
16
 
17
17
  task :test do
@@ -7,6 +7,7 @@ require 'axlsx'
7
7
  examples = []
8
8
  examples << :basic
9
9
  examples << :custom_styles
10
+ examples << :wrap_text
10
11
  examples << :cell_style_override
11
12
  examples << :custom_borders
12
13
  examples << :surrounding_border
@@ -22,6 +23,7 @@ examples << :auto_filter
22
23
  examples << :data_types
23
24
  examples << :hyperlinks
24
25
  examples << :number_currency_format
26
+ examples << :venezuela_currency
25
27
  examples << :bar_chart
26
28
  examples << :chart_gridlines
27
29
  examples << :pie_chart
@@ -33,8 +35,10 @@ examples << :hide_gridlines
33
35
  examples << :repeated_header
34
36
  examples << :defined_name
35
37
  examples << :printing
38
+ examples << :header_footer
36
39
  examples << :comments
37
40
  examples << :panes
41
+ examples << :sheet_view
38
42
  examples << :conditional_formatting
39
43
  examples << :streaming
40
44
  examples << :shared_strings
@@ -75,7 +79,26 @@ if examples.include? :custom_styles
75
79
  end
76
80
  end
77
81
  end
78
- #```
82
+
83
+
84
+ #```ruby
85
+ # A simple example of wrapping text. Seems this may not be working in Libre Office so here is an example for me to play with.
86
+ if examples.include? :wrap_text
87
+ wb.styles do |s|
88
+ wrap_text = s.add_style :fg_color=> "FFFFFF",
89
+ :b => true,
90
+ :bg_color => "004586",
91
+ :sz => 12,
92
+ :border => { :style => :thin, :color => "00" },
93
+ :alignment => { :horizontal => :center,
94
+ :vertical => :center ,
95
+ :wrap_text => true}
96
+ wb.add_worksheet(:name => 'wrap text') do |sheet|
97
+ sheet.add_row ['Torp, White and Cronin'], :style=>wrap_text
98
+ sheet.column_info.first.width = 5
99
+ end
100
+ end
101
+ end
79
102
 
80
103
  ##Styling Cell Overrides
81
104
 
@@ -128,7 +151,7 @@ if examples.include? :surrounding_border
128
151
  # LEARN IT! LIVE IT! LOVE IT!
129
152
  defaults = { :style => :thick, :color => "000000" }
130
153
  borders = Hash.new do |hash, key|
131
- hash[key] = wb.styles.add_style :border => defaults.merge( { :edges => key.to_s.split('_').map(&:to_sym) } )
154
+ hash[key] = wb.styles.add_style :border => defaults.merge( { :edges => key.to_s.split('_').map(&:to_sym) } )
132
155
  end
133
156
  top_row = [0, borders[:top_left], borders[:top], borders[:top], borders[:top_right]]
134
157
  middle_row = [0, borders[:left], nil, nil, borders[:right]]
@@ -146,11 +169,11 @@ if examples.include? :surrounding_border
146
169
  end
147
170
  end
148
171
 
149
- #```ruby
172
+ #```ruby
150
173
  # Hacking border styles
151
174
  if examples.include? :deep_custom_borders
152
175
  wb.styles do |s|
153
- top_bottom = s.add_style :border => { :style => :thick, :color =>"FFFF0000", :edges => [:top, :bottom] }
176
+ top_bottom = s.add_style :border => { :style => :thick, :color =>"FFFF0000", :edges => [:top, :bottom] }
154
177
  border = s.borders[s.cellXfs[top_bottom].borderId]
155
178
  # edit existing border parts
156
179
  border.prs.each do |part|
@@ -326,7 +349,7 @@ if examples.include? :hyperlinks
326
349
  wb.add_worksheet(:name => 'hyperlinks') do |sheet|
327
350
  # external references
328
351
  sheet.add_row ['axlsx']
329
- #sheet.add_hyperlink :location => 'https://github.com/randym/axlsx', :ref => sheet.rows.first.cells.first
352
+ sheet.add_hyperlink :location => 'https://github.com/randym/axlsx', :ref => sheet.rows.first.cells.first
330
353
  # internal references
331
354
  sheet.add_hyperlink :location => "'Next Sheet'!A1", :ref => 'A2', :target => :sheet
332
355
  sheet.add_row ['next sheet']
@@ -349,6 +372,15 @@ if examples.include? :number_currency_format
349
372
  sheet.add_row [1500, -122.34, 123456789, 594829], :style=> [currency, red_negative, comma, super_funk]
350
373
  end
351
374
  end
375
+
376
+ ## Venezuala currency
377
+ if examples.include? :venezuela_currency
378
+ wb.add_worksheet(:name => 'Venezuala_currency') do |sheet|
379
+ number = wb.styles.add_style :format_code => '#.##0\,00'
380
+ sheet.add_row [2.5] , :style => [number]
381
+ end
382
+ end
383
+
352
384
  ##Generating A Bar Chart
353
385
 
354
386
  #```ruby
@@ -481,7 +513,7 @@ if examples.include? :repeated_header
481
513
  wb.add_worksheet(:name => "repeated header") do |sheet|
482
514
  sheet.add_row %w(These Column Header Will Render On Every Printed Sheet)
483
515
  200.times { sheet.add_row %w(1 2 3 4 5 6 7 8) }
484
- wb.add_defined_name("'repeated header'!$1:$1", :local_sheet_id => sheet.index, :name => '_xlnm.Print_Titles')
516
+ wb.add_defined_name("'repeated header'!$1:$1", :local_sheet_id => sheet.index, :name => '_xlnm.Print_Titles')
485
517
  end
486
518
  end
487
519
 
@@ -516,7 +548,17 @@ if examples.include? :printing
516
548
  end
517
549
  #```
518
550
 
519
- ## Add Comments to your spreadsheet
551
+ ## Add headers and footers to a worksheet
552
+ #``` ruby
553
+ if examples.include? :header_footer
554
+ header_footer = {:different_first => false, :odd_header => '&L&F : &A&R&D &T', :odd_footer => '&C&Pof&N'}
555
+ wb.add_worksheet(:name => "header footer", :header_footer => header_footer) do |sheet|
556
+ sheet.add_row ["this sheet has a header and a footer"]
557
+ end
558
+ end
559
+ #```
560
+
561
+ ## Add Comments to your spreadsheet
520
562
  #``` ruby
521
563
  if examples.include? :comments
522
564
  wb.add_worksheet(:name => 'comments') do |sheet|
@@ -528,7 +570,7 @@ end
528
570
  ## Frozen/Split panes
529
571
  ## ``` ruby
530
572
  if examples.include? :panes
531
- wb.add_worksheet(:name => 'fixed headers') do |sheet|
573
+ wb.add_worksheet(:name => 'panes') do |sheet|
532
574
  sheet.add_row(['', (0..99).map { |i| "column header #{i}" }].flatten )
533
575
  100.times.with_index { |index| sheet << ["row header", (0..index).to_a].flatten }
534
576
  sheet.sheet_view.pane do |pane|
@@ -541,6 +583,33 @@ if examples.include? :panes
541
583
  end
542
584
  end
543
585
 
586
+ if examples.include? :sheet_view
587
+ ws = wb.add_worksheet(:name => 'SheetView - Split')
588
+ ws.sheet_view do |vs|
589
+ vs.pane do |pane|
590
+ pane.active_pane = :top_right
591
+ pane.state = :split
592
+ pane.x_split = 11080
593
+ pane.y_split = 5000
594
+ pane.top_left_cell = 'C44'
595
+ end
596
+
597
+ vs.add_selection(:top_left, { :active_cell => 'A2', :sqref => 'A2' })
598
+ vs.add_selection(:top_right, { :active_cell => 'I10', :sqref => 'I10' })
599
+ vs.add_selection(:bottom_left, { :active_cell => 'E55', :sqref => 'E55' })
600
+ vs.add_selection(:bottom_right, { :active_cell => 'I57', :sqref => 'I57' })
601
+ end
602
+
603
+ ws = wb.add_worksheet :name => "Sheetview - Frozen"
604
+ ws.sheet_view do |vs|
605
+ vs.pane do |pane|
606
+ pane.state = :frozen
607
+ pane.x_split = 3
608
+ pane.y_split = 4
609
+ end
610
+ end
611
+ end
612
+
544
613
  # conditional formatting
545
614
  #
546
615
  if examples.include? :conditional_formatting
@@ -551,59 +620,61 @@ if examples.include? :conditional_formatting
551
620
  profitable = wb.styles.add_style( :fg_color=>"FF428751",
552
621
  :type => :dxf)
553
622
 
554
- wb.add_worksheet(:name => "Conditional Cell Is") do |ws|
623
+ wb.add_worksheet(:name => "Conditional Cell Is") do |sheet|
555
624
 
556
- # Generate 20 rows of data
557
- ws.add_row ["Previous Year Quarterly Profits (JPY)"]
558
- ws.add_row ["Quarter", "Profit", "% of Total"]
625
+ # Generate 20 rosheet of data
626
+ sheet.add_row ["Previous Year Quarterly Profits (JPY)"]
627
+ sheet.add_row ["Quarter", "Profit", "% of Total"]
559
628
  offset = 3
560
- rows = 20
561
- offset.upto(rows + offset) do |i|
562
- ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent]
629
+ rosheet = 20
630
+ offset.upto(rosheet + offset) do |i|
631
+ sheet.add_row ["Q#{i}", 10000*((rosheet/2-i) * (rosheet/2-i)), "=100*B#{i}/SUM(B3:B#{rosheet+offset})"], :style=>[nil, money, percent]
563
632
  end
564
633
 
565
634
  # Apply conditional formatting to range B3:B100 in the worksheet
566
- ws.add_conditional_formatting("B3:B100", { :type => :cellIs, :operator => :greaterThan, :formula => "100000", :dxfId => profitable, :priority => 1 })
635
+ sheet.add_conditional_formatting("B3:B100", { :type => :cellIs, :operator => :greaterThan, :formula => "100000", :dxfId => profitable, :priority => 1 })
567
636
  end
568
637
 
569
- wb.add_worksheet(:name => "Conditional Color Scale") do |ws|
570
- ws.add_row ["Previous Year Quarterly Profits (JPY)"]
571
- ws.add_row ["Quarter", "Profit", "% of Total"]
638
+ wb.add_worksheet(:name => "Conditional Color Scale") do |sheet|
639
+ sheet.add_row ["Previous Year Quarterly Profits (JPY)"]
640
+ sheet.add_row ["Quarter", "Profit", "% of Total"]
572
641
  offset = 3
573
- rows = 20
574
- offset.upto(rows + offset) do |i|
575
- ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent]
642
+ rosheet = 20
643
+ offset.upto(rosheet + offset) do |i|
644
+ sheet.add_row ["Q#{i}", 10000*((rosheet/2-i) * (rosheet/2-i)), "=100*B#{i}/SUM(B3:B#{rosheet+offset})"], :style=>[nil, money, percent]
576
645
  end
577
- # Apply conditional formatting to range B3:B100 in the worksheet
578
- color_scale = Axlsx::ColorScale.new
579
- ws.add_conditional_formatting("B3:B100", { :type => :colorScale, :operator => :greaterThan, :formula => "100000", :dxfId => profitable, :priority => 1, :color_scale => color_scale })
646
+ # color scale has two_tone and three_tone class methods to setup the excel defaults (2011)
647
+ # alternatively, you can pass in {:type => [:min, :max, :percent], :val => [whatever], :color =>[Some RGB String] to create a customized color scale object
648
+
649
+ color_scale = Axlsx::ColorScale.three_tone
650
+ sheet.add_conditional_formatting("B3:B100", { :type => :colorScale, :operator => :greaterThan, :formula => "100000", :dxfId => profitable, :priority => 1, :color_scale => color_scale })
580
651
  end
581
652
 
582
653
 
583
- wb.add_worksheet(:name => "Conditional Data Bar") do |ws|
584
- ws.add_row ["Previous Year Quarterly Profits (JPY)"]
585
- ws.add_row ["Quarter", "Profit", "% of Total"]
654
+ wb.add_worksheet(:name => "Conditional Data Bar") do |sheet|
655
+ sheet.add_row ["Previous Year Quarterly Profits (JPY)"]
656
+ sheet.add_row ["Quarter", "Profit", "% of Total"]
586
657
  offset = 3
587
658
  rows = 20
588
659
  offset.upto(rows + offset) do |i|
589
- ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent]
660
+ sheet.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent]
590
661
  end
591
662
  # Apply conditional formatting to range B3:B100 in the worksheet
592
663
  data_bar = Axlsx::DataBar.new
593
- ws.add_conditional_formatting("B3:B100", { :type => :dataBar, :dxfId => profitable, :priority => 1, :data_bar => data_bar })
664
+ sheet.add_conditional_formatting("B3:B100", { :type => :dataBar, :dxfId => profitable, :priority => 1, :data_bar => data_bar })
594
665
  end
595
666
 
596
- wb.add_worksheet(:name => "Conditional Format Icon Set") do |ws|
597
- ws.add_row ["Previous Year Quarterly Profits (JPY)"]
598
- ws.add_row ["Quarter", "Profit", "% of Total"]
667
+ wb.add_worksheet(:name => "Conditional Format Icon Set") do |sheet|
668
+ sheet.add_row ["Previous Year Quarterly Profits (JPY)"]
669
+ sheet.add_row ["Quarter", "Profit", "% of Total"]
599
670
  offset = 3
600
671
  rows = 20
601
672
  offset.upto(rows + offset) do |i|
602
- ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent]
673
+ sheet.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent]
603
674
  end
604
675
  # Apply conditional formatting to range B3:B100 in the worksheet
605
676
  icon_set = Axlsx::IconSet.new
606
- ws.add_conditional_formatting("B3:B100", { :type => :iconSet, :dxfId => profitable, :priority => 1, :icon_set => icon_set })
677
+ sheet.add_conditional_formatting("B3:B100", { :type => :iconSet, :dxfId => profitable, :priority => 1, :icon_set => icon_set })
607
678
  end
608
679
  end
609
680
 
@@ -0,0 +1,21 @@
1
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
+ require 'axlsx'
3
+ p = Axlsx::Package.new
4
+ p.workbook do |wb|
5
+ wb.styles do |s|
6
+ wrap_text = s.add_style :fg_color=> "FFFFFF",
7
+ :b => true,
8
+ :bg_color => "004586",
9
+ :sz => 12,
10
+ :border => { :style => :thin, :color => "00" },
11
+ :alignment => { :horizontal => :center,
12
+ :vertical => :center ,
13
+ :wrap_text => true}
14
+ wb.add_worksheet(:name => 'wrap text') do |sheet|
15
+ sheet.add_row ['Torp, White and Cronin'], :style => wrap_text
16
+ # Forcing the column to be a bit narrow so we can see if the text wrap.
17
+ sheet.column_info.first.width = 5
18
+ end
19
+ end
20
+ end
21
+ p.serialize 'wrap_text.xlsx'
@@ -14,7 +14,7 @@ module Axlsx
14
14
  # @option options [Array|String|Cell] start_at The X, Y coordinates defining the top left corner of the chart.
15
15
  # @option options [Array|String|Cell] end_at The X, Y coordinates defining the bottom right corner of the chart.
16
16
  def initialize(frame, options={})
17
- @style = 18
17
+ @style = 18
18
18
  @view_3D = nil
19
19
  @graphic_frame=frame
20
20
  @graphic_frame.anchor.drawing.worksheet.workbook.charts << self
@@ -55,7 +55,7 @@ module Axlsx
55
55
  h = self.instance_values
56
56
  h[:Id] = 'rId' << rId.to_s
57
57
  str << '<Relationship '
58
- str << h.map { |key, value| '' << key.to_s << '="' << value.to_s << '"'}.join(' ')
58
+ str << h.map { |key, value| '' << key.to_s << '="' << Axlsx::coder.encode(value.to_s) << '"'}.join(' ')
59
59
  str << '/>'
60
60
  end
61
61
 
@@ -21,6 +21,16 @@ module Axlsx
21
21
  def xml_attributes
22
22
  @xml_attributes
23
23
  end
24
+
25
+ # This helper registers the attributes that will be formatted as elements.
26
+ def serializable_element_attributes(*symbols)
27
+ @xml_element_attributes = symbols
28
+ end
29
+
30
+ # attr reader for element attributes
31
+ def xml_element_attributes
32
+ @xml_element_attributes
33
+ end
24
34
  end
25
35
 
26
36
  # serializes the instance values of the defining object based on the
@@ -36,11 +46,32 @@ module Axlsx
36
46
  key_value_pairs.delete(key) unless self.class.xml_attributes.include?(key.to_sym)
37
47
  end
38
48
  key_value_pairs.merge! additional_attributes
39
-
40
49
  key_value_pairs.each do |key, value|
41
50
  str << "#{Axlsx.camel(key, false)}=\"#{value}\" "
42
51
  end
43
52
  str
44
53
  end
54
+
55
+
56
+ # serialized instance values at text nodes on a camelized element of the
57
+ # attribute name. You may pass in a block for evaluation against non nil
58
+ # values. We use an array for element attributes becuase misordering will
59
+ # break the xml and 1.8.7 does not support ordered hashes.
60
+ # @param [String] str The string instance to which serialized data is appended
61
+ # @param [Array] additional_attributes An array of additional attribute names.
62
+ # @param [Proc] block A which will be called with the value for each element.
63
+ # @return [String] The serialized output.
64
+ def serialized_element_attributes(str='', additional_attributes=[], &block)
65
+ attrs = self.class.xml_element_attributes + additional_attributes
66
+ values = instance_values
67
+ attrs.each do |attribute_name|
68
+ value = values[attribute_name.to_s]
69
+ next if value.nil?
70
+ value = yield value if block_given?
71
+ element_name = Axlsx.camel(attribute_name, false)
72
+ str << "<#{element_name}>#{value}</#{element_name}>"
73
+ end
74
+ str
75
+ end
45
76
  end
46
77
  end