axlsx 1.0.15 → 1.1.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 (184) hide show
  1. data/.yardopts +1 -0
  2. data/CHANGELOG.md +58 -2
  3. data/README.md +425 -207
  4. data/Rakefile +6 -2
  5. data/examples/axlsx.xlsx +0 -0
  6. data/examples/example.csv +1000 -0
  7. data/examples/example.rb +266 -132
  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/real_example.rb +63 -0
  12. data/examples/sample.png +0 -0
  13. data/examples/shared_strings_example.xlsx +0 -0
  14. data/lib/axlsx/content_type/content_type.rb +13 -12
  15. data/lib/axlsx/content_type/default.rb +10 -6
  16. data/lib/axlsx/content_type/override.rb +13 -8
  17. data/lib/axlsx/doc_props/app.rb +38 -41
  18. data/lib/axlsx/doc_props/core.rb +13 -17
  19. data/lib/axlsx/drawing/axis.rb +39 -19
  20. data/lib/axlsx/drawing/bar_3D_chart.rb +34 -32
  21. data/lib/axlsx/drawing/bar_series.rb +14 -14
  22. data/lib/axlsx/drawing/cat_axis.rb +16 -14
  23. data/lib/axlsx/drawing/cat_axis_data.rb +17 -18
  24. data/lib/axlsx/drawing/chart.rb +40 -41
  25. data/lib/axlsx/drawing/drawing.rb +27 -12
  26. data/lib/axlsx/drawing/graphic_frame.rb +22 -21
  27. data/lib/axlsx/drawing/hlink_click.rb~ +0 -0
  28. data/lib/axlsx/drawing/hyperlink.rb +96 -0
  29. data/lib/axlsx/drawing/hyperlink.rb~ +64 -0
  30. data/lib/axlsx/drawing/line_3D_chart.rb +31 -28
  31. data/lib/axlsx/drawing/line_series.rb +12 -11
  32. data/lib/axlsx/drawing/marker.rb +11 -8
  33. data/lib/axlsx/drawing/named_axis_data.rb +36 -0
  34. data/lib/axlsx/drawing/one_cell_anchor.rb +18 -16
  35. data/lib/axlsx/drawing/pic.rb +47 -33
  36. data/lib/axlsx/drawing/picture_locking.rb +22 -18
  37. data/lib/axlsx/drawing/pie_3D_chart.rb +11 -8
  38. data/lib/axlsx/drawing/pie_series.rb +16 -12
  39. data/lib/axlsx/drawing/scaling.rb +11 -10
  40. data/lib/axlsx/drawing/scatter_chart.rb +69 -0
  41. data/lib/axlsx/drawing/scatter_series.rb +39 -0
  42. data/lib/axlsx/drawing/ser_axis.rb +11 -10
  43. data/lib/axlsx/drawing/series.rb +16 -15
  44. data/lib/axlsx/drawing/series_title.rb +15 -14
  45. data/lib/axlsx/drawing/title.rb +27 -26
  46. data/lib/axlsx/drawing/two_cell_anchor.rb +19 -20
  47. data/lib/axlsx/drawing/val_axis.rb +9 -7
  48. data/lib/axlsx/drawing/val_axis_data.rb +18 -17
  49. data/lib/axlsx/drawing/view_3D.rb +23 -20
  50. data/lib/axlsx/package.rb +117 -52
  51. data/lib/axlsx/rels/relationship.rb +27 -8
  52. data/lib/axlsx/rels/relationships.rb +9 -2
  53. data/lib/axlsx/stylesheet/border.rb +28 -23
  54. data/lib/axlsx/stylesheet/border_pr.rb +17 -15
  55. data/lib/axlsx/stylesheet/cell_alignment.rb +24 -21
  56. data/lib/axlsx/stylesheet/cell_protection.rb +11 -7
  57. data/lib/axlsx/stylesheet/cell_style.rb +9 -5
  58. data/lib/axlsx/stylesheet/color.rb +20 -14
  59. data/lib/axlsx/stylesheet/fill.rb +8 -5
  60. data/lib/axlsx/stylesheet/font.rb +22 -14
  61. data/lib/axlsx/stylesheet/gradient_fill.rb +20 -17
  62. data/lib/axlsx/stylesheet/gradient_stop.rb +10 -6
  63. data/lib/axlsx/stylesheet/num_fmt.rb +13 -6
  64. data/lib/axlsx/stylesheet/pattern_fill.rb +26 -10
  65. data/lib/axlsx/stylesheet/styles.rb +55 -41
  66. data/lib/axlsx/stylesheet/table_style.rb +10 -4
  67. data/lib/axlsx/stylesheet/table_style_element.rb +11 -7
  68. data/lib/axlsx/stylesheet/table_styles.rb +12 -8
  69. data/lib/axlsx/stylesheet/xf.rb +30 -25
  70. data/lib/axlsx/util/cbf.rb +69 -33
  71. data/lib/axlsx/util/constants.rb +39 -20
  72. data/lib/axlsx/util/doc/_index.html +84 -0
  73. data/lib/axlsx/util/doc/class_list.html +47 -0
  74. data/lib/axlsx/util/doc/css/common.css +1 -0
  75. data/lib/axlsx/util/doc/css/full_list.css +55 -0
  76. data/lib/axlsx/util/doc/css/style.css +322 -0
  77. data/lib/axlsx/util/doc/file_list.html +46 -0
  78. data/lib/axlsx/util/doc/frames.html +13 -0
  79. data/lib/axlsx/util/doc/index.html +84 -0
  80. data/lib/axlsx/util/doc/js/app.js +205 -0
  81. data/lib/axlsx/util/doc/js/full_list.js +173 -0
  82. data/lib/axlsx/util/doc/js/jquery.js +16 -0
  83. data/lib/axlsx/util/doc/method_list.html +46 -0
  84. data/lib/axlsx/util/doc/top-level-namespace.html +95 -0
  85. data/lib/axlsx/util/font_tables.rb~ +0 -0
  86. data/lib/axlsx/util/ms_off_crypto.rb +10 -10
  87. data/lib/axlsx/util/parser.rb +1 -0
  88. data/lib/axlsx/util/simple_typed_list.rb +20 -10
  89. data/lib/axlsx/util/storage.rb +1 -1
  90. data/lib/axlsx/util/validators.rb +23 -7
  91. data/lib/axlsx/version.rb +5 -2
  92. data/lib/axlsx/workbook/shared_strings_table.rb +68 -0
  93. data/lib/axlsx/workbook/shared_strings_table.rb~ +69 -0
  94. data/lib/axlsx/workbook/workbook.rb +82 -26
  95. data/lib/axlsx/workbook/worksheet/cell.rb +166 -130
  96. data/lib/axlsx/workbook/worksheet/col.rb +114 -0
  97. data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
  98. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +29 -0
  99. data/lib/axlsx/workbook/worksheet/page_margins.rb +97 -0
  100. data/lib/axlsx/workbook/worksheet/row.rb +53 -21
  101. data/lib/axlsx/workbook/worksheet/shared_strings_table.rb~ +0 -0
  102. data/lib/axlsx/workbook/worksheet/table.rb +96 -0
  103. data/lib/axlsx/workbook/worksheet/table.rb~ +97 -0
  104. data/lib/axlsx/workbook/worksheet/worksheet.rb +275 -124
  105. data/lib/axlsx.rb +41 -14
  106. data/lib/schema/dc.xsd +5 -5
  107. data/lib/schema/dcmitype.xsd +5 -3
  108. data/lib/schema/dcterms.xsd +15 -15
  109. data/lib/schema/opc-coreProperties.xsd +6 -2
  110. data/lib/schema/xml.xsd +7 -8
  111. data/test/benchmark.rb +73 -0
  112. data/test/content_type/tc_content_type.rb +31 -31
  113. data/test/content_type/tc_default.rb +9 -22
  114. data/test/content_type/tc_override.rb +8 -21
  115. data/test/doc_props/tc_app.rb +2 -8
  116. data/test/doc_props/tc_core.rb +6 -7
  117. data/test/drawing/tc_axis.rb +7 -3
  118. data/test/drawing/tc_bar_3D_chart.rb +6 -7
  119. data/test/drawing/tc_bar_series.rb +4 -5
  120. data/test/drawing/tc_cat_axis.rb +2 -3
  121. data/test/drawing/tc_cat_axis_data.rb +2 -3
  122. data/test/drawing/tc_chart.rb +13 -14
  123. data/test/drawing/tc_drawing.rb +7 -8
  124. data/test/drawing/tc_graphic_frame.rb +3 -4
  125. data/test/drawing/tc_hyperlink.rb +69 -0
  126. data/test/drawing/tc_line_3d_chart.rb +5 -6
  127. data/test/drawing/tc_line_series.rb +3 -4
  128. data/test/drawing/tc_marker.rb +3 -4
  129. data/test/drawing/tc_one_cell_anchor.rb +6 -7
  130. data/test/drawing/tc_pic.rb +13 -8
  131. data/test/drawing/tc_picture_locking.rb +2 -3
  132. data/test/drawing/tc_pie_3D_chart.rb +5 -6
  133. data/test/drawing/tc_pie_series.rb +4 -5
  134. data/test/drawing/tc_scaling.rb +3 -4
  135. data/test/drawing/tc_scatter_chart.rb +43 -0
  136. data/test/drawing/tc_scatter_series.rb +20 -0
  137. data/test/drawing/tc_ser_axis.rb +2 -3
  138. data/test/drawing/tc_series.rb +4 -5
  139. data/test/drawing/tc_series_title.rb +4 -5
  140. data/test/drawing/tc_title.rb +4 -5
  141. data/test/drawing/tc_two_cell_anchor.rb +4 -5
  142. data/test/drawing/tc_val_axis.rb +2 -3
  143. data/test/drawing/tc_val_axis_data.rb +2 -3
  144. data/test/drawing/tc_view_3D.rb +6 -7
  145. data/test/profile.rb +34 -0
  146. data/test/rels/tc_relationship.rb +10 -6
  147. data/test/rels/tc_relationships.rb +4 -5
  148. data/test/stylesheet/tc_border.rb +3 -4
  149. data/test/stylesheet/tc_border_pr.rb +3 -4
  150. data/test/stylesheet/tc_cell_alignment.rb +10 -6
  151. data/test/stylesheet/tc_cell_protection.rb +2 -3
  152. data/test/stylesheet/tc_cell_style.rb +2 -3
  153. data/test/stylesheet/tc_color.rb +2 -3
  154. data/test/stylesheet/tc_fill.rb +1 -2
  155. data/test/stylesheet/tc_font.rb +12 -5
  156. data/test/stylesheet/tc_gradient_fill.rb +1 -2
  157. data/test/stylesheet/tc_gradient_stop.rb +1 -2
  158. data/test/stylesheet/tc_num_fmt.rb +1 -2
  159. data/test/stylesheet/tc_pattern_fill.rb +3 -4
  160. data/test/stylesheet/tc_styles.rb +31 -6
  161. data/test/stylesheet/tc_table_style.rb +2 -3
  162. data/test/stylesheet/tc_table_style_element.rb +2 -3
  163. data/test/stylesheet/tc_table_styles.rb +3 -4
  164. data/test/stylesheet/tc_xf.rb +16 -17
  165. data/test/tc_axlsx.rb +39 -0
  166. data/test/tc_helper.rb +3 -0
  167. data/test/tc_package.rb +43 -9
  168. data/test/util/tc_simple_typed_list.rb +8 -9
  169. data/test/util/tc_validators.rb +7 -8
  170. data/test/workbook/tc_shared_strings_table.rb +38 -0
  171. data/test/workbook/tc_workbook.rb +32 -6
  172. data/test/workbook/worksheet/table/tc_table.rb +71 -0
  173. data/test/workbook/worksheet/table/tc_table.rb~ +72 -0
  174. data/test/workbook/worksheet/tc_cell.rb +80 -13
  175. data/test/workbook/worksheet/tc_col.rb +59 -0
  176. data/test/workbook/worksheet/tc_col.rb~ +10 -0
  177. data/test/workbook/worksheet/tc_date_time_converter.rb +132 -0
  178. data/test/workbook/worksheet/tc_page_margins.rb +97 -0
  179. data/test/workbook/worksheet/tc_row.rb +54 -4
  180. data/test/workbook/worksheet/tc_worksheet.rb +205 -31
  181. metadata +78 -84
  182. data/examples/example.rb~ +0 -112
  183. data/test/drawing/tc_line_series.tc~ +0 -34
  184. data/test/drawing/tc_picture_locking.rb~ +0 -77
data/README.md CHANGED
@@ -2,53 +2,63 @@ 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.15
11
- **Ruby Version**: 1.8.7, 1.9.2, 1.9.3
5
+ **IRC**:[irc.freenode.net / #axlsx](irc://irc.freenode.net/axlsx)
12
6
 
13
- **Release Date**: January 6th 2012
7
+ **Git**:[http://github.com/randym/axlsx](http://github.com/randym/axlsx)
8
+
9
+ **Twitter**: [https://twitter.com/#!/morgan_randy](https://twitter.com/#!/morgan_randy)
10
+
11
+ **Google Group**: [https://groups.google.com/forum/?fromgroups#!forum/axlsx](https://groups.google.com/forum/?fromgroups#!forum/axlsx)
12
+
13
+ **Author**: Randy Morgan
14
+
15
+ **Copyright**: 2011 - 2012
16
+
17
+ **License**: MIT License
18
+
19
+ **Latest Version**: 1.1.1
20
+
21
+ **Ruby Version**: 1.8.7, 1.9.2, 1.9.3
22
+
23
+ **JRuby Version**: 1.6.7
24
+
25
+ **Release Date**: April 18th 2012
14
26
 
15
27
  Synopsis
16
28
  --------
17
29
 
18
30
  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.
31
+ With Axlsx you can create excel worksheets with charts, images (with links), automated and fixed column widths, customized 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.
32
+
33
+ ![Screen 1](https://github.com/randym/axlsx/raw/master/examples/sample.png)
20
34
 
21
35
  If you are working in rails, or with active record see:
22
- http://github.com/randym/acts_as_xlsx
36
+ http://github.com/randym/acts_as_xlsx
23
37
 
24
38
  There are guides for using axlsx and acts_as_xlsx here:
25
39
  [http://axlsx.blogspot.com](http://axlsx.blogspot.com)
26
40
 
27
- Help Wanted
28
- -----------
29
-
30
- I'd really like to get rid of the depenency on RMagick in this gem. RMagic is being used to calculate the column widths in a worksheet based on the content the user specified. If there happens to be anyone out there with the background and c skills to write an extenstion that can determine the width of a single character rendered with a specific font at a specific font size please give me a shout.
31
41
 
32
42
  Feature List
33
43
  ------------
34
-
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.
44
+
45
+ **1. Author xlsx documents: Axlsx is made to let you easily and quickly generate professional xlsx based reports that can be validated before serialization.
36
46
 
37
47
  **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
-
48
+
39
49
  **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
50
 
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.
51
+ **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
52
 
43
- **5. Automatic column widths: Axlsx will automatically determine the appropriate width for your columns based on the content in the worksheet.
53
+ **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
54
 
45
- **6. Support for automatically formatted 1904 and 1900 epocs configurable in the workbook.
55
+ **6. Support for automatically formatted 1904 and 1900 epochs configurable in the workbook.
46
56
 
47
- **7. Add jpg, gif and png images to worksheets
57
+ **7. Add jpg, gif and png images to worksheets with hyperlinks
48
58
 
49
- **8. Refernce cells in your worksheet with "A1" and "A1:D4" style references or from the workbook using "Sheett1!A3:B4" style references
59
+ **8. Reference cells in your worksheet with "A1" and "A1:D4" style references or from the workbook using "Sheet1!A3:B4" style references
50
60
 
51
- **9. Cell level style overrides for default and customized style object
61
+ **9. Cell level style overrides for default and customized style objects
52
62
 
53
63
  **10. Support for formulas
54
64
 
@@ -56,249 +66,457 @@ Feature List
56
66
 
57
67
  **12. Auto filtering tables with worksheet.auto_filter
58
68
 
69
+ **13. Export using shared strings or inline strings so we can inter-op with iWork Numbers (sans charts for now).
70
+
71
+ **14. Output to file or StringIO
72
+
73
+ **15. Support for page margins
74
+
59
75
  Installing
60
76
  ----------
61
77
 
62
78
  To install Axlsx, use the following command:
63
79
 
64
80
  $ gem install axlsx
65
-
81
+
66
82
  #Usage
67
83
  ------
68
84
 
69
- require 'axlsx'
70
-
71
- p = Axlsx::Package.new
72
- wb = p.workbook
73
-
74
- ##A Simple Workbook
85
+ ```ruby
86
+ require 'axlsx'
87
+
88
+ p = Axlsx::Package.new
89
+ wb = p.workbook
90
+ ```
91
+
92
+ #A Simple Workbook
93
+
94
+ ```ruby
95
+ wb.add_worksheet(:name => "Basic Worksheet") do |sheet|
96
+ sheet.add_row ["First Column", "Second", "Third"]
97
+ sheet.add_row [1, 2, 3]
98
+ end
99
+ ```
100
+
101
+ #Using Custom Styles
102
+
103
+ ```ruby
104
+ wb.styles do |s|
105
+ black_cell = s.add_style :bg_color => "00", :fg_color => "FF", :sz => 14, :alignment => { :horizontal=> :center }
106
+ blue_cell = s.add_style :bg_color => "0000FF", :fg_color => "FF", :sz => 20, :alignment => { :horizontal=> :center }
107
+ wb.add_worksheet(:name => "Custom Styles") do |sheet|
108
+ sheet.add_row ["Text Autowidth", "Second", "Third"], :style => [black_cell, blue_cell, black_cell]
109
+ sheet.add_row [1, 2, 3], :style => Axlsx::STYLE_THIN_BORDER
110
+ end
111
+ end
112
+ ```
113
+
114
+ #Using Custom Border Styles
115
+
116
+ ```ruby
117
+ wb.styles do |s|
118
+ red_border = s.add_style :border => { :style => :thin, :color =>"FFFF0000" }
119
+ blue_border = s.add_style :border => { :style => :thin, :color =>"FF0000FF" }
120
+
121
+ wb.add_worksheet(:name => "Custom Borders") do |sheet|
122
+ sheet.add_row ["wrap", "me", "Up in Red"], :style => red_border
123
+ sheet.add_row [1, 2, 3], :style => blue_border
124
+ end
125
+ end
126
+ ```
127
+
128
+
129
+ ##Using Custom Formatting and date1904
130
+
131
+ ```ruby
132
+ require 'date'
133
+ wb.styles do |s|
134
+ date = s.add_style(:format_code => "yyyy-mm-dd", :border => Axlsx::STYLE_THIN_BORDER)
135
+ padded = s.add_style(:format_code => "00#", :border => Axlsx::STYLE_THIN_BORDER)
136
+ percent = s.add_style(:format_code => "0000%", :border => Axlsx::STYLE_THIN_BORDER)
137
+ # wb.date1904 = true # Use the 1904 date system (Used by Excel for Mac < 2011)
138
+ wb.add_worksheet(:name => "Formatting Data") do |sheet|
139
+ sheet.add_row ["Custom Formatted Date", "Percent Formatted Float", "Padded Numbers"], :style => Axlsx::STYLE_THIN_BORDER
140
+ sheet.add_row [Date::strptime('2012-01-19','%Y-%m-%d'), 0.2, 32], :style => [date, percent, padded]
141
+ end
142
+ end
143
+ ```
75
144
 
76
- wb.add_worksheet(:name => "Basic Worksheet") do |sheet|
77
- sheet.add_row ["First Column", "Second", "Third"]
78
- sheet.add_row [1, 2, 3]
79
- end
80
145
 
81
- ##Using Custom Styles
146
+ ##Add an Image
82
147
 
83
- wb.styles do |s|
84
- black_cell = s.add_style :bg_color => "00", :fg_color => "FF", :sz => 14, :alignment => { :horizontal=> :center }
85
- blue_cell = s.add_style :bg_color => "0000FF", :fg_color => "FF", :sz => 20, :alignment => { :horizontal=> :center }
86
- wb.add_worksheet(:name => "Custom Styles") do |sheet|
87
- 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
89
- end
90
- end
148
+ ```ruby
149
+ wb.add_worksheet(:name => "Images") do |sheet|
150
+ img = File.expand_path('../image1.jpeg', __FILE__)
151
+ sheet.add_image(:image_src => img, :noSelect => true, :noMove => true) do |image|
152
+ image.width=720
153
+ image.height=666
154
+ image.start_at 2, 2
155
+ end
156
+ end
157
+ ```
158
+
159
+ ##Add an Image with a hyperlink
160
+
161
+ ```ruby
162
+ wb.add_worksheet(:name => "Image with Hyperlink") do |sheet|
163
+ img = File.expand_path('../image1.jpeg', __FILE__)
164
+ sheet.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image|
165
+ image.width=720
166
+ image.height=666
167
+ image.hyperlink.tooltip = "Labeled Link"
168
+ image.start_at 2, 2
169
+ end
170
+ end
171
+ ```
91
172
 
92
- ##Using Custom Formatting
173
+ ##Asian Language Support
93
174
 
94
- wb.styles do |s|
95
- date = s.add_style(:format_code => "yyyy-mm-dd", :border => Axlsx::STYLE_THIN_BORDER)
96
- padded = s.add_style(:format_code => "00#", :border => Axlsx::STYLE_THIN_BORDER)
97
- percent = s.add_style(:format_code => "0000%", :border => Axlsx::STYLE_THIN_BORDER)
98
- wb.add_worksheet(:name => "Formatting Data") do |sheet|
99
- sheet.add_row ["Custom Formatted Date", "Percent Formatted Float", "Padded Numbers"], :style => Axlsx::STYLE_THIN_BORDER
100
- sheet.add_row [Time.now, 0.2, 32], :style => [date, percent, padded]
101
- end
102
- end
175
+ ```ruby
176
+ wb.add_worksheet(:name => "日本語でのシート名") do |sheet|
177
+ sheet.add_row ["日本語"]
178
+ sheet.add_row ["华语/華語"]
179
+ sheet.add_row ["한국어/조선말"]
180
+ end
181
+ ```
103
182
 
104
183
  ##Styling Columns
105
184
 
106
- wb.styles do |s|
107
- percent = s.add_style :num_fmt => 9
108
- wb.add_worksheet(:name => "Styling Columns") do |sheet|
109
- sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
110
- sheet.add_row [1, 2, 0.3, 4]
111
- sheet.add_row [1, 2, 0.2, 4]
112
- sheet.add_row [1, 2, 0.1, 4]
113
- sheet.col_style 2, percent, :row_offset => 1
114
- end
115
- end
185
+ ```ruby
186
+ wb.styles do |s|
187
+ percent = s.add_style :num_fmt => 9
188
+ wb.add_worksheet(:name => "Styling Columns") do |sheet|
189
+ sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
190
+ sheet.add_row [1, 2, 0.3, 4]
191
+ sheet.add_row [1, 2, 0.2, 4]
192
+ sheet.add_row [1, 2, 0.1, 4]
193
+ sheet.col_style 2, percent, :row_offset => 1
194
+ end
195
+ end
196
+ ```
197
+
198
+ ##Hiding Columns
199
+
200
+ ```ruby
201
+ wb.styles do |s|
202
+ percent = s.add_style :num_fmt => 9
203
+ wb.add_worksheet(:name => "Hidden Column") do |sheet|
204
+ sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
205
+ sheet.add_row [1, 2, 0.3, 4]
206
+ sheet.add_row [1, 2, 0.2, 4]
207
+ sheet.add_row [1, 2, 0.1, 4]
208
+ sheet.col_style 2, percent, :row_offset => 1
209
+ sheet.column_info[1].hidden = true
210
+ end
211
+ end
212
+ ```
116
213
 
117
214
  ##Styling Rows
118
215
 
119
- wb.styles do |s|
120
- head = s.add_style :bg_color => "00", :fg_color => "FF"
121
- percent = s.add_style :num_fmt => 9
122
- wb.add_worksheet(:name => "Styling Rows") do |sheet|
123
- sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
124
- sheet.add_row [1, 2, 0.3, 4]
125
- sheet.add_row [1, 2, 0.2, 4]
126
- sheet.add_row [1, 2, 0.1, 4]
127
- sheet.col_style 2, percent, :row_offset => 1
128
- sheet.row_style 0, head
129
- end
130
- end
216
+ ```ruby
217
+ wb.styles do |s|
218
+ head = s.add_style :bg_color => "00", :fg_color => "FF"
219
+ percent = s.add_style :num_fmt => 9
220
+ wb.add_worksheet(:name => "Styling Rows") do |sheet|
221
+ sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
222
+ sheet.add_row [1, 2, 0.3, 4]
223
+ sheet.add_row [1, 2, 0.2, 4]
224
+ sheet.add_row [1, 2, 0.1, 4]
225
+ sheet.col_style 2, percent, :row_offset => 1
226
+ sheet.row_style 0, head
227
+ end
228
+ end
229
+ ```
131
230
 
132
231
  ##Styling Cell Overrides
133
232
 
134
- wb.add_worksheet(:name => "Cell Level Style Overrides") do |sheet|
135
- # cell level style overides when adding cells
136
- sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4'], :sz => 16
137
- sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
138
- # cell level style overrides via sheet range
139
- sheet["A1:D1"].each { |c| c.color = "FF0000"}
140
- sheet['A1:D2'].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
141
- end
142
-
143
- ##Add an Image
144
-
145
- wb.add_worksheet(:name => "Images") do |sheet|
146
- img = File.expand_path('examples/image1.jpeg')
147
- sheet.add_image(:image_src => img, :noSelect => true, :noMove => true) do |image|
148
- image.width=720
149
- image.height=666
150
- image.start_at 2, 2
151
- end
152
- end
153
-
154
- ##Asian Language Support
155
-
156
- wb.add_worksheet(:name => "Unicode Support") do |sheet|
157
- sheet.add_row ["日本語"]
158
- sheet.add_row ["华语/華語"]
159
- sheet.add_row ["한국어/조선말"]
160
- end
161
-
233
+ ```ruby
234
+ wb.add_worksheet(:name => "Cell Level Style Overrides") do |sheet|
235
+ # cell level style overides when adding cells
236
+ sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4'], :sz => 16
237
+ sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
238
+ # cell level style overrides via sheet range
239
+ sheet["A1:D1"].each { |c| c.color = "FF0000"}
240
+ sheet['A1:D2'].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
241
+ end
242
+ ```
162
243
 
163
244
  ##Using formula
164
245
 
165
- wb.add_worksheet(:name => "Using Formulas") do |sheet|
166
- sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
167
- sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
168
- end
169
-
170
-
171
- ##Merging Cells
172
-
173
- wb.add_worksheet(:name => 'Merging Cells') do |sheet|
174
- # cell level style overides when adding cells
175
- sheet.add_row ["col 1", "col 2", "col 3", "col 4"], :sz => 16
176
- sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
177
- sheet.add_row [2, 3, 4, "=SUM(A3:C3)"]
178
- sheet.add_row ["total", "", "", "=SUM(D2:D3)"]
179
- sheet.merge_cells("A4:C4")
180
- sheet["A1:D1"].each { |c| c.color = "FF0000"}
181
- sheet["A1:D4"].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
182
- end
246
+ ```ruby
247
+ wb.add_worksheet(:name => "Using Formulas") do |sheet|
248
+ sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
249
+ sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
250
+ end
251
+ ```
252
+
253
+ ##Automatic cell types
254
+
255
+ ```ruby
256
+ wb.add_worksheet(:name => "Automatic cell types") do |sheet|
257
+ sheet.add_row ["Date", "Time", "String", "Boolean", "Float", "Integer"]
258
+ sheet.add_row [Date.today, Time.now, "value", true, 0.1, 1]
259
+ end
260
+ ```
261
+
262
+ ##Merging Cells.
263
+
264
+ ```ruby
265
+ wb.add_worksheet(:name => 'Merging Cells') do |sheet|
266
+ # cell level style overides when adding cells
267
+ sheet.add_row ["col 1", "col 2", "col 3", "col 4"], :sz => 16
268
+ sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
269
+ sheet.add_row [2, 3, 4, "=SUM(A3:C3)"]
270
+ sheet.add_row ["total", "", "", "=SUM(D2:D3)"]
271
+ sheet.merge_cells("A4:C4")
272
+ sheet["A1:D1"].each { |c| c.color = "FF0000"}
273
+ sheet["A1:D4"].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
274
+ end
275
+ ```
183
276
 
184
277
  ##Generating A Bar Chart
185
278
 
186
- wb.add_worksheet(:name => "Bar Chart") do |sheet|
187
- sheet.add_row ["A Simple Bar Chart"]
188
- sheet.add_row ["First", "Second", "Third"]
189
- sheet.add_row [1, 2, 3]
190
- sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A4", :end_at => "F17") do |chart|
191
- chart.add_series :data => sheet["A3:C3"], :labels => sheet["A2:C2"], :title => sheet["A1"]
192
- end
193
- end
279
+ ```ruby
280
+ wb.add_worksheet(:name => "Bar Chart") do |sheet|
281
+ sheet.add_row ["A Simple Bar Chart"]
282
+ sheet.add_row ["First", "Second", "Third"]
283
+ sheet.add_row [1, 2, 3]
284
+ sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A4", :end_at => "F17") do |chart|
285
+ chart.add_series :data => sheet["A3:C3"], :labels => sheet["A2:C2"], :title => sheet["A1"]
286
+ end
287
+ end
288
+ ```
289
+
290
+ ##Hide Gridlines in chart
291
+
292
+ ```ruby
293
+ wb.add_worksheet(:name => "Chart With No Gridlines") do |sheet|
294
+ sheet.add_row ["A Simple Bar Chart"]
295
+ sheet.add_row ["First", "Second", "Third"]
296
+ sheet.add_row [1, 2, 3]
297
+ sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A4", :end_at => "F17") do |chart|
298
+ chart.add_series :data => sheet["A3:C3"], :labels => sheet["A2:C2"], :title => sheet["A1"]
299
+ chart.valAxis.gridlines = false
300
+ chart.catAxis.gridlines = false
301
+ end
302
+ end
303
+ ```
194
304
 
195
305
  ##Generating A Pie Chart
196
306
 
197
- wb.add_worksheet(:name => "Pie Chart") do |sheet|
198
- sheet.add_row ["First", "Second", "Third", "Fourth"]
199
- sheet.add_row [1, 2, 3, "=PRODUCT(A2:C2)"]
200
- sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,2], :end_at => [5, 15], :title => "example 3: Pie Chart") do |chart|
201
- chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"]
202
- end
203
- end
307
+ ```ruby
308
+ wb.add_worksheet(:name => "Pie Chart") do |sheet|
309
+ sheet.add_row ["First", "Second", "Third", "Fourth"]
310
+ sheet.add_row [1, 2, 3, "=PRODUCT(A2:C2)"]
311
+ sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,2], :end_at => [5, 15], :title => "example 3: Pie Chart") do |chart|
312
+ chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"]
313
+ end
314
+ end
315
+ ```
204
316
 
205
317
  ##Data over time
206
318
 
207
- wb.add_worksheet(:name=>'Charting Dates') do |sheet|
208
- # cell level style overides when adding cells
209
- sheet.add_row ['Date', 'Value'], :sz => 16
210
- sheet.add_row [Time.now - (7*60*60*24), 3]
211
- sheet.add_row [Time.now - (6*60*60*24), 7]
212
- sheet.add_row [Time.now - (5*60*60*24), 18]
213
- sheet.add_row [Time.now - (4*60*60*24), 1]
214
- sheet.add_chart(Axlsx::Bar3DChart) do |chart|
215
- chart.start_at "B7"
216
- chart.end_at "H27"
217
- chart.add_series(:data => sheet["B2:B5"], :labels => sheet["A2:A5"], :title => sheet["B1"])
218
- end
219
- end
319
+ ```ruby
320
+ wb.add_worksheet(:name=>'Charting Dates') do |sheet|
321
+ # cell level style overides when adding cells
322
+ sheet.add_row ['Date', 'Value'], :sz => 16
323
+ sheet.add_row [Time.now - (7*60*60*24), 3]
324
+ sheet.add_row [Time.now - (6*60*60*24), 7]
325
+ sheet.add_row [Time.now - (5*60*60*24), 18]
326
+ sheet.add_row [Time.now - (4*60*60*24), 1]
327
+ sheet.add_chart(Axlsx::Bar3DChart) do |chart|
328
+ chart.start_at "B7"
329
+ chart.end_at "H27"
330
+ chart.add_series(:data => sheet["B2:B5"], :labels => sheet["A2:A5"], :title => sheet["B1"])
331
+ end
332
+ end
333
+ ```
220
334
 
221
335
  ##Generating A Line Chart
222
336
 
223
- wb.add_worksheet(:name => "Line Chart") do |sheet|
224
- sheet.add_row ["First", 1, 5, 7, 9]
225
- sheet.add_row ["Second", 5, 2, 14, 9]
226
- sheet.add_chart(Axlsx::Line3DChart, :title => "example 6: Line Chart", :rotX => 30, :rotY => 20) do |chart|
227
- chart.start_at 0, 2
228
- chart.end_at 10, 15
229
- chart.add_series :data => sheet["B1:E1"], :title => sheet["A1"]
230
- chart.add_series :data => sheet["B2:E2"], :title => sheet["A2"]
231
- end
232
- end
337
+ ```ruby
338
+ wb.add_worksheet(:name => "Line Chart") do |sheet|
339
+ sheet.add_row ["First", 1, 5, 7, 9]
340
+ sheet.add_row ["Second", 5, 2, 14, 9]
341
+ sheet.add_chart(Axlsx::Line3DChart, :title => "example 6: Line Chart", :rotX => 30, :rotY => 20) do |chart|
342
+ chart.start_at 0, 2
343
+ chart.end_at 10, 15
344
+ chart.add_series :data => sheet["B1:E1"], :title => sheet["A1"]
345
+ chart.add_series :data => sheet["B2:E2"], :title => sheet["A2"]
346
+ end
347
+ end
348
+ ```
349
+
350
+ ##Generating A Scatter Chart
351
+
352
+ ```ruby
353
+ wb.add_worksheet(:name => "Scatter Chart") do |sheet|
354
+ sheet.add_row ["First", 1, 5, 7, 9]
355
+ sheet.add_row ["", 1, 25, 49, 81]
356
+ sheet.add_row ["Second", 5, 2, 14, 9]
357
+ sheet.add_row ["", 5, 10, 15, 20]
358
+ sheet.add_chart(Axlsx::ScatterChart, :title => "example 7: Scatter Chart") do |chart|
359
+ chart.start_at 0, 4
360
+ chart.end_at 10, 19
361
+ chart.add_series :xData => sheet["B1:E1"], :yData => sheet["B2:E2"], :title => sheet["A1"]
362
+ chart.add_series :xData => sheet["B3:E3"], :yData => sheet["B4:E4"], :title => sheet["A3"]
363
+ end
364
+ end
365
+ ```
233
366
 
234
367
  ##Auto Filter
235
368
 
236
- wb.add_worksheet(:name => "Auto Filter") do |sheet|
237
- sheet.add_row ["Build Matrix"]
238
- sheet.add_row ["Build", "Duration", "Finished", "Rvm"]
239
- sheet.add_row ["19.1", "1 min 32 sec", "about 10 hours ago", "1.8.7"]
240
- sheet.add_row ["19.2", "1 min 28 sec", "about 10 hours ago", "1.9.2"]
241
- sheet.add_row ["19.3", "1 min 35 sec", "about 10 hours ago", "1.9.3"]
242
- sheet.auto_filter = "A2:D5"
243
- end
369
+ ```ruby
370
+ wb.add_worksheet(:name => "Auto Filter") do |sheet|
371
+ sheet.add_row ["Build Matrix"]
372
+ sheet.add_row ["Build", "Duration", "Finished", "Rvm"]
373
+ sheet.add_row ["19.1", "1 min 32 sec", "about 10 hours ago", "1.8.7"]
374
+ sheet.add_row ["19.2", "1 min 28 sec", "about 10 hours ago", "1.9.2"]
375
+ sheet.add_row ["19.3", "1 min 35 sec", "about 10 hours ago", "1.9.3"]
376
+ sheet.auto_filter = "A2:D5"
377
+ end
378
+ ```
379
+
380
+ ##Tables
381
+
382
+ ```ruby
383
+ wb.add_worksheet(:name => "Table") do |sheet|
384
+ sheet.add_row ["Build Matrix"]
385
+ sheet.add_row ["Build", "Duration", "Finished", "Rvm"]
386
+ sheet.add_row ["19.1", "1 min 32 sec", "about 10 hours ago", "1.8.7"]
387
+ sheet.add_row ["19.2", "1 min 28 sec", "about 10 hours ago", "1.9.2"]
388
+ sheet.add_row ["19.3", "1 min 35 sec", "about 10 hours ago", "1.9.3"]
389
+ sheet.add_table "A2:D5", :name => 'Build Matrix'
390
+ end
391
+ ```
392
+
393
+ ##Specifying Column Widths
394
+
395
+ ```ruby
396
+ wb.add_worksheet(:name => "custom column widths") do |sheet|
397
+ sheet.add_row ["I use autowidth and am very wide", "I use a custom width and am narrow"]
398
+ sheet.add_row ['abcdefg', 'This is a very long text and should flow into the right cell', nil, 'xxx' ]
399
+ sheet.column_widths nil, 3, 5, nil
400
+ end
401
+ ```
402
+
403
+ ##Fit to page printing
404
+
405
+ ```ruby
406
+ wb.add_worksheet(:name => "fit to page") do |sheet|
407
+ sheet.add_row ['this all goes on one page']
408
+ sheet.fit_to_page = true
409
+ end
410
+ ```
411
+
412
+ ##Hide Gridlines in worksheet
413
+
414
+ ```ruby
415
+ wb.add_worksheet(:name => "No Gridlines") do |sheet|
416
+ sheet.add_row ["This", "Sheet", "Hides", "Gridlines"]
417
+ sheet.show_gridlines = false
418
+ end
419
+ ```
420
+
421
+ ##Specify Page Margins for printing
422
+
423
+ ```ruby
424
+ margins = {:left => 3, :right => 3, :top => 1.2, :bottom => 1.2, :header => 0.7, :footer => 0.7}
425
+ wb.add_worksheet(:name => "print margins", :page_margins => margins) do |sheet|
426
+ sheet.add_row ["this sheet uses customized page margins for printing"]
427
+ end
428
+ ```
244
429
 
245
430
  ##Validate and Serialize
246
431
 
247
- p.validate.each { |e| puts e.message }
248
- p.serialize("example.xlsx")
432
+ ```ruby
433
+ p.serialize("example.xlsx")
249
434
 
435
+ s = p.to_stream()
436
+ File.open('example_streamed.xlsx', 'w') { |f| f.write(s.read) }
437
+ ```
438
+
439
+ ##Using Shared Strings
440
+
441
+ ```ruby
442
+ p.use_shared_strings = true
443
+ p.serialize("shared_strings_example.xlsx")
444
+ ```
445
+
446
+
447
+ ##Disabling Autowidth
448
+
449
+ ```ruby
450
+ p = Axlsx::Package.new
451
+ p.use_autowidth = false
452
+ wb = p.workbook
453
+ wb.add_worksheet(:name => "No Magick") do | sheet |
454
+ sheet.add_row ['oh look! no autowidth - and no magick loaded in your process']
455
+ end
456
+ p.validate.each { |e| puts e.message }
457
+ p.serialize("no-use_autowidth.xlsx")
458
+ ```
250
459
 
251
460
  #Documentation
252
461
  --------------
253
462
  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:
254
463
 
255
- gem install yard
256
- yard server -g
257
-
258
-
464
+ ```bash
465
+ gem install yard
466
+ yard server -g
467
+ ```
259
468
  #Specs
260
469
  ------
261
470
  This gem has 100% test coverage using test/unit. To execute tests for this gem, simply run rake in the gem directory.
262
-
263
- #Changelog
471
+
472
+ #Change log
264
473
  ---------
265
- - **January.6.12**: 1.0.15 release
266
- - Bug fix add_style specified number formats must be explicity applied for libraOffice
267
- - performance improvements from ochko when creating cells with options.
268
- - Bug fix setting types=>[:n] when adding a row incorrectly determines the cell type to be string as the value is null during creation.
269
- - Release in preparation for password protection merge
270
-
271
- - **December.14.11**: 1.0.14 release
272
- - Added support for merging cells
273
- - Added support for auto filters
274
- - Improved auto width calculations
275
- - Improved charts
276
- - Updated examples to output to a single workbook with multiple sheets
277
- - Added access to app and core package objects so you can set the creator and other properties of the package
278
- - The beginning of password protected xlsx files - roadmapped for January release.
279
-
280
- - **December.8.11**: 1.0.13 release
281
- - Fixing .gemspec errors that caused gem to miss the lib directory. Sorry about that.
282
-
283
- - **December.7.11**: 1.0.12 release
284
- DO NOT USE THIS VERSION = THE GEM IS BROKEN
285
- - changed dependency from 'zip' gem to 'rubyzip' and added conditional code to force binary encoding to resolve issue with excel 2011
286
- - Patched bug in app.xml that would ignore user specified properties.
287
- - **December.5.11**: 1.0.11 release
288
- - Added [] methods to worksheet and workbook to provide name based access to cells.
289
- - Added support for functions as cell values
290
- - Updated color creation so that two character shorthand values can be used like 'FF' for 'FFFFFFFF' or 'D8' for 'FFD8D8D8'
291
- - Examples for all this fun stuff added to the readme
292
- - Clean up and support for 1.9.2 and travis integration
293
- - Added support for string based cell referencing to chart start_at and end_at. That means you can now use :start_at=>"A1" when using worksheet.add_chart, or chart.start_at ="A1" in addition to passing a cell or the x, y coordinates.
294
-
474
+ - ** April.18.12**: 1.1.1 release
475
+ - bugfix for autowidth calculations across multiple rows
476
+ - bugfix for dimension calculations with nil cells.
477
+ - REMOVED RMAGICK dependency WOOT!
478
+ - Update readme to show screenshot of gem output.
479
+ - Cleanup benchmark and add benchmark rake task
480
+
481
+ - ** April.3.12**: 1.1.0 release
482
+ - bugfix patch name_to_indecies to properly handle extended ranges.
483
+ - bugfix properly serialize chart title.
484
+ - lower rake minimum requirement for 1.8.7 apps that don't want to move on to 0.9 NOTE this will be reverted for 2.0.0 with workbook parsing!
485
+ - Added Fit to Page printing
486
+ - added support for turning off gridlines in charts.
487
+ - added support for turning off gridlines in worksheet.
488
+ - bugfix some apps like libraoffice require apply[x] attributes to be true. applyAlignment is now properly set.
489
+ - added option use_autowidth. When this is false RMagick will not be loaded or used in the stack. However it is still a requirement in the gem.
490
+ - added border style specification to styles#add_style. See the example in the readme.
491
+ - Support for tables added in - Note: Pre 2011 versions of Mac office do not support this feature and will warn.
492
+ - Support for splatter charts added
493
+ - Major (like 7x faster!) performance updates.
494
+ - Gem now supports for JRuby 1.6.7, as well as expirimental support for Rubinius
495
+
295
496
  Please see the {file:CHANGELOG.md} document for past release information.
296
497
 
297
498
  #Thanks!
298
499
  --------
299
- ochko https://github.com/ochko
500
+ [ochko](https://github.com/ochko) - for performance fixes, kicking the crap out of axlsx and helping to maintain my general sanity.
501
+
502
+ [kleine2](https://github.com/kleine2) - for generously donating in return for the image hyperlink feature.
503
+
504
+ [ffmike](https://github.com/ffmike) - for knocking down an over restrictive i18n dependency, massive patience and great communication skills.
505
+
506
+ [JonathanTron](https://github.com/JonathanTron) - for giving the gem some style, and making sure it applies.
507
+
508
+ [JosephHalter](https://github.com/JosephHalter) - for making sure we arrive at the right time on the right date.
509
+
510
+ [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.
511
+
512
+ [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.
513
+
514
+ [joekain](https://github.com/joekain) - for keeping our references working even in the double digits!
515
+
516
+ [moskrin](https://github.com/moskrin) - for keeping border creation on the edge.
517
+
300
518
  #Copyright and License
301
519
  ----------
302
520
 
303
- Axlsx &copy; 2011 by [Randy Morgan](mailto:digial.ipseity@gmail.com). Axlsx is
521
+ Axlsx &copy; 2011-2012 by [Randy Morgan](mailto:digial.ipseity@gmail.com). Axlsx is
304
522
  licensed under the MIT license. Please see the {file:LICENSE} document for more information.