axlsx 1.3.6 → 2.0.1

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 (87) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts_guide +19 -0
  3. data/CHANGELOG.md +8 -0
  4. data/README.md +54 -79
  5. data/Rakefile +0 -5
  6. data/examples/2010_comments.rb +17 -0
  7. data/examples/anchor_swapping.rb +28 -0
  8. data/examples/example.rb +16 -1
  9. data/examples/pivot_table.rb +2 -0
  10. data/examples/underline.rb +13 -0
  11. data/lib/axlsx/doc_props/core.rb +6 -1
  12. data/lib/axlsx/drawing/axes.rb +7 -3
  13. data/lib/axlsx/drawing/bar_3D_chart.rb +2 -2
  14. data/lib/axlsx/drawing/chart.rb +20 -4
  15. data/lib/axlsx/drawing/drawing.rb +2 -17
  16. data/lib/axlsx/drawing/graphic_frame.rb +3 -8
  17. data/lib/axlsx/drawing/hyperlink.rb +5 -12
  18. data/lib/axlsx/drawing/marker.rb +25 -5
  19. data/lib/axlsx/drawing/one_cell_anchor.rb +9 -0
  20. data/lib/axlsx/drawing/pic.rb +17 -23
  21. data/lib/axlsx/drawing/two_cell_anchor.rb +7 -27
  22. data/lib/axlsx/package.rb +36 -16
  23. data/lib/axlsx/rels/relationship.rb +73 -8
  24. data/lib/axlsx/rels/relationships.rb +8 -1
  25. data/lib/axlsx/stylesheet/color.rb +1 -1
  26. data/lib/axlsx/stylesheet/num_fmt.rb +2 -2
  27. data/lib/axlsx/stylesheet/styles.rb +5 -3
  28. data/lib/axlsx/util/serialized_attributes.rb +11 -8
  29. data/lib/axlsx/util/simple_typed_list.rb +34 -13
  30. data/lib/axlsx/util/validators.rb +7 -0
  31. data/lib/axlsx/version.rb +1 -1
  32. data/lib/axlsx/workbook/defined_name.rb +1 -1
  33. data/lib/axlsx/workbook/shared_strings_table.rb +12 -3
  34. data/lib/axlsx/workbook/workbook.rb +31 -8
  35. data/lib/axlsx/workbook/worksheet/break.rb +37 -0
  36. data/lib/axlsx/workbook/worksheet/cell.rb +5 -5
  37. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +1 -1
  38. data/lib/axlsx/workbook/worksheet/col_breaks.rb +35 -0
  39. data/lib/axlsx/workbook/worksheet/comment.rb +6 -5
  40. data/lib/axlsx/workbook/worksheet/comments.rb +3 -3
  41. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +1 -1
  42. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +6 -5
  43. data/lib/axlsx/workbook/worksheet/pivot_table.rb +32 -18
  44. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +4 -3
  45. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +1 -1
  46. data/lib/axlsx/workbook/worksheet/row.rb +1 -1
  47. data/lib/axlsx/workbook/worksheet/row_breaks.rb +33 -0
  48. data/lib/axlsx/workbook/worksheet/table.rb +3 -2
  49. data/lib/axlsx/workbook/worksheet/tables.rb +1 -1
  50. data/lib/axlsx/workbook/worksheet/worksheet.rb +61 -26
  51. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +6 -5
  52. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +3 -9
  53. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +5 -10
  54. data/lib/axlsx.rb +10 -2
  55. data/lib/schema/sml.xsd +4 -0
  56. data/test/axlsx.qcachegrind +2226 -0
  57. data/test/doc_props/tc_core.rb +7 -0
  58. data/test/drawing/tc_axes.rb +8 -0
  59. data/test/drawing/tc_bar_3D_chart.rb +6 -0
  60. data/test/drawing/tc_chart.rb +13 -0
  61. data/test/drawing/tc_drawing.rb +0 -5
  62. data/test/drawing/tc_graphic_frame.rb +4 -7
  63. data/test/drawing/tc_hyperlink.rb +0 -4
  64. data/test/drawing/tc_pic.rb +14 -3
  65. data/test/drawing/tc_two_cell_anchor.rb +3 -3
  66. data/test/profile.rb +7 -3
  67. data/test/rels/tc_relationship.rb +29 -11
  68. data/test/rels/tc_relationships.rb +12 -1
  69. data/test/stylesheet/tc_color.rb +6 -0
  70. data/test/stylesheet/tc_styles.rb +2 -2
  71. data/test/tc_helper.rb +1 -0
  72. data/test/tc_package.rb +31 -1
  73. data/test/util/tc_serialized_attributes.rb +19 -0
  74. data/test/workbook/tc_shared_strings_table.rb +6 -0
  75. data/test/workbook/tc_workbook.rb +23 -1
  76. data/test/workbook/worksheet/tc_break.rb +49 -0
  77. data/test/workbook/worksheet/tc_comment.rb +17 -6
  78. data/test/workbook/worksheet/tc_conditional_formatting.rb +2 -2
  79. data/test/workbook/worksheet/tc_date_time_converter.rb +3 -11
  80. data/test/workbook/worksheet/tc_pivot_table.rb +40 -22
  81. data/test/workbook/worksheet/tc_pivot_table_cache_definition.rb +9 -1
  82. data/test/workbook/worksheet/tc_sheet_view.rb +39 -39
  83. data/test/workbook/worksheet/tc_table.rb +2 -2
  84. data/test/workbook/worksheet/tc_worksheet.rb +39 -7
  85. data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +2 -11
  86. metadata +39 -11
  87. data/test/example.xlsx +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5ac3fa208421a6a360082bbc4b4365cc4109e89
4
- data.tar.gz: 45f0bc90cd313ae0042a63c868166177ab312184
3
+ metadata.gz: 36ce715dcecdf3de554b7683d87d35eccf159a81
4
+ data.tar.gz: d9550ff6639b90f612e45c0bf40f5a50ac88928e
5
5
  SHA512:
6
- metadata.gz: 1c9396cf2d1f3841902f4de9787a7f793fd98795bd21a0a77af383e38c29e8428ea9b8d507d7b9b24e4a25a548ffa561a92c7f9cfb48e59e87fc87ba33a9f390
7
- data.tar.gz: 7d48a79d7beb734a9f4d8abe3011df69c10a5fab90b284bbd0924742d66b70adbff793d4462248bafc682418aca7096668b2e49fecb0acb6841fd23823dd239e
6
+ metadata.gz: 9939c4e2c0bba3911171ae36441f61175d3b4604dfe878a125ac9b391c38c88430426a2c9660e2d1bafe0f7ae1c4a039a09d4410890978bad70509204a43e9d0
7
+ data.tar.gz: 0b58dc0cb79601febcc3782410e36225d2154c788f7dfe38e11d98a5845554ad0cd8a649656712e058f52e0ad884dafc9a3aa2a6379d5e1784585ca66f7f5b20
data/.yardopts_guide ADDED
@@ -0,0 +1,19 @@
1
+ -t guide
2
+ --title YARD
3
+ -o doc_guide
4
+ --exclude /server/templates/
5
+ --exclude /yard/rubygems/
6
+ --asset docs/images:images
7
+ -
8
+ docs/WhatsNew.md
9
+ docs/GettingStarted.md
10
+ docs/Overview.md
11
+ docs/CodeObjects.md
12
+ docs/Tags.md
13
+ docs/Parser.md
14
+ docs/Handlers.md
15
+ docs/Templates.md
16
+ docs/Glossary.md
17
+ ChangeLog
18
+ LICENSE
19
+ LEGAL
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  CHANGELOG
2
2
  ---------
3
+ - **November.25.12**:1.3.4
4
+ - Support for headers and footers for worksheets
5
+ - bug fix: Properly escape hyperlink urls
6
+ - Improvements in color_scale generation for conditional formatting
7
+ - Improvements in autowidth calculation.
8
+ - **November.8.12**:1.3.3
9
+ - Patched cell run styles for u and validation for family
10
+
3
11
  - **November.5.12**:1.3.2
4
12
  - MASSIVE REFACTORING
5
13
  - Patch for apostrophes in worksheet names
data/README.md CHANGED
@@ -21,25 +21,24 @@ 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.6
24
+ **Latest Version**: 2.0.1
25
25
 
26
- **Ruby Version**: 1.8.7 (soon to be depreciated!!!), 1.9.2, 1.9.3, 2.0.0
26
+ **Ruby Version**: 1.9.2, 1.9.3, 2.0.0
27
27
 
28
- **JRuby Version**: 1.6.7 1.8 and 1.9 modes
28
+ **JRuby Version**: 1.9 modes
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**: April 24th 2013
32
+ **Release Date**: September 12th 2013
33
33
 
34
34
  If you are working in rails, or with active record see:
35
35
  [acts_as_xlsx](http://github.com/randym/acts_as_xlsx)
36
36
 
37
37
  acts_as_xlsx is a simple ActiveRecord mixin that lets you generate a workbook with:
38
38
 
39
- ```ruby
40
- Posts.where(created_at > Time.now-30.days).to_xlsx
41
- ```
42
-
39
+ ```ruby
40
+ Posts.where(created_at > Time.now-30.days).to_xlsx
41
+ ```
43
42
 
44
43
  ** and **
45
44
 
@@ -71,46 +70,49 @@ With Axlsx you can create excel worksheets with charts, images (with links), aut
71
70
  Feature List
72
71
  ------------
73
72
 
74
- **1. Author xlsx documents: Axlsx is made to let you easily and quickly generate professional xlsx based reports that can be validated before serialization.
73
+ 1. Author xlsx documents: Axlsx is made to let you easily and quickly generate professional xlsx based reports that can be validated before serialization.
75
74
 
76
- **2. Generate 3D Pie, Line, Scatter and Bar Charts: With Axlsx chart generation and management is as easy as a few lines of code. You can build charts based off data in your worksheet or generate charts without any data in your sheet at all. Customize gridlines, label rotation and series colors as well.
75
+ 2. Generate 3D Pie, Line, Scatter and Bar Charts: With Axlsx chart generation and management is as easy as a few lines of code. You can build charts based off data in your worksheet or generate charts without any data in your sheet at all. Customize gridlines, label rotation and series colors as well.
77
76
 
78
- **3. Custom Styles: With guaranteed document validity, you can style borders, alignment, fills, fonts, and number formats in a single line of code. Those styles can be applied to an entire row, or a single cell anywhere in your workbook.
77
+ 3. Custom Styles: With guaranteed document validity, you can style borders, alignment, fills, fonts, and number formats in a single line of code. Those styles can be applied to an entire row, or a single cell anywhere in your workbook.
79
78
 
80
- **4. Automatic type support: Axlsx will automatically determine the type of data you are generating. In this release Float, Integer, String, Date, Time and Boolean types are automatically identified and serialized to your spreadsheet.
79
+ 4. Automatic type support: Axlsx will automatically determine the type of data you are generating. In this release Float, Integer, String, Date, Time and Boolean types are automatically identified and serialized to your spreadsheet.
81
80
 
82
- **5. Automatic and fixed column widths: Axlsx will automatically determine the appropriate width for your columns based on the content in the worksheet, or use any value you specify for the really funky stuff.
81
+ 5. Automatic and fixed column widths: Axlsx will automatically determine the appropriate width for your columns based on the content in the worksheet, or use any value you specify for the really funky stuff.
83
82
 
84
- **6. Support for automatically formatted 1904 and 1900 epochs configurable in the workbook.
83
+ 6. Support for automatically formatted 1904 and 1900 epochs configurable in the workbook.
85
84
 
86
- **7. Add jpg, gif and png images to worksheets with hyperlinks
85
+ 7. Add jpg, gif and png images to worksheets with hyperlinks
87
86
 
88
- **8. Reference cells in your worksheet with "A1" and "A1:D4" style references or from the workbook using "Sheet1!A3:B4" style references
87
+ 8. Reference cells in your worksheet with "A1" and "A1:D4" style references or from the workbook using "Sheet1!A3:B4" style references
89
88
 
90
- **9. Cell level style overrides for default and customized style objects
89
+ 9. Cell level style overrides for default and customized style objects
91
90
 
92
- **10. Support for formulas, merging, row and column outlining as well as
91
+ 10. Support for formulas, merging, row and column outlining as well as
93
92
  cell level input data validation.
94
93
 
95
- **12. Auto filtering tables with worksheet.auto_filter as well as support for Tables
94
+ 12. Auto filtering tables with worksheet.auto_filter as well as support for Tables
96
95
 
97
- **13. Export using shared strings or inline strings so we can inter-op with iWork Numbers (sans charts for now).
96
+ 13. Export using shared strings or inline strings so we can inter-op with iWork Numbers (sans charts for now).
98
97
 
99
- **14. Output to file or StringIO
98
+ 14. Output to file or StringIO
100
99
 
101
- **15. Support for page margins and print options
100
+ 15. Support for page margins and print options
102
101
 
103
- **16. Support for password and non password based sheet protection.
102
+ 16. Support for password and non password based sheet protection.
104
103
 
105
- **17. First stage interoperability support for GoogleDocs, LibreOffice,
104
+ 17. First stage interoperability support for GoogleDocs, LibreOffice,
106
105
  and Numbers
107
106
 
108
- **18. Support for defined names, which gives you repeated header rows for printing.
107
+ 18. Support for defined names, which gives you repeated header rows for printing.
108
+
109
+ 19. Data labels for charts as well as series color customization.
109
110
 
110
- **19. Data labels for charts as well as series color customization.
111
+ 20. Support for sheet headers and footers
111
112
 
112
- **20. Support for sheet headers and footers
113
+ 21. Pivot Tables
113
114
 
115
+ 22. Page Breaks
114
116
 
115
117
  Installing
116
118
  ----------
@@ -148,6 +150,7 @@ There is much, much more you can do with this gem. If you get stuck, grab me on
148
150
 
149
151
  #Documentation
150
152
  --------------
153
+
151
154
  This gem is 100% documented with YARD, an exceptional documentation library. To see documentation for this, and all the gems installed on your system use:
152
155
 
153
156
  gem install yard
@@ -156,10 +159,31 @@ This gem is 100% documented with YARD, an exceptional documentation library. To
156
159
 
157
160
  #Specs
158
161
  ------
162
+
159
163
  This gem has 100% test coverage using test/unit. To execute tests for this gem, simply run rake in the gem directory.
160
164
 
161
165
  #Change log
162
166
  ---------
167
+
168
+ - **September.12.13**:2.0.1
169
+ - Unpinned rubyzip version
170
+ - **September.12.13**:2.0.0
171
+ - DROPPED support for ruby 1.8.7
172
+ - Altered readme to link to contributors
173
+ - Lots of improvements to make charts and relations more stable.
174
+ - Patched color param mutation.
175
+ - Data sourced for pivot tables can now come from other sheets.
176
+ - Altered image file extension comparisons to be case insensitive.
177
+ - Added control character sanitization to shared strings.
178
+ - Added page breaks. see examples/example.rb for an example.
179
+ - Bugfix: single to dual cell anchors for images now swap properly so you can set the end_at position during instantiation, in a block or directly on the image.
180
+ - Improved how we convert date/time to include the UTC offset when provided.
181
+ - Pinned rubyzip to 0.9.9 for those who are not ready to go up. Please note that release 2.0.1 and on will be using the 1.n.n series of rubyzip
182
+ - Bugfix: transposition of cells for Worksheet#cols now supports
183
+ incongruent column counts.counts
184
+ - Added space preservation for cell text. This will allow whitespace
185
+ in cell text both when using shared strings and when serializing
186
+ directly to the cell.
163
187
  - **April.24.13**:1.3.6
164
188
  - Fixed LibreOffice/OpenOffice issue to properly apply colors to lines
165
189
  in charts.
@@ -180,13 +204,6 @@ This gem has 100% test coverage using test/unit. To execute tests for this gem,
180
204
  - Added support for descrete border edge styles
181
205
  - Improved validation of sheet names
182
206
  - Added support for formula value caching so that iOS and OSX preview can show the proper values. See Cell.add_row and the formula_values option.
183
- - **November.25.12**:1.3.4
184
- - Support for headers and footers for worksheets
185
- - bug fix: Properly escape hyperlink urls
186
- - Improvements in color_scale generation for conditional formatting
187
- - Improvements in autowidth calculation.
188
- - **November.8.12**:1.3.3
189
- - Patched cell run styles for u and validation for family
190
207
 
191
208
  Please see the {file:CHANGELOG.md} document for past release information.
192
209
 
@@ -227,55 +244,13 @@ p.serialize('simple.xlsx')
227
244
  #Thanks!
228
245
 
229
246
  Open source software is a community effort. None of this could have been
230
- done without the help of the people below.
231
-
232
- --------
233
- [ochko](https://github.com/ochko) - for performance fixes, kicking the crap out of axlsx and helping to maintain my general sanity.
234
-
235
- [kleine2](https://github.com/kleine2) - for generously donating in return for the image hyperlink feature.
236
-
237
- [ffmike](https://github.com/ffmike) - for knocking down an over restrictive i18n dependency, massive patience and great communication skills.
238
-
239
- [JonathanTron](https://github.com/JonathanTron) - for giving the gem some style, and making sure it applies.
240
-
241
- [JosephHalter](https://github.com/JosephHalter) - for making sure we arrive at the right time on the right date.
242
-
243
- [noniq](https://github.com/noniq) - for keeping true to the gem's style, and making sure what we put on paper does not get marginalized.
244
-
245
- [jurriaan](https://github.com/jurriaan) - for showing there is more than one way to skin a cat, and work with rows while you are at it.
246
-
247
- [joekain](https://github.com/joekain) - for keeping our references working even in the double digits!
248
-
249
- [moskrin](https://github.com/moskrin) - for keeping border creation on the edge.
250
-
251
- [scpike](https://github.com/scpike) - for keeping numbers fixed even when they are rational and a super clean implementation of conditional formatting.
252
-
253
- [janhuehne](https://github.com/janhuehne) - for working out the decoder ring and adding in cell level validation, and providing a support for window panes.
254
-
255
- [rfc2616](https://github.com/rfc2616) - for FINALLY working out the interop issues with google docs.
256
-
257
- [straydogstudio](https://github.com/straydogstudio) - For making an AWESOME axlsx templating gem for rails.
258
-
259
- [MitchellAJ](https://github.com/MitchellAJ) - For catching a bug in font_size calculations, finding some old code in an example and above all for reporting all of that brilliantly
260
-
261
- [ebenoist](https://github.com/ebenoist) - For taking control of control characters and keeping what is between the lines, between the lines.
262
-
263
- [adammathys](https://github.com/adammathys) - For getting our head in the
264
- air and our feet on the ground.
265
-
266
- [raiis](https://github.com/raiis) - For letting us specify diffent border styles on any edge.
267
-
268
- [alexrothenberg](https://github.com/alexrothenberg) - For an outstanding implementation of PivotTables, one of the last BIG chunks missing from the spec.
269
-
270
- [ball-hayden](https://github.com/ball-hayden) - For making sure we only get the right characters in our sheet names.
271
-
272
- [nibus](https://github.com/nibus) - For patching sheet name uniqueness.
247
+ done without the help of these awesome folks.
273
248
 
274
- [scambra](https://github.com/scambra) - for keeping our lines in line!
249
+ [contributors](https://github.com/randym/axlsx/graphs/contributors)
275
250
 
276
251
  #Copyright and License
277
252
  ----------
278
253
 
279
- Axlsx © 2011-2013 by [Randy Morgan](mailto:digial.ipseity@gmail.com).
254
+ Axlsx © 2011-2013 by [Randy Morgan](mailto:digial.ipseity@gmail.com).
280
255
 
281
256
  Axlsx is licensed under the MIT license. Please see the LICENSE document for more information.
data/Rakefile CHANGED
@@ -24,11 +24,6 @@ task :test do
24
24
  end
25
25
  end
26
26
 
27
- task :report do
28
- require 'cover_me'
29
- CoverMe.complete!
30
- end
31
-
32
27
  task :release => :build do
33
28
  system "gem push axlsx-#{Axlsx::VERSION}.gem"
34
29
  end
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby -w -s
2
+ # -*- coding: utf-8 -*-
3
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
4
+
5
+ #```ruby
6
+ require 'axlsx'
7
+ p = Axlsx::Package.new
8
+ p.workbook.add_worksheet(:name => 'Excel 2010 comments') do |sheet|
9
+ sheet.add_row ['Cell with visible comment']
10
+ sheet.add_row
11
+ sheet.add_row
12
+ sheet.add_row ['Cell with hidden comment']
13
+
14
+ sheet.add_comment :ref => 'A1', :author => 'XXX', :text => 'Visibile'
15
+ sheet.add_comment :ref => 'A4', :author => 'XXX', :text => 'Hidden', :visible => false
16
+ end
17
+ p.serialize('excel_2010_comment_test.xlsx')
@@ -0,0 +1,28 @@
1
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
+ require 'axlsx'
3
+ xls = Axlsx::Package.new
4
+ wb = xls.workbook
5
+ wb.add_worksheet do |ws|
6
+ img = File.expand_path('../image1.jpeg', __FILE__)
7
+ ws.add_image(:image_src => img) do |image|
8
+ image.start_at 2, 2
9
+ image.end_at 5, 5
10
+ end
11
+ end
12
+ wb.add_worksheet do |ws|
13
+ img = File.expand_path('../image1.jpeg', __FILE__)
14
+ ws.add_image(:image_src => img, :start_at => "B2") do |image|
15
+ image.width = 70
16
+ image.height = 50
17
+ end
18
+ end
19
+ wb.add_worksheet do |ws|
20
+ img = File.expand_path('../image1.jpeg', __FILE__)
21
+ ws.add_image(:image_src => img, :start_at => [1,1]) do |image|
22
+ image.end_at "E7"
23
+ end
24
+ end
25
+
26
+
27
+
28
+ xls.serialize 'anchor.xlsx'
data/examples/example.rb CHANGED
@@ -46,6 +46,8 @@ examples << :streaming
46
46
  examples << :shared_strings
47
47
  examples << :no_autowidth
48
48
  examples << :cached_formula
49
+ examples << :page_breaks
50
+
49
51
  p = Axlsx::Package.new
50
52
  wb = p.workbook
51
53
  #```
@@ -57,6 +59,7 @@ if examples.include? :basic
57
59
  wb.add_worksheet(:name => "Basic Worksheet") do |sheet|
58
60
  sheet.add_row ["First Column", "Second", "Third"]
59
61
  sheet.add_row [1, 2, 3]
62
+ sheet.add_row [' preserving whitespace']
60
63
  end
61
64
  end
62
65
  #```
@@ -309,6 +312,7 @@ end
309
312
 
310
313
  #```ruby
311
314
  if examples.include? :mbcs
315
+ wb.styles.fonts.first.name = 'Arial Unicode MS'
312
316
  wb.add_worksheet(:name => "日本語でのシート名") do |sheet|
313
317
  sheet.add_row ["日本語"]
314
318
  sheet.add_row ["华语/華語"]
@@ -640,6 +644,7 @@ if examples.include? :sheet_view
640
644
  end
641
645
  end
642
646
 
647
+
643
648
  # conditional formatting
644
649
  #
645
650
  if examples.include? :conditional_formatting
@@ -710,7 +715,17 @@ if examples.include? :conditional_formatting
710
715
  end
711
716
  end
712
717
 
713
- ##Validate and Serialize
718
+ # Page Breaks
719
+ if examples.include? :page_breaks
720
+ ws = wb.add_worksheet(:name => "page breaks") do |sheet|
721
+ sheet.add_row ["A"] * 10
722
+ sheet.add_row ["A"] * 10
723
+ sheet.add_page_break("B2")
724
+ sheet.sheet_view.view = :page_layout # so you can see the breaks!
725
+ end
726
+ end
727
+
728
+ #Validate and Serialize
714
729
 
715
730
  #```ruby
716
731
  # Serialize directly to file
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby -w -s
2
+ # -*- coding: utf-8 -*-
3
+
2
4
  $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
3
5
  require 'axlsx'
4
6
 
@@ -0,0 +1,13 @@
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
+ no_underline = s.add_style :sz => 10, :b => true, :u => false, :alignment => { :horizontal=> :right }
7
+ wb.add_worksheet(:name => 'wunderlinen') do |sheet|
8
+ sheet.add_row %w{a b c really?}, :style => no_underline
9
+ end
10
+ end
11
+ end
12
+ p.serialize 'no_underline.xlsx'
13
+
@@ -8,14 +8,19 @@ module Axlsx
8
8
 
9
9
  # Creates a new Core object.
10
10
  # @option options [String] creator
11
+ # @option options [Time] created
11
12
  def initialize(options={})
12
13
  @creator = options[:creator] || 'axlsx'
14
+ @created = options[:created]
13
15
  end
14
16
 
15
17
  # The author of the document. By default this is 'axlsx'
16
18
  # @return [String]
17
19
  attr_accessor :creator
18
20
 
21
+ # Creation time of the document. If nil, the current time will be used.
22
+ attr_accessor :created
23
+
19
24
  # serializes the core.xml document
20
25
  # @return [String]
21
26
  def to_xml_string(str = '')
@@ -24,7 +29,7 @@ module Axlsx
24
29
  str << 'xmlns:dcmitype="' << CORE_NS_DCMIT << '" xmlns:dcterms="' << CORE_NS_DCT << '" '
25
30
  str << 'xmlns:xsi="' << CORE_NS_XSI << '">'
26
31
  str << '<dc:creator>' << self.creator << '</dc:creator>'
27
- str << '<dcterms:created xsi:type="dcterms:W3CDTF">' << Time.now.strftime('%Y-%m-%dT%H:%M:%S') << 'Z</dcterms:created>'
32
+ str << '<dcterms:created xsi:type="dcterms:W3CDTF">' << (created || Time.now).strftime('%Y-%m-%dT%H:%M:%S') << 'Z</dcterms:created>'
28
33
  str << '<cp:revision>0</cp:revision>'
29
34
  str << '</cp:coreProperties>'
30
35
  end
@@ -5,9 +5,11 @@ module Axlsx
5
5
  class Axes
6
6
 
7
7
  # @param [Hash] options options used to generate axis each key
8
- # should be an axis name like :val_axix and its value should be the
9
- # class of the axis type to construct.
8
+ # should be an axis name like :val_axis and its value should be the
9
+ # class of the axis type to construct. The :cat_axis, if there is one,
10
+ # must come first (we assume a Ruby 1.9+ Hash or an OrderedHash).
10
11
  def initialize(options={})
12
+ raise(ArgumentError, "CatAxis must come first") if options.keys.include?(:cat_axis) && options.keys.first != :cat_axis
11
13
  options.each do |name, axis_class|
12
14
  add_axis(name, axis_class)
13
15
  end
@@ -28,7 +30,9 @@ module Axlsx
28
30
  # serialized. Otherwise, each axis is serialized in full.
29
31
  def to_xml_string(str = '', options = {})
30
32
  if options[:ids]
31
- axes.inject(str) { |string, axis| string << '<c:axId val="' << axis[1].id.to_s << '"/>' }
33
+ # CatAxis must come first in the XML (for Microsoft Excel at least)
34
+ sorted = axes.sort_by { |name, axis| axis.kind_of?(CatAxis) ? 0 : 1 }
35
+ sorted.inject(str) { |string, axis| string << '<c:axId val="' << axis[1].id.to_s << '"/>' }
32
36
  else
33
37
  axes.each { |axis| axis[1].to_xml_string(str) }
34
38
  end
@@ -142,10 +142,10 @@ module Axlsx
142
142
  end
143
143
 
144
144
  # A hash of axes used by this chart. Bar charts have a value and
145
- # category axes specified via axex[:val_axes] and axes[:cat_axis]
145
+ # category axes specified via axes[:val_axes] and axes[:cat_axis]
146
146
  # @return [Axes]
147
147
  def axes
148
- @axes ||= Axes.new(:val_axis => ValAxis, :cat_axis => CatAxis)
148
+ @axes ||= Axes.new(:cat_axis => CatAxis, :val_axis => ValAxis)
149
149
  end
150
150
  end
151
151
  end
@@ -20,6 +20,7 @@ module Axlsx
20
20
  @graphic_frame.anchor.drawing.worksheet.workbook.charts << self
21
21
  @series = SimpleTypedList.new Series
22
22
  @show_legend = true
23
+ @display_blanks_as = :gap
23
24
  @series_type = Series
24
25
  @title = Title.new
25
26
  parse_options options
@@ -70,10 +71,19 @@ module Axlsx
70
71
  # @return [Boolean]
71
72
  attr_reader :show_legend
72
73
 
73
- # returns a relationship object for the chart
74
- # @return [Axlsx::Relationship]
74
+ # How to display blank values
75
+ # Options are
76
+ # * gap: Display nothing
77
+ # * span: Not sure what this does
78
+ # * zero: Display as if the value were zero, not blank
79
+ # @return [Symbol]
80
+ # Default :gap (although this really should vary by chart type and grouping)
81
+ attr_reader :display_blanks_as
82
+
83
+ # The relationship object for this chart.
84
+ # @return [Relationship]
75
85
  def relationship
76
- Relationship.new(CHART_R, "../#{pn}")
86
+ Relationship.new(self, CHART_R, "../#{pn}")
77
87
  end
78
88
 
79
89
  # The index of this chart in the workbooks charts collection
@@ -105,6 +115,12 @@ module Axlsx
105
115
  # @return [Boolean]
106
116
  def show_legend=(v) Axlsx::validate_boolean(v); @show_legend = v; end
107
117
 
118
+ # How to display blank values
119
+ # @see display_blanks_as
120
+ # @param [Symbol] v
121
+ # @return [Symbol]
122
+ def display_blanks_as=(v) Axlsx::validate_display_blanks_as(v); @display_blanks_as = v; end
123
+
108
124
  # The style for the chart.
109
125
  # see ECMA Part 1 §21.2.2.196
110
126
  # @param [Integer] v must be between 1 and 48
@@ -157,7 +173,7 @@ module Axlsx
157
173
  str << '</c:legend>'
158
174
  end
159
175
  str << '<c:plotVisOnly val="1"/>'
160
- str << '<c:dispBlanksAs val="zero"/>'
176
+ str << '<c:dispBlanksAs val="' << display_blanks_as.to_s << '"/>'
161
177
  str << '<c:showDLblsOverMax val="1"/>'
162
178
  str << '</c:chart>'
163
179
  str << '<c:printSettings>'
@@ -82,7 +82,7 @@ module Axlsx
82
82
  TwoCellAnchor.new(self, options).add_pic(options)
83
83
  else
84
84
  OneCellAnchor.new(self, options)
85
- end
85
+ end
86
86
  @anchors.last.object
87
87
  end
88
88
 
@@ -121,12 +121,6 @@ module Axlsx
121
121
  @worksheet.workbook.drawings.index(self)
122
122
  end
123
123
 
124
- # The relation reference id for this drawing
125
- # @return [String]
126
- def rId
127
- "rId#{index+1}"
128
- end
129
-
130
124
  # The part name for this drawing
131
125
  # @return [String]
132
126
  def pn
@@ -140,15 +134,7 @@ module Axlsx
140
134
  "#{DRAWING_RELS_PN % (index+1)}"
141
135
  end
142
136
 
143
- # The index of a chart, image or hyperlink object this drawing contains
144
- def index_of(object)
145
- child_objects.index(object)
146
- end
147
-
148
-
149
- # An ordered list of objects this drawing holds
150
- # It is important that the objects are returned in the same order each time for
151
- # releationship indexing in the package
137
+ # A list of objects this drawing holds.
152
138
  # @return [Array]
153
139
  def child_objects
154
140
  charts + images + hyperlinks
@@ -168,7 +154,6 @@ module Axlsx
168
154
  def to_xml_string(str = '')
169
155
  str << '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
170
156
  str << '<xdr:wsDr xmlns:xdr="' << XML_NS_XDR << '" xmlns:a="' << XML_NS_A << '">'
171
-
172
157
  anchors.each { |anchor| anchor.to_xml_string(str) }
173
158
  str << '</xdr:wsDr>'
174
159
  end
@@ -22,15 +22,10 @@ module Axlsx
22
22
  @chart = chart_type.new(self, options)
23
23
  end
24
24
 
25
- # The relationship id for this graphic
25
+ # The relationship id for this graphic frame.
26
26
  # @return [String]
27
- #
28
- # NOTE: Discontinued. This should not be part of GraphicFrame.
29
- # The drawing object maintains relationships and needs to be queried to determine the relationship id of any given graphic data child object.
30
- #
31
27
  def rId
32
- warn('axlsx::DEPRECIATED: GraphicFrame#rId has been depreciated. relationship id is determed by the drawing object')
33
- "rId#{@anchor.index+1}"
28
+ @anchor.drawing.relationships.for(chart).Id
34
29
  end
35
30
 
36
31
  # Serializes the object
@@ -49,7 +44,7 @@ module Axlsx
49
44
  str << '</xdr:xfrm>'
50
45
  str << '<a:graphic>'
51
46
  str << '<a:graphicData uri="' << XML_NS_C << '">'
52
- str << '<c:chart xmlns:c="' << XML_NS_C << '" xmlns:r="' << XML_NS_R << '" r:id="rId' << (@anchor.drawing.index_of(@chart)+1).to_s << '"/>'
47
+ str << '<c:chart xmlns:c="' << XML_NS_C << '" xmlns:r="' << XML_NS_R << '" r:id="' << rId << '"/>'
53
48
  str << '</a:graphicData>'
54
49
  str << '</a:graphic>'
55
50
  str << '</xdr:graphicFrame>'
@@ -83,27 +83,20 @@ module Axlsx
83
83
  # @return [String]
84
84
  attr_accessor :tooltip
85
85
 
86
- # Returns a relationship object for this hyperlink
87
- # @return [Axlsx::Relationship]
86
+ # The relationship object for this hyperlink.
87
+ # @return [Relationship]
88
88
  def relationship
89
- Relationship.new(HYPERLINK_R, href, :target_mode => :External)
89
+ Relationship.new(self, HYPERLINK_R, href, :target_mode => :External)
90
90
  end
91
+
91
92
  # Serializes the object
92
93
  # @param [String] str
93
94
  # @return [String]
94
95
  def to_xml_string(str = '')
95
96
  str << '<a:hlinkClick '
96
- serialized_attributes str, {:'r:id' => "rId#{id}", :'xmlns:r' => XML_NS_R }
97
+ serialized_attributes str, {:'r:id' => relationship.Id, :'xmlns:r' => XML_NS_R }
97
98
  str << '/>'
98
99
  end
99
100
 
100
- private
101
-
102
- # The relational ID for this hyperlink
103
- # @return [Integer]
104
- def id
105
- @parent.anchor.drawing.index_of(self)+1
106
- end
107
-
108
101
  end
109
102
  end