axlsx 1.0.16 → 1.0.18

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 (91) hide show
  1. data/.yardopts +1 -0
  2. data/CHANGELOG.md +7 -0
  3. data/README.md +105 -46
  4. data/examples/example.rb +172 -142
  5. data/lib/axlsx/content_type/content_type.rb +4 -3
  6. data/lib/axlsx/content_type/default.rb +1 -0
  7. data/lib/axlsx/content_type/override.rb +1 -0
  8. data/lib/axlsx/doc_props/app.rb +1 -1
  9. data/lib/axlsx/doc_props/core.rb +1 -0
  10. data/lib/axlsx/drawing/axis.rb +1 -0
  11. data/lib/axlsx/drawing/bar_3D_chart.rb +1 -0
  12. data/lib/axlsx/drawing/bar_series.rb +1 -0
  13. data/lib/axlsx/drawing/cat_axis.rb +1 -0
  14. data/lib/axlsx/drawing/cat_axis_data.rb +1 -0
  15. data/lib/axlsx/drawing/chart.rb +4 -4
  16. data/lib/axlsx/drawing/drawing.rb +1 -0
  17. data/lib/axlsx/drawing/graphic_frame.rb +1 -0
  18. data/lib/axlsx/drawing/hyperlink.rb +1 -1
  19. data/lib/axlsx/drawing/line_3D_chart.rb +1 -0
  20. data/lib/axlsx/drawing/line_series.rb +1 -0
  21. data/lib/axlsx/drawing/marker.rb +1 -0
  22. data/lib/axlsx/drawing/one_cell_anchor.rb +1 -0
  23. data/lib/axlsx/drawing/pic.rb +2 -1
  24. data/lib/axlsx/drawing/picture_locking.rb +1 -0
  25. data/lib/axlsx/drawing/pie_3D_chart.rb +1 -0
  26. data/lib/axlsx/drawing/pie_series.rb +1 -0
  27. data/lib/axlsx/drawing/scaling.rb +1 -0
  28. data/lib/axlsx/drawing/ser_axis.rb +1 -0
  29. data/lib/axlsx/drawing/series.rb +1 -0
  30. data/lib/axlsx/drawing/series_title.rb +1 -0
  31. data/lib/axlsx/drawing/title.rb +1 -0
  32. data/lib/axlsx/drawing/two_cell_anchor.rb +1 -0
  33. data/lib/axlsx/drawing/val_axis.rb +1 -0
  34. data/lib/axlsx/drawing/val_axis_data.rb +1 -0
  35. data/lib/axlsx/drawing/view_3D.rb +1 -0
  36. data/lib/axlsx/package.rb +86 -38
  37. data/lib/axlsx/rels/relationship.rb +4 -3
  38. data/lib/axlsx/rels/relationships.rb +1 -0
  39. data/lib/axlsx/stylesheet/border.rb +1 -0
  40. data/lib/axlsx/stylesheet/border_pr.rb +1 -0
  41. data/lib/axlsx/stylesheet/cell_alignment.rb +1 -0
  42. data/lib/axlsx/stylesheet/cell_protection.rb +1 -0
  43. data/lib/axlsx/stylesheet/cell_style.rb +1 -0
  44. data/lib/axlsx/stylesheet/color.rb +1 -0
  45. data/lib/axlsx/stylesheet/fill.rb +1 -0
  46. data/lib/axlsx/stylesheet/font.rb +8 -0
  47. data/lib/axlsx/stylesheet/gradient_fill.rb +1 -1
  48. data/lib/axlsx/stylesheet/gradient_stop.rb +1 -1
  49. data/lib/axlsx/stylesheet/num_fmt.rb +1 -0
  50. data/lib/axlsx/stylesheet/pattern_fill.rb +1 -0
  51. data/lib/axlsx/stylesheet/styles.rb +12 -9
  52. data/lib/axlsx/stylesheet/table_style.rb +1 -0
  53. data/lib/axlsx/stylesheet/table_style_element.rb +1 -0
  54. data/lib/axlsx/stylesheet/table_styles.rb +1 -0
  55. data/lib/axlsx/stylesheet/xf.rb +1 -0
  56. data/lib/axlsx/util/cbf.rb +1 -0
  57. data/lib/axlsx/util/constants.rb +23 -14
  58. data/lib/axlsx/util/ms_off_crypto.rb +1 -1
  59. data/lib/axlsx/util/parser.rb +1 -0
  60. data/lib/axlsx/util/simple_typed_list.rb +2 -1
  61. data/lib/axlsx/util/storage.rb +1 -0
  62. data/lib/axlsx/util/validators.rb +11 -2
  63. data/lib/axlsx/version.rb +2 -1
  64. data/lib/axlsx/workbook/shared_strings_table.rb +71 -0
  65. data/lib/axlsx/workbook/shared_strings_table.rb~ +69 -0
  66. data/lib/axlsx/workbook/workbook.rb +47 -25
  67. data/lib/axlsx/workbook/worksheet/cell.rb +131 -78
  68. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +29 -0
  69. data/lib/axlsx/workbook/worksheet/page_margins.rb +94 -0
  70. data/lib/axlsx/workbook/worksheet/row.rb +44 -12
  71. data/lib/axlsx/workbook/worksheet/shared_strings_table.rb~ +0 -0
  72. data/lib/axlsx/workbook/worksheet/worksheet.rb +158 -44
  73. data/lib/axlsx.rb +16 -10
  74. data/test/content_type/tc_content_type.rb +2 -0
  75. data/test/content_type/tc_default.rb +2 -0
  76. data/test/content_type/tc_override.rb +1 -0
  77. data/test/drawing/tc_chart.rb +2 -2
  78. data/test/stylesheet/tc_cell_alignment.rb +8 -3
  79. data/test/stylesheet/tc_font.rb +8 -0
  80. data/test/stylesheet/tc_styles.rb +6 -2
  81. data/test/tc_package.rb +31 -0
  82. data/test/workbook/tc_shared_strings_table.rb +39 -0
  83. data/test/workbook/tc_shared_strings_table.rb~ +8 -0
  84. data/test/workbook/tc_workbook.rb +8 -0
  85. data/test/workbook/worksheet/tc_cell.rb +52 -9
  86. data/test/workbook/worksheet/tc_date_time_converter.rb +127 -0
  87. data/test/workbook/worksheet/tc_date_time_converter.rb~ +69 -0
  88. data/test/workbook/worksheet/tc_page_margins.rb +100 -0
  89. data/test/workbook/worksheet/tc_row.rb +36 -0
  90. data/test/workbook/worksheet/tc_worksheet.rb +97 -3
  91. metadata +33 -40
data/.yardopts CHANGED
@@ -2,3 +2,4 @@
2
2
  --no-private
3
3
  --title "AXLSX"
4
4
  --files LICENSE
5
+ --files CHANGELOG.md
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  CHANGELOG
2
2
  ---------
3
+ - **January.6.12**: 1.0.15 release
4
+ https://github.com/randym/axlsx/compare/1.0.14...1.0.15
5
+ - Bug fix add_style specified number formats must be explicity applied for libraOffice
6
+ - performance improvements from ochko when creating cells with options.
7
+ - Bug fix setting types=>[:n] when adding a row incorrectly determines the cell type to be string as the value is null during creation.
8
+ - Release in preparation for password protection merge
9
+
3
10
  - **December.14.11**: 1.0.14 release
4
11
  - Added support for merging cells
5
12
  - Added support for auto filters
data/README.md CHANGED
@@ -2,24 +2,24 @@ Axlsx: Office Open XML Spreadsheet Generation
2
2
  ====================================
3
3
  [![Build Status](https://secure.travis-ci.org/randym/axlsx.png)](http://travis-ci.org/randym/axlsx/)
4
4
 
5
- **IRC**: [irc.freenode.net / #axlsx](irc://irc.freenode.net/axlsx)
6
- **Git**: [http://github.com/randym/axlsx](http://github.com/randym/axlsx)
7
- **Author**: Randy Morgan
8
- **Copyright**: 2011
9
- **License**: MIT License
10
- **Latest Version**: 1.0.16
11
- **Ruby Version**: 1.8.7, 1.9.2, 1.9.3
5
+ **IRC**: [irc.freenode.net / #axlsx](irc://irc.freenode.net/axlsx)
6
+ **Git**: [http://github.com/randym/axlsx](http://github.com/randym/axlsx)
7
+ **Author**: Randy Morgan
8
+ **Copyright**: 2011
9
+ **License**: MIT License
10
+ **Latest Version**: 1.0.18
11
+ **Ruby Version**: 1.8.7, 1.9.2, 1.9.3
12
12
 
13
- **Release Date**: February 2nd 2012
13
+ **Release Date**: March 5th 2012
14
14
 
15
15
  Synopsis
16
16
  --------
17
17
 
18
18
  Axlsx is an Office Open XML Spreadsheet generator for the Ruby programming language.
19
- With Axlsx you can create excel worksheets with charts, images, automated column width, customizable styles, functins, merged cells and auto filters as well as full schema validation. Axlsx excels at helping you generate beautiful Office Open XML Spreadsheet documents without having to understand the entire ECMA specification.
19
+ With Axlsx you can create excel worksheets with charts, images (with links), automated and fixed column widths, customizable styles, functions, merged cells, auto filters, file and stream serialization as well as full schema validation. Axlsx excels at helping you generate beautiful Office Open XML Spreadsheet documents without having to understand the entire ECMA specification.
20
20
 
21
21
  If you are working in rails, or with active record see:
22
- http://github.com/randym/acts_as_xlsx
22
+ http://github.com/randym/acts_as_xlsx
23
23
 
24
24
  There are guides for using axlsx and acts_as_xlsx here:
25
25
  [http://axlsx.blogspot.com](http://axlsx.blogspot.com)
@@ -31,24 +31,24 @@ I'd really like to get rid of the depenency on RMagick in this gem. RMagic is be
31
31
 
32
32
  Feature List
33
33
  ------------
34
-
34
+
35
35
  **1. Author xlsx documents: Axlsx is made to let you easily and quickly generate profesional xlsx based reports that can be validated before serialiation.
36
36
 
37
37
  **2. Generate 3D Pie, Line 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.
38
-
38
+
39
39
  **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.
40
40
 
41
- **4. Automatic type support: Axlsx will automatically determine the type of data you are generating. In this release Float, Integer, String and Time types are automatically identified and serialized to your spreadsheet.
41
+ **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.
42
42
 
43
- **5. Automatic column widths: Axlsx will automatically determine the appropriate width for your columns based on the content in the worksheet.
43
+ **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.
44
44
 
45
- **6. Support for automatically formatted 1904 and 1900 epocs configurable in the workbook.
45
+ **6. Support for automatically formatted 1904 and 1900 epochs configurable in the workbook.
46
46
 
47
47
  **7. Add jpg, gif and png images to worksheets with hyperlinks
48
48
 
49
- **8. Refernce cells in your worksheet with "A1" and "A1:D4" style references or from the workbook using "Sheett1!A3:B4" style references
49
+ **8. Reference cells in your worksheet with "A1" and "A1:D4" style references or from the workbook using "Sheett1!A3:B4" style references
50
50
 
51
- **9. Cell level style overrides for default and customized style object
51
+ **9. Cell level style overrides for default and customized style objects
52
52
 
53
53
  **10. Support for formulas
54
54
 
@@ -56,13 +56,19 @@ Feature List
56
56
 
57
57
  **12. Auto filtering tables with worksheet.auto_filter
58
58
 
59
+ **13. Export using shared strings or inline strings so we can inter-op with iWork Numbers (sans charts for now).
60
+
61
+ **14. Output to file or StringIO
62
+
63
+ **15. Support for page margins
64
+
59
65
  Installing
60
66
  ----------
61
67
 
62
68
  To install Axlsx, use the following command:
63
69
 
64
70
  $ gem install axlsx
65
-
71
+
66
72
  #Usage
67
73
  ------
68
74
 
@@ -78,18 +84,19 @@ To install Axlsx, use the following command:
78
84
  sheet.add_row [1, 2, 3]
79
85
  end
80
86
 
81
- ##Using Custom Styles
87
+ ##Using Custom Styles and Row Heights
82
88
 
83
89
  wb.styles do |s|
84
90
  black_cell = s.add_style :bg_color => "00", :fg_color => "FF", :sz => 14, :alignment => { :horizontal=> :center }
85
91
  blue_cell = s.add_style :bg_color => "0000FF", :fg_color => "FF", :sz => 20, :alignment => { :horizontal=> :center }
86
92
  wb.add_worksheet(:name => "Custom Styles") do |sheet|
87
93
  sheet.add_row ["Text Autowidth", "Second", "Third"], :style => [black_cell, blue_cell, black_cell]
88
- sheet.add_row [1, 2, 3], :style => Axlsx::STYLE_THIN_BORDER
94
+ sheet.add_row [1, 2, 3], :style => Axlsx::STYLE_THIN_BORDER, :height => 20
89
95
  end
90
96
  end
91
97
 
92
98
  ##Using Custom Formatting and date1904
99
+
93
100
  require 'date'
94
101
  wb.styles do |s|
95
102
  date = s.add_style(:format_code => "yyyy-mm-dd", :border => Axlsx::STYLE_THIN_BORDER)
@@ -105,25 +112,25 @@ To install Axlsx, use the following command:
105
112
  ##Add an Image
106
113
 
107
114
  wb.add_worksheet(:name => "Images") do |sheet|
108
- img = File.expand_path('examples/image1.jpeg')
115
+ img = File.expand_path('examples/image1.jpeg')
109
116
  sheet.add_image(:image_src => img, :noSelect => true, :noMove => true) do |image|
110
117
  image.width=720
111
118
  image.height=666
112
119
  image.start_at 2, 2
113
120
  end
114
- end
121
+ end
115
122
 
116
123
  ##Add an Image with a hyperlink
117
124
 
118
125
  wb.add_worksheet(:name => "Image with Hyperlink") do |sheet|
119
- img = File.expand_path('examples/image1.jpeg')
126
+ img = File.expand_path('examples/image1.jpeg')
120
127
  sheet.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image|
121
128
  image.width=720
122
129
  image.height=666
123
130
  image.hyperlink.tooltip = "Labeled Link"
124
131
  image.start_at 2, 2
125
132
  end
126
- end
133
+ end
127
134
 
128
135
  ##Asian Language Support
129
136
 
@@ -131,7 +138,7 @@ To install Axlsx, use the following command:
131
138
  sheet.add_row ["日本語"]
132
139
  sheet.add_row ["华语/華語"]
133
140
  sheet.add_row ["한국어/조선말"]
134
- end
141
+ end
135
142
 
136
143
  ##Styling Columns
137
144
 
@@ -170,7 +177,7 @@ To install Axlsx, use the following command:
170
177
  # cell level style overrides via sheet range
171
178
  sheet["A1:D1"].each { |c| c.color = "FF0000"}
172
179
  sheet['A1:D2'].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
173
- end
180
+ end
174
181
 
175
182
  ##Using formula
176
183
 
@@ -179,6 +186,13 @@ To install Axlsx, use the following command:
179
186
  sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
180
187
  end
181
188
 
189
+ ##Automatic cell types
190
+
191
+ wb.add_worksheet(:name => "Automatic cell types") do |sheet|
192
+ sheet.add_row ["Date", "Time", "String", "Boolean", "Float", "Integer"]
193
+ sheet.add_row [Date.today, Time.now, "value", true, 0.1, 1]
194
+ end
195
+
182
196
  ##Merging Cells.
183
197
 
184
198
  wb.add_worksheet(:name => 'Merging Cells') do |sheet|
@@ -190,7 +204,7 @@ To install Axlsx, use the following command:
190
204
  sheet.merge_cells("A4:C4")
191
205
  sheet["A1:D1"].each { |c| c.color = "FF0000"}
192
206
  sheet["A1:D4"].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
193
- end
207
+ end
194
208
 
195
209
  ##Generating A Bar Chart
196
210
 
@@ -201,7 +215,7 @@ To install Axlsx, use the following command:
201
215
  sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A4", :end_at => "F17") do |chart|
202
216
  chart.add_series :data => sheet["A3:C3"], :labels => sheet["A2:C2"], :title => sheet["A1"]
203
217
  end
204
- end
218
+ end
205
219
 
206
220
  ##Generating A Pie Chart
207
221
 
@@ -211,7 +225,7 @@ To install Axlsx, use the following command:
211
225
  sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,2], :end_at => [5, 15], :title => "example 3: Pie Chart") do |chart|
212
226
  chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"]
213
227
  end
214
- end
228
+ end
215
229
 
216
230
  ##Data over time
217
231
 
@@ -225,9 +239,9 @@ To install Axlsx, use the following command:
225
239
  sheet.add_chart(Axlsx::Bar3DChart) do |chart|
226
240
  chart.start_at "B7"
227
241
  chart.end_at "H27"
228
- chart.add_series(:data => sheet["B2:B5"], :labels => sheet["A2:A5"], :title => sheet["B1"])
229
- end
230
- end
242
+ chart.add_series(:data => sheet["B2:B5"], :labels => sheet["A2:A5"], :title => sheet["B1"])
243
+ end
244
+ end
231
245
 
232
246
  ##Generating A Line Chart
233
247
 
@@ -238,9 +252,9 @@ To install Axlsx, use the following command:
238
252
  chart.start_at 0, 2
239
253
  chart.end_at 10, 15
240
254
  chart.add_series :data => sheet["B1:E1"], :title => sheet["A1"]
241
- chart.add_series :data => sheet["B2:E2"], :title => sheet["A2"]
242
- end
243
- end
255
+ chart.add_series :data => sheet["B2:E2"], :title => sheet["A2"]
256
+ end
257
+ end
244
258
 
245
259
  ##Auto Filter
246
260
 
@@ -251,13 +265,36 @@ To install Axlsx, use the following command:
251
265
  sheet.add_row ["19.2", "1 min 28 sec", "about 10 hours ago", "1.9.2"]
252
266
  sheet.add_row ["19.3", "1 min 35 sec", "about 10 hours ago", "1.9.3"]
253
267
  sheet.auto_filter = "A2:D5"
254
- end
268
+ end
269
+
270
+ ##Specifying Column Widths
271
+
272
+ wb.add_worksheet(:name => "custom column widths") do |sheet|
273
+ sheet.add_row ["I use auto_fit and am very wide", "I use a custom width and am narrow"]
274
+ sheet.column_widths nil, 3
275
+ end
276
+
277
+ ##Specify Page Margins for printing
278
+ margins = {:left => 3, :right => 3, :top => 1.2, :bottom => 1.2, :header => 0.7, :footer => 0.7}
279
+ wb.add_worksheet(:name => "print margins", :page_margins => margins) do |sheet|
280
+ sheet.add_row["this sheet uses customized page margins for printing"]
281
+ end
255
282
 
256
283
  ##Validate and Serialize
257
284
 
258
285
  p.validate.each { |e| puts e.message }
259
286
  p.serialize("example.xlsx")
260
287
 
288
+ # alternatively, serilaize to StringIO
289
+ s = p.to_stream()
290
+ File.open('example_streamed.xlsx', 'w') { |f| f.write(s.read) }
291
+
292
+ ##Using Shared Strings
293
+
294
+ p.use_shared_strings = true
295
+ p.serialize("shared_strings_example.xlsx")
296
+
297
+
261
298
 
262
299
  #Documentation
263
300
  --------------
@@ -269,23 +306,35 @@ This gem is 100% documented with YARD, an exceptional documentation library. To
269
306
  #Specs
270
307
  ------
271
308
  This gem has 100% test coverage using test/unit. To execute tests for this gem, simply run rake in the gem directory.
272
-
309
+
273
310
  #Changelog
274
311
  ---------
312
+ - ** March.5.12**: 1.0.18 release
313
+ https://github.com/randym/axlsx/compare/1.0.17...1.0.18
314
+ - bugfix custom borders are not properly applied when using styles.add_style
315
+ - interop worksheet names must be 31 characters or less or some versions of office complain about repairs
316
+ - added type support for :boolean and :date types cell values
317
+ - added support for fixed column widths
318
+ - added support for page_margins
319
+ - added << alias for add_row
320
+ - removed presetting of date1904 based on authoring platform. Now defaults to use 1900 epoch (date1904 = false)
321
+
322
+ - ** February.14.12**: 1.0.17 release
323
+ https://github.com/randym/axlsx/compare/1.0.16...1.0.17
324
+ - Added in support for serializing to StringIO
325
+ - Added in support for using shared strings table. This makes most of the features in axlsx interoperable with iWorks Numbers
326
+ - Added in support for fixed column_widths
327
+ - Removed unneded depenencies on activesupport and i18n
328
+
275
329
  - ** February.2.12**: 1.0.16 release
330
+ https://github.com/randym/axlsx/compare/1.0.15...1.0.16
276
331
  - Bug fix for schema file locations when validating in rails
277
332
  - Added hyperlink to images
278
333
  - date1904 now automatically set in bsd and mac environments
279
334
  - removed whitespace/indentation from xml outputs
280
335
  - col_style now skips rows that do not contain cells at the column index
281
-
282
- - **January.6.12**: 1.0.15 release
283
- - Bug fix add_style specified number formats must be explicity applied for libraOffice
284
- - performance improvements from ochko when creating cells with options.
285
- - Bug fix setting types=>[:n] when adding a row incorrectly determines the cell type to be string as the value is null during creation.
286
- - Release in preparation for password protection merge
287
-
288
-
336
+
337
+
289
338
  Please see the {file:CHANGELOG.md} document for past release information.
290
339
 
291
340
  #Thanks!
@@ -294,8 +343,18 @@ Please see the {file:CHANGELOG.md} document for past release information.
294
343
 
295
344
  [kleine2](https://github.com/kleine2) - for generously donating in return for the image hyperlink feature.
296
345
 
346
+ [ffmike](https://github.com/ffmike) - for knocking down an over restrictive i18n dependency, massive patience and great communication skills.
347
+
348
+ [JonathanTron](https://github.com/JonathanTron) - for giving the gem some style, and making sure it applies.
349
+
350
+ [JosephHalter](https://github.com/JosephHalter) - for making sure we arrive at the right time on the right date.
351
+
352
+ [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.
353
+
354
+ [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.
355
+
297
356
  #Copyright and License
298
357
  ----------
299
358
 
300
- Axlsx &copy; 2011 by [Randy Morgan](mailto:digial.ipseity@gmail.com). Axlsx is
359
+ Axlsx &copy; 2011 by [Randy Morgan](mailto:digial.ipseity@gmail.com). Axlsx is
301
360
  licensed under the MIT license. Please see the {file:LICENSE} document for more information.