axlsx 1.2.3 → 1.3.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 (65) hide show
  1. data/.yardopts +3 -2
  2. data/CHANGELOG.md +34 -1
  3. data/README.md +26 -37
  4. data/Rakefile +1 -1
  5. data/examples/auto_filter.rb +16 -0
  6. data/examples/auto_filter.xlsx +0 -0
  7. data/examples/example.rb +3 -2
  8. data/examples/example.xlsx +0 -0
  9. data/examples/example_streamed.xlsx +0 -0
  10. data/examples/no-use_autowidth.xlsx +0 -0
  11. data/examples/shared_strings_example.xlsx +0 -0
  12. data/examples/skydrive/real_example.rb +6 -6
  13. data/examples/sprk2012/Screen Shot 2012-09-11 at 10.42.06 PM.png +0 -0
  14. data/examples/sprk2012/Screen Shot 2012-09-11 at 11.07.48 PM.png +0 -0
  15. data/examples/sprk2012/Screen Shot 2012-09-11 at 8.31.50 PM.png +0 -0
  16. data/examples/sprk2012/Screen Shot 2012-09-11 at 9.23.27 PM.png +0 -0
  17. data/examples/sprk2012/Screen Shot 2012-09-11 at 9.32.06 PM.png +0 -0
  18. data/examples/sprk2012/Screen Shot 2012-09-11 at 9.33.35 PM.png +0 -0
  19. data/examples/sprk2012/Screen Shot 2012-09-11 at 9.46.44 PM.png +0 -0
  20. data/examples/sprk2012/Screen Shot 2012-09-12 at 5.07.23 PM.png +0 -0
  21. data/examples/sprk2012/basics.rb +1 -0
  22. data/examples/sprk2012/basics.xlsx +0 -0
  23. data/examples/sprk2012/gravatar.jpeg +0 -0
  24. data/examples/sprk2012/hair_club.jpg +0 -0
  25. data/examples/sprk2012/images.rb +7 -12
  26. data/examples/sprk2012/images.xlsx +0 -0
  27. data/examples/sprk2012/line_chart.rb +56 -0
  28. data/examples/sprk2012/line_chart.xlsx +0 -0
  29. data/examples/sprk2012/sprk2012.key +0 -0
  30. data/examples/sprk2012/styles.rb +13 -12
  31. data/examples/sprk2012/styles.xlsx +0 -0
  32. data/examples/styles.rb +62 -0
  33. data/examples/styles.xlsx +0 -0
  34. data/lib/axlsx.rb +8 -1
  35. data/lib/axlsx/stylesheet/styles.rb +4 -0
  36. data/lib/axlsx/util/constants.rb +90 -5
  37. data/lib/axlsx/util/validators.rb +26 -8
  38. data/lib/axlsx/version.rb +2 -2
  39. data/lib/axlsx/workbook/workbook.rb +4 -1
  40. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +77 -0
  41. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +102 -0
  42. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +253 -0
  43. data/lib/axlsx/workbook/worksheet/cell.rb +9 -4
  44. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +1 -1
  45. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +47 -0
  46. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +49 -0
  47. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +87 -4
  48. data/lib/axlsx/workbook/worksheet/table.rb +8 -1
  49. data/lib/axlsx/workbook/worksheet/table_style_info.rb +68 -0
  50. data/lib/axlsx/workbook/worksheet/worksheet.rb +18 -3
  51. data/test/stylesheet/tc_styles.rb +13 -0
  52. data/test/util/tc_validators.rb +8 -1
  53. data/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +38 -0
  54. data/test/workbook/worksheet/auto_filter/tc_filter_column.rb +76 -0
  55. data/test/workbook/worksheet/auto_filter/tc_filters.rb +50 -0
  56. data/test/workbook/worksheet/tc_cell.rb +5 -0
  57. data/test/workbook/worksheet/tc_page_set_up_pr.rb +15 -0
  58. data/test/workbook/worksheet/tc_sheet_calc_pr.rb +18 -0
  59. data/test/workbook/worksheet/tc_sheet_pr.rb +27 -0
  60. data/test/workbook/worksheet/{table/tc_table.rb → tc_table.rb} +6 -1
  61. data/test/workbook/worksheet/tc_table_style_info.rb +53 -0
  62. data/test/workbook/worksheet/tc_worksheet.rb +17 -3
  63. metadata +45 -7
  64. data/examples/~$extractive.xlsx +0 -0
  65. data/lib/axlsx/workbook/worksheet/auto_filter.rb +0 -35
data/.yardopts CHANGED
@@ -4,5 +4,6 @@
4
4
  --readme README.md
5
5
  --markup markdown
6
6
  --markup-provider kramdown
7
- --files CHANGELOG.md, LICENSE
8
- --list-undoc
7
+ -
8
+ CHANGELOG.md
9
+ LICENSE
@@ -1,5 +1,39 @@
1
1
  CHANGELOG
2
2
  ---------
3
+ - **August.27.12**: 1.2.2
4
+ - minor patch for auto-filters
5
+ - minor documentation improvements.
6
+ - **August.12.12**: 1.2.1
7
+ - Add support for hyperlinks in worksheets
8
+ - Fix example that was using old style cell merging with concact.
9
+ - Fix bug that occurs when calculating the font_size for cells that use a user specified style which does not define sz
10
+ - **August.5.12**: 1.2.0
11
+ - rebuilt worksheet serialization to clean up the code base a bit.
12
+ - added data labels for charts
13
+ - added table header printing for each sheet via defined_name. This
14
+ means that when you print your worksheet, the header rows show for every page
15
+ - **July.??.12**: 1.1.9 release
16
+ - lots of code clean up for worksheet
17
+ - added in data labels for pie charts, line charts and bar charts.
18
+ - bugfix chard with data in a sheet that has a space in the name are
19
+ now auto updating formula based values
20
+ - **July.14.12**: 1.1.8 release
21
+ - added html entity encoding for sheet names. This allows you to use
22
+ characters like '<' and '&' in your sheet names.
23
+ - new - first round google docs interoperability
24
+ - added filter to strip out control characters from cell data.
25
+ - added in interop requirements so that charts are properly exported
26
+ to PDF from Libra Office
27
+ - various readability improvements and work standardizing attribute
28
+ names to snake_case. Aliases are provided for backward compatiblity
29
+ - **June.11.12**: 1.1.7 release
30
+ - fix chart rendering issue when label offset is specified as a
31
+ percentage in serialization and ensure that formula are not stored
32
+ in value caches
33
+ - fix bug that causes repair warnings when using a text only title reference.
34
+ - Add title property to axis so you can lable the x/y/series axis for
35
+ charts.
36
+ - Add sheet views with panes
3
37
  - **May.30.12**: 1.1.6 release
4
38
  - data protection with passwords for sheets
5
39
  - cell level input validators
@@ -10,7 +44,6 @@ CHANGELOG
10
44
  - added ph (phonetics) and s (style) attributes for row.
11
45
  - resolved all warnings generating from this gem.
12
46
  - improved comment relationship management for multiple comments
13
-
14
47
  - **May.13.12**: 1.1.5 release
15
48
  - MOAR print options! You can now specify paper size, orientation,
16
49
  fit to width, page margings and gridlines for printing.
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.2.3
24
+ **Latest Version**: 1.3.1
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**: September 8th 2012
32
+ **Release Date**: September 30th 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
@@ -149,45 +149,19 @@ This gem has 100% test coverage using test/unit. To execute tests for this gem,
149
149
 
150
150
  #Change log
151
151
  ---------
152
+ - **September.30.12**: 1.3.1
153
+ - Improved control character handling
154
+ - Added stored auto filter values and date grouping items
155
+ - Improved support for autowidth when custom styles are applied
156
+ - Added support for table style info that lets you take advantage of
157
+ all the predefined table styles.
158
+ - Improved style management for fonts so they merge undefined values
159
+ from the initial master.
152
160
  - **September.8.12**: 1.2.3
153
161
  - enhance exponential float/bigdecimal values rendering as strings intead
154
162
  of 'numbers' in excel.
155
163
  - added support for :none option on chart axis labels
156
164
  - added support for paper_size option on worksheet.page_setup
157
- - **August.27.12**: 1.2.2
158
- - minor patch for auto-filters
159
- - minor documentation improvements.
160
- - **August.12.12**: 1.2.1
161
- - Add support for hyperlinks in worksheets
162
- - Fix example that was using old style cell merging with concact.
163
- - Fix bug that occurs when calculating the font_size for cells that use a user specified style which does not define sz
164
- - **August.5.12**: 1.2.0
165
- - rebuilt worksheet serialization to clean up the code base a bit.
166
- - added data labels for charts
167
- - added table header printing for each sheet via defined_name. This
168
- means that when you print your worksheet, the header rows show for every page
169
- - **July.??.12**: 1.1.9 release
170
- - lots of code clean up for worksheet
171
- - added in data labels for pie charts, line charts and bar charts.
172
- - bugfix chard with data in a sheet that has a space in the name are
173
- now auto updating formula based values
174
- - **July.14.12**: 1.1.8 release
175
- - added html entity encoding for sheet names. This allows you to use
176
- characters like '<' and '&' in your sheet names.
177
- - new - first round google docs interoperability
178
- - added filter to strip out control characters from cell data.
179
- - added in interop requirements so that charts are properly exported
180
- to PDF from Libra Office
181
- - various readability improvements and work standardizing attribute
182
- names to snake_case. Aliases are provided for backward compatiblity
183
- - **June.11.12**: 1.1.7 release
184
- - fix chart rendering issue when label offset is specified as a
185
- percentage in serialization and ensure that formula are not stored
186
- in value caches
187
- - fix bug that causes repair warnings when using a text only title reference.
188
- - Add title property to axis so you can lable the x/y/series axis for
189
- charts.
190
- - Add sheet views with panes
191
165
 
192
166
  Please see the {file:CHANGELOG.md} document for past release information.
193
167
 
@@ -209,7 +183,19 @@ related to themes, which axlsx does not implement at this time.
209
183
  - border colors do not work
210
184
 
211
185
  3. Numbers
212
- - you must set 'use_shared_strings' to true
186
+ - you must set 'use_shared_strings' to true. This is most
187
+ conveniently done just before rendering by calling Package.use_shared_strings = true prior to serialization.
188
+
189
+ ```ruby
190
+ p = Axlsx::Package.new
191
+ p.workbook.add_worksheet(:name => "Basic Worksheet") do |sheet|
192
+ sheet.add_row ["First Column", "Second", "Third"]
193
+ sheet.add_row [1, 2, 3]
194
+ end
195
+ p.use_shared_strings = true
196
+ p.serialize('simple.xlsx')
197
+ ```
198
+
213
199
  - charts do not render
214
200
 
215
201
 
@@ -246,6 +232,9 @@ done without the help of the people below.
246
232
  [straydogstudio](https://github.com/straydocstudio) - For making an AWESOME axlsx templating gem for rails.
247
233
 
248
234
  [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
235
+
236
+ [ebenoist](https://github.com/ebenoist) - For taking control of control characters and keeping what is between the lines, between the lines.
237
+
249
238
  #Copyright and License
250
239
  ----------
251
240
 
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
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby -w -s
2
+ # -*- coding: utf-8 -*-
3
+
4
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
5
+ require 'axlsx'
6
+ Axlsx::Package.new do |p|
7
+ p.workbook.add_worksheet(:name => "Table") do |sheet|
8
+ sheet.add_row ["Build Matrix"]
9
+ sheet.add_row ["Build", "Duration", "Finished", "Rvm"]
10
+ sheet.add_row ["19.1", "1 min 32 sec", "about 10 hours ago", "1.8.7"]
11
+ sheet.add_row ["19.2", "1 min 28 sec", "about 10 hours ago", "1.9.2"]
12
+ sheet.add_row ["19.3", "1 min 35 sec", "about 10 hours ago", "1.9.3"]
13
+ sheet.auto_filter = 'A2:D5'
14
+ sheet.auto_filter.add_column 3, :filters, :filter_items => ['1.9.2']
15
+ end
16
+ end.serialize('auto_filter.xlsx')
Binary file
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby -w -s
2
2
  # -*- coding: utf-8 -*-
3
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
3
+ # $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
4
4
 
5
5
  #```ruby
6
6
  require 'axlsx'
@@ -190,6 +190,7 @@ wb.add_worksheet(:name => "Auto Filter") do |sheet|
190
190
  sheet.add_row ["19.2", "1 min 28 sec", "about 10 hours ago", "1.9.2"]
191
191
  sheet.add_row ["19.3", "1 min 35 sec", "about 10 hours ago", "1.9.3"]
192
192
  sheet.auto_filter = "A2:D5"
193
+ sheet.auto_filter.add_column 3, :filters, :filter_items => ['1.9.2', '1.8.7']
193
194
  end
194
195
  #```
195
196
 
@@ -315,7 +316,7 @@ wb.add_worksheet(:name => "Table") do |sheet|
315
316
  sheet.add_row ["19.1", "1 min 32 sec", "about 10 hours ago", "1.8.7"]
316
317
  sheet.add_row ["19.2", "1 min 28 sec", "about 10 hours ago", "1.9.2"]
317
318
  sheet.add_row ["19.3", "1 min 35 sec", "about 10 hours ago", "1.9.3"]
318
- sheet.add_table "A2:D5", :name => 'Build Matrix'
319
+ sheet.add_table "A2:D5", :name => 'Build Matrix', :style_info => { :name => "TableStyleMedium23" }
319
320
  end
320
321
  #```
321
322
 
Binary file
@@ -5,14 +5,14 @@ require 'axlsx'
5
5
  Axlsx::Package.new do |p|
6
6
  p.workbook do |wb|
7
7
  styles = wb.styles
8
- header = styles.add_style :bg_color => "DD", :sz => 16, :b => true, :alignment => {:horizontal => :center}
8
+ header = styles.add_style :bg_color => "DD", :sz => 16, :b => true, :alignment => {:horizontal => :center}
9
9
  tbl_header = styles.add_style :b => true, :alignment => { :horizontal => :center }
10
10
  ind_header = styles.add_style :bg_color => "FFDFDEDF", :b => true, :alignment => {:indent => 1}
11
- col_header = styles.add_style :bg_color => "FFDFDEDF", :b => true, :alignment => { :horizontal => :center }
12
- label = styles.add_style :alignment => { :indent => 1 }
13
- money = styles.add_style :num_fmt => 5
14
- t_label = styles.add_style :b => true, :bg_color => "FFDFDEDF"
15
- t_money = styles.add_style :b => true, :num_fmt => 5, :bg_color => "FFDFDEDF"
11
+ col_header = styles.add_style :bg_color => "FFDFDEDF", :b => true, :alignment => { :horizontal => :center }
12
+ label = styles.add_style :alignment => { :indent => 1 }
13
+ money = styles.add_style :num_fmt => 5
14
+ t_label = styles.add_style :b => true, :bg_color => "FFDFDEDF"
15
+ t_money = styles.add_style :b => true, :num_fmt => 5, :bg_color => "FFDFDEDF"
16
16
 
17
17
  wb.add_worksheet do |sheet|
18
18
  sheet.add_row
@@ -1,3 +1,4 @@
1
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib"
1
2
  require 'axlsx'
2
3
 
3
4
  package = Axlsx::Package.new
@@ -1,14 +1,9 @@
1
- require 'axlsx'
2
- package = Axlsx::Package.new
3
- workbook = package.workbook
1
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib"
4
2
 
5
- workbook.add_worksheet(:name => "Image with Hyperlink") do |sheet|
6
- img = File.expand_path('../image1.jpeg', __FILE__)
7
- sheet.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image|
8
- image.width=720
9
- image.height=666
10
- image.hyperlink.tooltip = "Labeled Link"
11
- image.start_at 2, 2
3
+ require 'axlsx'
4
+ package = Axlsx::Package.new do |package|
5
+ package.workbook.add_worksheet(:name => "imagex") do |sheet|
6
+ img_path = File.expand_path('../../image1.jpeg', __FILE__)
7
+ sheet.add_image(:image_src => img_path, :width => 720, :height => 666, :start_at => [2,2])
12
8
  end
13
- end
14
-
9
+ end.serialize 'images.xlsx'
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env ruby -w -s
2
+ # -*- coding: utf-8 -*-
3
+
4
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib"
5
+ require 'axlsx'
6
+
7
+ data = [ ['oil-bbl',9591.411671,8860.714604,8237.936509,7700.523067,7231.831842,6819.307902,6453.297235,6126.251755,5832.182748,5566.276532,5324.618706,5103.992757,4901.730597,4715.600022,4543.718862,4384.488699,4236.543136,4098.707009,3969.963937,3849.430276,3736.33405,3629.997786,3529.824424,3435.28568,3345.912388,3261.286414,3181.033882,3104.819438,3032.341401,2963.327615,2897.531915,2834.731083,2774.722219,2717.320479,2662.357097,2609.677666,2559.140642,2510.616021,2463.984182,2419.134871,2375.966292,2334.384311,2294.301748,2255.637735,2218.317165,2182.270173,2147.431696,2113.741056,2081.141602,2049.580377,2019.007821,1989.377502,1960.645871,1932.772042,1905.71759,1879.446367,1853.924338,1829.119424,1805.001366,1781.541597,1758.713122,1736.490414,1714.849315,1693.766943,1673.22161,1653.192744,1633.660817,1614.607284,1596.014514,1577.865741,1560.145009,1542.837121,1525.927597,1509.402632,1493.249056,1477.454298,1462.006352,1446.893746,1432.105512,1417.631159,1403.460647,1389.584361,1375.993094,1362.678018,1349.630672,1336.842938,1324.307026,1312.015455,1299.961043,1288.136885,1276.536347,1265.153047,1253.980847,1243.013838,1232.246332,1221.672852,1211.288119,1201.087047,1191.064732,1181.216443,1171.537618,1162.023853,1152.670896,1143.474642,1134.431125,1125.536513,1116.787101,1108.179309,1099.709672,1091.37484,1083.171571,1075.096725,1067.147265,1059.320247,1051.612821,1044.022223,1036.545778,1029.180889,1021.92504,1014.775789],
8
+
9
+ ['gas-mcf', 940970.153,836556.732,748476.939,673307.64,608520.158,552204.935,502892.3,459432.263,420911.806,386596.658,355889.491,328299.357,303418.988,280907.679,260478.232,241886.857,224925.287,209414.552,195200.029,182147.455,170139.707,159074.174,148860.596,139419.282,130679.626,122578.864,115061.035,108076.1,101579.19,95529.972,89892.104,84632.762,79722.24,75133.597,70842.349,66826.213,63064.865,59539.742,56233.86,53131.662,50218.869,47482.365,44910.082,42490.907,40214.588,38071.662,36053.382,34151.656,32358.989,30668.434,29073.545,27568.334,26147.237,24805.079,23537.041,22338.633,21205.67,20134.246,19120.717,18161.677,17253.941,16394.533,15580.663,14809.724,14079.269,13387.006,12730.786,12108.59,11518.524,10958.809,10427.774,9923.847,9445.55,8991.492,8560.364,8150.934,7762.041,7392.59,7041.551,6707.951,6390.874,6089.452,5802.871,5530.358,5271.185,5024.664,4790.145,4567.013,4354.687,4152.618,3960.286,3777.198,3602.889,3436.919,3278.87,3128.347,2984.976,2848.401,2718.287,2594.316,2476.184,2363.606,2256.309,2154.037,2056.545,1963.599,1874.982,1790.482,1709.903,1633.054,1559.758,1489.844,1423.151,1359.525,1298.821,1240.899,1185.628,1132.883,1082.544,1034.499],
10
+
11
+ ['water-bbl',940.97,836.557,748.477,673.308,608.52,552.205,502.892,459.432,420.912,386.597,355.889,328.299,303.419,280.908,260.478,241.887,224.925,209.415,195.2,182.147,170.14,159.074,148.861,139.419,130.68,122.579,115.061,108.076,101.579,95.53,89.892,84.633,79.722,75.134,70.842,66.826,63.065,59.54,56.234,53.132,50.219,47.482,44.91,42.491,40.215,38.072,36.053,34.152,32.359,30.668,29.074,27.568,26.147,24.805,23.537,22.339,21.206,20.134,19.121,18.162,17.254,16.395,15.581,14.81,14.079,13.387,12.731,12.109,11.519,10.959,10.428,9.924,9.446,8.991,8.56,8.151,7.762,7.393,7.042,6.708,6.391,6.089,5.803,5.53,5.271,5.025,4.79,4.567,4.355,4.153,3.96,3.777,3.603,3.437,3.279,3.128,2.985,2.848,2.718,2.594,2.476,2.364,2.256,2.154,2.057,1.964,1.875,1.79,1.71,1.633,1.56,1.49,1.423,1.36,1.299,1.241,1.186,1.133,1.083,1.034] ]
12
+
13
+ package = Axlsx::Package.new
14
+ package.workbook.add_worksheet(:name => 'volumes') do |ws|
15
+
16
+ # perspective, rotX and rotY flatten the 3D chart
17
+ # hPercent sets the chart height to 100%
18
+ chart_options = { :perspective => 0,
19
+ :hPercent => 100,
20
+ :rotX => 0,
21
+ :rotY => 0,
22
+ :start_at => "A4",
23
+ :end_at => 'M44',
24
+ :title => 'Monthly forcast for Type Curve Gas secondary - gross ngl' }
25
+
26
+ chart = ws.add_chart(Axlsx::Line3DChart, chart_options)
27
+
28
+ # Set up log based scaling and appropriate min/max values for Y axis
29
+ chart.valAxis.scaling.logBase = 10
30
+ chart.valAxis.scaling.min = 0.1
31
+ chart.valAxis.scaling.max = 10000000.0
32
+
33
+ # No poing in showing the series axis labels as the chart is flattened!
34
+ chart.serAxis.delete = true
35
+
36
+ # Knock the catAxis labels down to the forced min.
37
+ chart.catAxis.crosses = :min
38
+
39
+ # set up cat labels / markes to show every 12th item
40
+ chart.catAxis.tickLblSkip = 12
41
+ chart.catAxis.tickMarkSkip = 12
42
+
43
+ #rgb colors for our data series
44
+ colors = ['00FF00', 'FF0000', '0000FF']
45
+
46
+ data.each_with_index do |value, index|
47
+ ws.add_row value
48
+ chart.add_series :data => ws.rows.last.cells[(1..value.size-1)],
49
+ :labels => (0..value.size).map{ |i| i },
50
+ :title => ws.rows.last.cells.first,
51
+ :color => colors[index]
52
+ end
53
+ end
54
+
55
+ package.serialize 'line_chart.xlsx'
56
+
@@ -1,19 +1,20 @@
1
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib"
2
+
1
3
  require 'axlsx'
2
4
  package = Axlsx::Package.new
3
- workbook = package.workbook
4
-
5
- workbook.styles do |s|
6
-
7
- black_cell = s.add_style :bg_color => "00", :fg_color => "FF", :sz => 14, :alignment => { :horizontal=> :center }
8
- blue_cell = s.add_style :bg_color => "0000FF", :fg_color => "FF", :sz => 20, :alignment => { :horizontal=> :center }
9
-
10
- wb.add_worksheet(:name => "Styles") do |sheet|
5
+ package.workbook do |workbook|
6
+ workbook.styles do |s|
7
+ black_cell = s.add_style :bg_color => "00", :fg_color => "FF", :sz => 14, :alignment => { :horizontal=> :center }
8
+ blue_cell = s.add_style :bg_color => "0000FF", :fg_color => "FF", :sz => 20, :alignment => { :horizontal=> :center }
11
9
 
12
- # Applies the black_cell style to the first and third cell, and the blue_cell style to the second.
13
- sheet.add_row ["Text Autowidth", "Second", "Third"], :style => [black_cell, blue_cell, black_cell]
10
+ workbook.add_worksheet(:name => "Styles") do |sheet|
11
+ # Applies the black_cell style to the first and third cell, and the blue_cell style to the second.
12
+ sheet.add_row ["Text Autowidth", "Second", "Third"], :style => [black_cell, blue_cell, black_cell]
14
13
 
15
- # Applies the thin border to all three cells
16
- sheet.add_row [1, 2, 3], :style => Axlsx::STYLE_THIN_BORDER
14
+ # Applies the thin border to all three cells
15
+ sheet.add_row [1, 2, 3], :style => Axlsx::STYLE_THIN_BORDER
16
+ end
17
17
  end
18
18
  end
19
+ package.serialize 'styles.xlsx'
19
20
 
@@ -0,0 +1,62 @@
1
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
+ require 'axlsx'
3
+ require 'date'
4
+
5
+ p = Axlsx::Package.new
6
+ wb = p.workbook
7
+ wb.styles do |style|
8
+
9
+ # Date/Time Styles
10
+ #
11
+ # The most important thing to remember about OOXML styles is that they are
12
+ # exclusive. This means that each style must define all the components it
13
+ # requires to render the cell the way you want. A good example of this is
14
+ # changing the font size for a date. You cannot specify just the font size,
15
+ # you must also specify the number format or format code so that renders
16
+ # know how to display the serialized date float value
17
+ #
18
+ # The parts that make up a custom styles are:
19
+ #
20
+ # fonts(Font), fills(Fill), borders(Border) and number formats(NumFmt).
21
+ # Getting to know those classes will help you make the most out of custom
22
+ # styling. However axlsx certainly does not expect you to create all those
23
+ # objects manually.
24
+ #
25
+ # workbook.styles.add_style provides a helper method 'add_style' for defining
26
+ # styles in one go. The docs for that method are definitely worth a read.
27
+ # @see Style#add_style
28
+
29
+ # When no style is applied to a cell, axlsx will automatically apply date/time
30
+ # formatting to Date and Time objects for you. However, if you are defining
31
+ # custom styles, you define all aspects of the style you want to apply.
32
+ #
33
+ # An aside on styling and auto-width. Auto-width calculations do not
34
+ # currently take into account any style or formatting you have applied to the
35
+ # data in your cells as it would require the creation of a rendering engine,
36
+ # and frankly kill performance. If you are doing a lot of custom formatting,
37
+ # you are going to be better served by specifying fixed column widths.
38
+ #
39
+ # Let's look at an example:
40
+ #
41
+ # A style that only applies a font size
42
+ large_font = wb.styles.add_style :sz => 20
43
+
44
+ # A style that applies both a font size and a predefined number format.
45
+ # @see NumFmt
46
+ predefined_format = wb.styles.add_style :sz => 20, :num_fmt => 14
47
+
48
+ # A style that a applies a font size and a custom formatting code
49
+ custom_format = wb.styles.add_style :sz => 20, :format_code => 'yyyy-mm-dd'
50
+
51
+
52
+ wb.add_worksheet do |sheet|
53
+
54
+ # We then apply those styles positionally
55
+ sheet.add_row [123, "123", Time.now], style: [nil, large_font, predefined_format]
56
+ sheet.add_row [123, "123", Date.new(2012, 9, 14)], style: [large_font, nil, custom_format]
57
+ sheet.add_row [123, "123", Date.new(2000, 9, 12)] # This uses the axlsx default format_code (14)
58
+ end
59
+
60
+ end
61
+ p.serialize 'styles.xlsx'
62
+