bonio-axlsx 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (325) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +9 -0
  3. data/.yardopts_guide +19 -0
  4. data/CHANGELOG.md +239 -0
  5. data/LICENSE +22 -0
  6. data/README.md +258 -0
  7. data/Rakefile +30 -0
  8. data/examples/2010_comments.rb +17 -0
  9. data/examples/anchor_swapping.rb +28 -0
  10. data/examples/auto_filter.rb +25 -0
  11. data/examples/basic_charts.rb +58 -0
  12. data/examples/chart_colors.rb +88 -0
  13. data/examples/colored_links.rb +59 -0
  14. data/examples/conditional_formatting/example_conditional_formatting.rb +89 -0
  15. data/examples/conditional_formatting/getting_barred.rb +37 -0
  16. data/examples/conditional_formatting/hitting_the_high_notes.rb +37 -0
  17. data/examples/conditional_formatting/scaled_colors.rb +39 -0
  18. data/examples/conditional_formatting/stop_and_go.rb +37 -0
  19. data/examples/data_validation.rb +50 -0
  20. data/examples/example.rb +875 -0
  21. data/examples/extractive.rb +45 -0
  22. data/examples/image1.jpeg +0 -0
  23. data/examples/ios_preview.rb +14 -0
  24. data/examples/merge_cells.rb +17 -0
  25. data/examples/no_grid_with_borders.rb +18 -0
  26. data/examples/page_setup.rb +11 -0
  27. data/examples/pivot_table.rb +39 -0
  28. data/examples/pivot_test.rb +63 -0
  29. data/examples/sheet_protection.rb +10 -0
  30. data/examples/skydrive/real_example.rb +63 -0
  31. data/examples/split.rb +16 -0
  32. data/examples/styles.rb +66 -0
  33. data/examples/underline.rb +13 -0
  34. data/examples/wrap_text.rb +21 -0
  35. data/lib/axlsx.rb +168 -0
  36. data/lib/axlsx/content_type/abstract_content_type.rb +32 -0
  37. data/lib/axlsx/content_type/content_type.rb +26 -0
  38. data/lib/axlsx/content_type/default.rb +25 -0
  39. data/lib/axlsx/content_type/override.rb +25 -0
  40. data/lib/axlsx/doc_props/app.rb +235 -0
  41. data/lib/axlsx/doc_props/core.rb +39 -0
  42. data/lib/axlsx/drawing/ax_data_source.rb +26 -0
  43. data/lib/axlsx/drawing/axes.rb +61 -0
  44. data/lib/axlsx/drawing/axis.rb +190 -0
  45. data/lib/axlsx/drawing/bar_3D_chart.rb +151 -0
  46. data/lib/axlsx/drawing/bar_series.rb +82 -0
  47. data/lib/axlsx/drawing/bubble_chart.rb +59 -0
  48. data/lib/axlsx/drawing/bubble_series.rb +63 -0
  49. data/lib/axlsx/drawing/cat_axis.rb +85 -0
  50. data/lib/axlsx/drawing/chart.rb +274 -0
  51. data/lib/axlsx/drawing/d_lbls.rb +90 -0
  52. data/lib/axlsx/drawing/drawing.rb +164 -0
  53. data/lib/axlsx/drawing/graphic_frame.rb +54 -0
  54. data/lib/axlsx/drawing/hyperlink.rb +100 -0
  55. data/lib/axlsx/drawing/line_3D_chart.rb +68 -0
  56. data/lib/axlsx/drawing/line_chart.rb +99 -0
  57. data/lib/axlsx/drawing/line_series.rb +110 -0
  58. data/lib/axlsx/drawing/marker.rb +84 -0
  59. data/lib/axlsx/drawing/num_data.rb +52 -0
  60. data/lib/axlsx/drawing/num_data_source.rb +62 -0
  61. data/lib/axlsx/drawing/num_val.rb +34 -0
  62. data/lib/axlsx/drawing/one_cell_anchor.rb +98 -0
  63. data/lib/axlsx/drawing/pic.rb +213 -0
  64. data/lib/axlsx/drawing/picture_locking.rb +42 -0
  65. data/lib/axlsx/drawing/pie_3D_chart.rb +47 -0
  66. data/lib/axlsx/drawing/pie_series.rb +74 -0
  67. data/lib/axlsx/drawing/scaling.rb +60 -0
  68. data/lib/axlsx/drawing/scatter_chart.rb +74 -0
  69. data/lib/axlsx/drawing/scatter_series.rb +98 -0
  70. data/lib/axlsx/drawing/ser_axis.rb +45 -0
  71. data/lib/axlsx/drawing/series.rb +69 -0
  72. data/lib/axlsx/drawing/series_title.rb +23 -0
  73. data/lib/axlsx/drawing/str_data.rb +42 -0
  74. data/lib/axlsx/drawing/str_val.rb +34 -0
  75. data/lib/axlsx/drawing/title.rb +96 -0
  76. data/lib/axlsx/drawing/two_cell_anchor.rb +92 -0
  77. data/lib/axlsx/drawing/val_axis.rb +37 -0
  78. data/lib/axlsx/drawing/view_3D.rb +115 -0
  79. data/lib/axlsx/drawing/vml_drawing.rb +42 -0
  80. data/lib/axlsx/drawing/vml_shape.rb +66 -0
  81. data/lib/axlsx/package.rb +363 -0
  82. data/lib/axlsx/rels/relationship.rb +129 -0
  83. data/lib/axlsx/rels/relationships.rb +29 -0
  84. data/lib/axlsx/stylesheet/border.rb +71 -0
  85. data/lib/axlsx/stylesheet/border_pr.rb +71 -0
  86. data/lib/axlsx/stylesheet/cell_alignment.rb +132 -0
  87. data/lib/axlsx/stylesheet/cell_protection.rb +41 -0
  88. data/lib/axlsx/stylesheet/cell_style.rb +72 -0
  89. data/lib/axlsx/stylesheet/color.rb +76 -0
  90. data/lib/axlsx/stylesheet/dxf.rb +79 -0
  91. data/lib/axlsx/stylesheet/fill.rb +35 -0
  92. data/lib/axlsx/stylesheet/font.rb +148 -0
  93. data/lib/axlsx/stylesheet/gradient_fill.rb +103 -0
  94. data/lib/axlsx/stylesheet/gradient_stop.rb +37 -0
  95. data/lib/axlsx/stylesheet/num_fmt.rb +86 -0
  96. data/lib/axlsx/stylesheet/pattern_fill.rb +73 -0
  97. data/lib/axlsx/stylesheet/styles.rb +420 -0
  98. data/lib/axlsx/stylesheet/table_style.rb +54 -0
  99. data/lib/axlsx/stylesheet/table_style_element.rb +77 -0
  100. data/lib/axlsx/stylesheet/table_styles.rb +46 -0
  101. data/lib/axlsx/stylesheet/xf.rb +147 -0
  102. data/lib/axlsx/util/accessors.rb +64 -0
  103. data/lib/axlsx/util/constants.rb +397 -0
  104. data/lib/axlsx/util/mime_type_utils.rb +11 -0
  105. data/lib/axlsx/util/options_parser.rb +16 -0
  106. data/lib/axlsx/util/parser.rb +44 -0
  107. data/lib/axlsx/util/serialized_attributes.rb +89 -0
  108. data/lib/axlsx/util/simple_typed_list.rb +179 -0
  109. data/lib/axlsx/util/storage.rb +146 -0
  110. data/lib/axlsx/util/string.rb +7 -0
  111. data/lib/axlsx/util/validators.rb +311 -0
  112. data/lib/axlsx/version.rb +5 -0
  113. data/lib/axlsx/workbook/defined_name.rb +128 -0
  114. data/lib/axlsx/workbook/defined_names.rb +21 -0
  115. data/lib/axlsx/workbook/shared_strings_table.rb +77 -0
  116. data/lib/axlsx/workbook/workbook.rb +375 -0
  117. data/lib/axlsx/workbook/workbook_view.rb +78 -0
  118. data/lib/axlsx/workbook/workbook_views.rb +22 -0
  119. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +77 -0
  120. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +94 -0
  121. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +244 -0
  122. data/lib/axlsx/workbook/worksheet/break.rb +35 -0
  123. data/lib/axlsx/workbook/worksheet/cell.rb +475 -0
  124. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +166 -0
  125. data/lib/axlsx/workbook/worksheet/cfvo.rb +60 -0
  126. data/lib/axlsx/workbook/worksheet/cfvos.rb +15 -0
  127. data/lib/axlsx/workbook/worksheet/col.rb +141 -0
  128. data/lib/axlsx/workbook/worksheet/col_breaks.rb +35 -0
  129. data/lib/axlsx/workbook/worksheet/color_scale.rb +110 -0
  130. data/lib/axlsx/workbook/worksheet/cols.rb +20 -0
  131. data/lib/axlsx/workbook/worksheet/comment.rb +91 -0
  132. data/lib/axlsx/workbook/worksheet/comments.rb +82 -0
  133. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +82 -0
  134. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +220 -0
  135. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +25 -0
  136. data/lib/axlsx/workbook/worksheet/data_bar.rb +129 -0
  137. data/lib/axlsx/workbook/worksheet/data_validation.rb +246 -0
  138. data/lib/axlsx/workbook/worksheet/data_validations.rb +28 -0
  139. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +30 -0
  140. data/lib/axlsx/workbook/worksheet/dimension.rb +64 -0
  141. data/lib/axlsx/workbook/worksheet/header_footer.rb +52 -0
  142. data/lib/axlsx/workbook/worksheet/icon_set.rb +81 -0
  143. data/lib/axlsx/workbook/worksheet/merged_cells.rb +37 -0
  144. data/lib/axlsx/workbook/worksheet/outline_pr.rb +33 -0
  145. data/lib/axlsx/workbook/worksheet/page_margins.rb +97 -0
  146. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +44 -0
  147. data/lib/axlsx/workbook/worksheet/page_setup.rb +240 -0
  148. data/lib/axlsx/workbook/worksheet/pane.rb +139 -0
  149. data/lib/axlsx/workbook/worksheet/pivot_table.rb +289 -0
  150. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +66 -0
  151. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +24 -0
  152. data/lib/axlsx/workbook/worksheet/print_options.rb +39 -0
  153. data/lib/axlsx/workbook/worksheet/protected_range.rb +47 -0
  154. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +34 -0
  155. data/lib/axlsx/workbook/worksheet/rich_text.rb +35 -0
  156. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +254 -0
  157. data/lib/axlsx/workbook/worksheet/row.rb +161 -0
  158. data/lib/axlsx/workbook/worksheet/row_breaks.rb +33 -0
  159. data/lib/axlsx/workbook/worksheet/selection.rb +101 -0
  160. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +29 -0
  161. data/lib/axlsx/workbook/worksheet/sheet_data.rb +27 -0
  162. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +60 -0
  163. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +87 -0
  164. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +118 -0
  165. data/lib/axlsx/workbook/worksheet/sheet_view.rb +213 -0
  166. data/lib/axlsx/workbook/worksheet/table.rb +102 -0
  167. data/lib/axlsx/workbook/worksheet/table_style_info.rb +49 -0
  168. data/lib/axlsx/workbook/worksheet/tables.rb +31 -0
  169. data/lib/axlsx/workbook/worksheet/worksheet.rb +799 -0
  170. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +58 -0
  171. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +58 -0
  172. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +74 -0
  173. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +38 -0
  174. data/lib/schema/dc.xsd +118 -0
  175. data/lib/schema/dcmitype.xsd +52 -0
  176. data/lib/schema/dcterms.xsd +331 -0
  177. data/lib/schema/dml-chart.xsd +1499 -0
  178. data/lib/schema/dml-chartDrawing.xsd +146 -0
  179. data/lib/schema/dml-compatibility.xsd +14 -0
  180. data/lib/schema/dml-diagram.xsd +1091 -0
  181. data/lib/schema/dml-lockedCanvas.xsd +11 -0
  182. data/lib/schema/dml-main.xsd +3048 -0
  183. data/lib/schema/dml-picture.xsd +23 -0
  184. data/lib/schema/dml-spreadsheetDrawing.xsd +185 -0
  185. data/lib/schema/dml-wordprocessingDrawing.xsd +185 -0
  186. data/lib/schema/opc-contentTypes.xsd +42 -0
  187. data/lib/schema/opc-coreProperties.xsd +54 -0
  188. data/lib/schema/opc-digSig.xsd +49 -0
  189. data/lib/schema/opc-relationships.xsd +33 -0
  190. data/lib/schema/pml.xsd +1676 -0
  191. data/lib/schema/shared-additionalCharacteristics.xsd +28 -0
  192. data/lib/schema/shared-bibliography.xsd +144 -0
  193. data/lib/schema/shared-commonSimpleTypes.xsd +166 -0
  194. data/lib/schema/shared-customXmlDataProperties.xsd +25 -0
  195. data/lib/schema/shared-customXmlSchemaProperties.xsd +18 -0
  196. data/lib/schema/shared-documentPropertiesCustom.xsd +59 -0
  197. data/lib/schema/shared-documentPropertiesExtended.xsd +56 -0
  198. data/lib/schema/shared-documentPropertiesVariantTypes.xsd +195 -0
  199. data/lib/schema/shared-math.xsd +582 -0
  200. data/lib/schema/shared-relationshipReference.xsd +25 -0
  201. data/lib/schema/sml.xsd +4434 -0
  202. data/lib/schema/vml-main.xsd +569 -0
  203. data/lib/schema/vml-officeDrawing.xsd +509 -0
  204. data/lib/schema/vml-presentationDrawing.xsd +12 -0
  205. data/lib/schema/vml-spreadsheetDrawing.xsd +108 -0
  206. data/lib/schema/vml-wordprocessingDrawing.xsd +96 -0
  207. data/lib/schema/wml.xsd +3644 -0
  208. data/lib/schema/xml.xsd +116 -0
  209. data/test/benchmark.rb +72 -0
  210. data/test/content_type/tc_content_type.rb +76 -0
  211. data/test/content_type/tc_default.rb +16 -0
  212. data/test/content_type/tc_override.rb +14 -0
  213. data/test/doc_props/tc_app.rb +43 -0
  214. data/test/doc_props/tc_core.rb +42 -0
  215. data/test/drawing/tc_axes.rb +8 -0
  216. data/test/drawing/tc_axis.rb +112 -0
  217. data/test/drawing/tc_bar_3D_chart.rb +71 -0
  218. data/test/drawing/tc_bar_series.rb +37 -0
  219. data/test/drawing/tc_bubble_chart.rb +44 -0
  220. data/test/drawing/tc_bubble_series.rb +21 -0
  221. data/test/drawing/tc_cat_axis.rb +31 -0
  222. data/test/drawing/tc_cat_axis_data.rb +27 -0
  223. data/test/drawing/tc_chart.rb +110 -0
  224. data/test/drawing/tc_d_lbls.rb +57 -0
  225. data/test/drawing/tc_data_source.rb +23 -0
  226. data/test/drawing/tc_drawing.rb +80 -0
  227. data/test/drawing/tc_graphic_frame.rb +27 -0
  228. data/test/drawing/tc_hyperlink.rb +64 -0
  229. data/test/drawing/tc_line_3d_chart.rb +47 -0
  230. data/test/drawing/tc_line_chart.rb +39 -0
  231. data/test/drawing/tc_line_series.rb +71 -0
  232. data/test/drawing/tc_marker.rb +44 -0
  233. data/test/drawing/tc_named_axis_data.rb +27 -0
  234. data/test/drawing/tc_num_data.rb +31 -0
  235. data/test/drawing/tc_num_val.rb +29 -0
  236. data/test/drawing/tc_one_cell_anchor.rb +66 -0
  237. data/test/drawing/tc_pic.rb +106 -0
  238. data/test/drawing/tc_picture_locking.rb +72 -0
  239. data/test/drawing/tc_pie_3D_chart.rb +28 -0
  240. data/test/drawing/tc_pie_series.rb +32 -0
  241. data/test/drawing/tc_scaling.rb +36 -0
  242. data/test/drawing/tc_scatter_chart.rb +48 -0
  243. data/test/drawing/tc_scatter_series.rb +45 -0
  244. data/test/drawing/tc_ser_axis.rb +31 -0
  245. data/test/drawing/tc_series.rb +23 -0
  246. data/test/drawing/tc_series_title.rb +33 -0
  247. data/test/drawing/tc_str_data.rb +18 -0
  248. data/test/drawing/tc_str_val.rb +30 -0
  249. data/test/drawing/tc_title.rb +49 -0
  250. data/test/drawing/tc_two_cell_anchor.rb +36 -0
  251. data/test/drawing/tc_val_axis.rb +24 -0
  252. data/test/drawing/tc_view_3D.rb +54 -0
  253. data/test/drawing/tc_vml_drawing.rb +25 -0
  254. data/test/drawing/tc_vml_shape.rb +106 -0
  255. data/test/profile.rb +24 -0
  256. data/test/rels/tc_relationship.rb +44 -0
  257. data/test/rels/tc_relationships.rb +37 -0
  258. data/test/stylesheet/tc_border.rb +37 -0
  259. data/test/stylesheet/tc_border_pr.rb +32 -0
  260. data/test/stylesheet/tc_cell_alignment.rb +81 -0
  261. data/test/stylesheet/tc_cell_protection.rb +29 -0
  262. data/test/stylesheet/tc_cell_style.rb +57 -0
  263. data/test/stylesheet/tc_color.rb +43 -0
  264. data/test/stylesheet/tc_dxf.rb +81 -0
  265. data/test/stylesheet/tc_fill.rb +18 -0
  266. data/test/stylesheet/tc_font.rb +121 -0
  267. data/test/stylesheet/tc_gradient_fill.rb +72 -0
  268. data/test/stylesheet/tc_gradient_stop.rb +31 -0
  269. data/test/stylesheet/tc_num_fmt.rb +30 -0
  270. data/test/stylesheet/tc_pattern_fill.rb +43 -0
  271. data/test/stylesheet/tc_styles.rb +235 -0
  272. data/test/stylesheet/tc_table_style.rb +44 -0
  273. data/test/stylesheet/tc_table_style_element.rb +45 -0
  274. data/test/stylesheet/tc_table_styles.rb +29 -0
  275. data/test/stylesheet/tc_xf.rb +120 -0
  276. data/test/tc_axlsx.rb +82 -0
  277. data/test/tc_helper.rb +10 -0
  278. data/test/tc_package.rb +233 -0
  279. data/test/util/tc_mime_type_utils.rb +13 -0
  280. data/test/util/tc_serialized_attributes.rb +19 -0
  281. data/test/util/tc_simple_typed_list.rb +77 -0
  282. data/test/util/tc_validators.rb +210 -0
  283. data/test/workbook/tc_defined_name.rb +49 -0
  284. data/test/workbook/tc_shared_strings_table.rb +58 -0
  285. data/test/workbook/tc_workbook.rb +145 -0
  286. data/test/workbook/tc_workbook_view.rb +50 -0
  287. data/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +38 -0
  288. data/test/workbook/worksheet/auto_filter/tc_filter_column.rb +76 -0
  289. data/test/workbook/worksheet/auto_filter/tc_filters.rb +50 -0
  290. data/test/workbook/worksheet/tc_break.rb +49 -0
  291. data/test/workbook/worksheet/tc_cell.rb +373 -0
  292. data/test/workbook/worksheet/tc_cfvo.rb +31 -0
  293. data/test/workbook/worksheet/tc_col.rb +78 -0
  294. data/test/workbook/worksheet/tc_color_scale.rb +58 -0
  295. data/test/workbook/worksheet/tc_comment.rb +72 -0
  296. data/test/workbook/worksheet/tc_comments.rb +57 -0
  297. data/test/workbook/worksheet/tc_conditional_formatting.rb +224 -0
  298. data/test/workbook/worksheet/tc_data_bar.rb +46 -0
  299. data/test/workbook/worksheet/tc_data_validation.rb +265 -0
  300. data/test/workbook/worksheet/tc_date_time_converter.rb +124 -0
  301. data/test/workbook/worksheet/tc_header_footer.rb +151 -0
  302. data/test/workbook/worksheet/tc_icon_set.rb +45 -0
  303. data/test/workbook/worksheet/tc_outline_pr.rb +19 -0
  304. data/test/workbook/worksheet/tc_page_margins.rb +97 -0
  305. data/test/workbook/worksheet/tc_page_set_up_pr.rb +15 -0
  306. data/test/workbook/worksheet/tc_page_setup.rb +143 -0
  307. data/test/workbook/worksheet/tc_pane.rb +54 -0
  308. data/test/workbook/worksheet/tc_pivot_table.rb +140 -0
  309. data/test/workbook/worksheet/tc_pivot_table_cache_definition.rb +54 -0
  310. data/test/workbook/worksheet/tc_print_options.rb +72 -0
  311. data/test/workbook/worksheet/tc_protected_range.rb +17 -0
  312. data/test/workbook/worksheet/tc_rich_text.rb +44 -0
  313. data/test/workbook/worksheet/tc_rich_text_run.rb +172 -0
  314. data/test/workbook/worksheet/tc_row.rb +122 -0
  315. data/test/workbook/worksheet/tc_selection.rb +55 -0
  316. data/test/workbook/worksheet/tc_sheet_calc_pr.rb +18 -0
  317. data/test/workbook/worksheet/tc_sheet_format_pr.rb +88 -0
  318. data/test/workbook/worksheet/tc_sheet_pr.rb +49 -0
  319. data/test/workbook/worksheet/tc_sheet_protection.rb +117 -0
  320. data/test/workbook/worksheet/tc_sheet_view.rb +214 -0
  321. data/test/workbook/worksheet/tc_table.rb +68 -0
  322. data/test/workbook/worksheet/tc_table_style_info.rb +53 -0
  323. data/test/workbook/worksheet/tc_worksheet.rb +594 -0
  324. data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +55 -0
  325. metadata +582 -0
@@ -0,0 +1,45 @@
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
+ p = Axlsx::Package.new
14
+ wb = p.workbook
15
+ wb.add_worksheet(:name => 'volumes') do |ws|
16
+
17
+ # perspective, rotX and rotY flatten the 3D chart
18
+ # hPercent sets the chart height to 100%
19
+ chart = ws.add_chart(Axlsx::Line3DChart, :perspective => 0, :hPercent => 100, :rotX => 0, :rotY => 0, :start_at => "A4", :end_at => 'M44', :title => 'Monthly forcast for Type Curve Gas secondary - gross ngl')
20
+
21
+ # Set up log based scaling and appropriate min/max values for Y axis
22
+ chart.valAxis.scaling.logBase = 10
23
+ chart.valAxis.scaling.min = 0.1
24
+ chart.valAxis.scaling.max = 10000000.0
25
+
26
+ # No poing in showing the series axis labels as the chart is flattened!
27
+ chart.serAxis.delete = true
28
+
29
+ # Knock the catAxis labels down to the forced min.
30
+ chart.catAxis.crosses = :min
31
+
32
+ # set up cat labels / markes to show every 12th item
33
+ chart.catAxis.tickLblSkip = 12
34
+ chart.catAxis.tickMarkSkip = 12
35
+
36
+ #rgb colors for our data series
37
+ colors = ['00FF00', 'FF0000', '0000FF']
38
+
39
+ data.each_with_index do |value, index|
40
+ ws.add_row value
41
+ chart.add_series :data => ws.rows.last.cells[(1..value.size-1)], :labels => (0..value.size).map{ |i| i }, :title => ws.rows.last.cells.first, :color => colors[index]
42
+ end
43
+ end
44
+
45
+ p.serialize 'extractive.xlsx'
Binary file
@@ -0,0 +1,14 @@
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
+
8
+ p = Axlsx::Package.new
9
+ p.use_shared_strings = true
10
+ s = p.workbook.add_worksheet(:name => "Formula test")
11
+ s.add_row [1, 2, 3]
12
+ s.add_row %w(a b c)
13
+ s.add_row ["=SUM(A1:C1)"], :formula_values => [6]
14
+ p.serialize "ios_preview.xlsx"
@@ -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
+ package = Axlsx::Package.new
8
+ package.workbook do |workbook|
9
+ workbook.add_worksheet name: 'merged_cells' do |sheet|
10
+ 4.times do
11
+ sheet.add_row %w(a b c d e f g)
12
+ end
13
+ sheet.merge_cells "A1:A2"
14
+ sheet.merge_cells "B1:B2"
15
+ end
16
+ end
17
+ package.serialize 'merged_cells.xlsx'
@@ -0,0 +1,18 @@
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
+ package = Axlsx::Package.new
8
+ package.workbook do |workbook|
9
+ workbook.styles do |s|
10
+ gridstyle_border = s.add_style :border => { :style => :thin, :color =>"FFCDCDCD" }
11
+ workbook.add_worksheet :name => "Custom Borders" do |sheet|
12
+ sheet.sheet_view.show_grid_lines = false
13
+ sheet.add_row ["with", "grid", "style"], :style => gridstyle_border
14
+ sheet.add_row ["no", "border"]
15
+ end
16
+ end
17
+ end
18
+ package.serialize 'no_grid_with_borders.xlsx'
@@ -0,0 +1,11 @@
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
+ # Excel does not currently follow the specification and will ignore paper_width and paper_height so if you need
7
+ # to for a paper size, be sure to set :paper_size
8
+ ws.page_setup.set :paper_width => "210mm", :paper_size => 10, :paper_height => "297mm", :orientation => :landscape
9
+ ws.add_row %w(AXLSX is cool)
10
+ end
11
+ xls.serialize "page_setup.xlsx"
@@ -0,0 +1,39 @@
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
+ p = Axlsx::Package.new
8
+ wb = p.workbook
9
+
10
+ # Create some data in a sheet
11
+ def month
12
+ %w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec).sample
13
+ end
14
+ def year
15
+ %w(2010 2011 2012).sample
16
+ end
17
+ def type
18
+ %w(Meat Dairy Beverages Produce).sample
19
+ end
20
+ def sales
21
+ rand(5000)
22
+ end
23
+ def region
24
+ %w(East West North South).sample
25
+ end
26
+
27
+ wb.add_worksheet(:name => "Data Sheet") do |sheet|
28
+ sheet.add_row ['Month', 'Year', 'Type', 'Sales', 'Region']
29
+ 30.times { sheet.add_row [month, year, type, sales, region] }
30
+ sheet.add_pivot_table 'G4:L17', "A1:E31" do |pivot_table|
31
+ pivot_table.rows = ['Month', 'Year']
32
+ pivot_table.columns = ['Type']
33
+ pivot_table.data = ['Sales']
34
+ pivot_table.pages = ['Region']
35
+ end
36
+ end
37
+
38
+ # Write the excel file
39
+ p.serialize("pivot_table.xlsx")
@@ -0,0 +1,63 @@
1
+ class RandomReportGenerator
2
+ def date
3
+ Date.today.strftime("%m/%d/%Y")
4
+ end
5
+ def member_id
6
+ @i ||= 0
7
+ @i += 1
8
+ end
9
+ def name
10
+ "John S."
11
+ end
12
+ def gender
13
+ ["Male", "Female"].sample
14
+ end
15
+ def age
16
+ rand(100)
17
+ end
18
+ def city
19
+ ["New York", "Mountain View", "Newark", "Phoenix"].sample
20
+ end
21
+ def state
22
+ ["NY", "CA", "NJ", "AZ"].sample
23
+ end
24
+ def parenting
25
+ "Foo"
26
+ end
27
+ def student
28
+ "Bar"
29
+ end
30
+ def income
31
+ "Bar"
32
+ end
33
+ def education
34
+ "Bar"
35
+ end
36
+ def answer
37
+ ["Yes", "No", "Maybe", "I dont know"].sample
38
+ end
39
+ def run
40
+ package = Axlsx::Package.new
41
+ workbook = package.workbook
42
+
43
+ workbook.add_worksheet(:name => "Data Sheet") do |sheet|
44
+ sheet.add_row [
45
+ "Date", "Member ID", "Name", "Gender", "Age", "City", "State",
46
+ "Parenting Status", "Student Status", "Income", "Education", "Answer"
47
+ ]
48
+ 30.times do
49
+ sheet.add_row [date, member_id, name, gender, age, city, state,
50
+ parenting, student, income, education, answer]
51
+ end
52
+ end
53
+
54
+ workbook.add_worksheet(:name => "Summary") do |sheet|
55
+ pivot_table = Axlsx::PivotTable.new 'A1:B15', "A1:L31", workbook.worksheets[0]
56
+ pivot_table.rows = ['Answer']
57
+ pivot_table.data = [{:ref => "Member ID", :subtotal => "count"}]
58
+ sheet.pivot_tables << pivot_table
59
+ end
60
+
61
+ package.serialize("pivot_table.xlsx")
62
+ end
63
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby -w -s
2
+ # -*- coding: utf-8 -*-
3
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
4
+ require 'axlsx'
5
+
6
+ p = Axlsx::Package.new
7
+ p.workbook.add_worksheet(:name => 'Open Office') { |ws| ws.sheet_protection.password = 'fish' }
8
+ p.serialize 'sheet_protection.xlsx'
9
+
10
+
@@ -0,0 +1,63 @@
1
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib"
2
+
3
+ require 'axlsx'
4
+
5
+ Axlsx::Package.new do |p|
6
+ p.workbook do |wb|
7
+ styles = wb.styles
8
+ header = styles.add_style :bg_color => "DD", :sz => 16, :b => true, :alignment => {:horizontal => :center}
9
+ tbl_header = styles.add_style :b => true, :alignment => { :horizontal => :center }
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"
16
+
17
+ wb.add_worksheet do |sheet|
18
+ sheet.add_row
19
+ sheet.add_row [nil, "College Budget"], :style => [nil, header]
20
+ sheet.add_row
21
+ sheet.add_row [nil, "What's coming in this month.", nil, nil, "How am I doing"], :style => tbl_header
22
+ sheet.add_row [nil, "Item", "Amount", nil, "Item", "Amount"], :style => [nil, ind_header, col_header, nil, ind_header, col_header]
23
+ sheet.add_row [nil, "Estimated monthly net income", 500, nil, "Monthly income", "=C9"], :style => [nil, label, money, nil, label, money]
24
+ sheet.add_row [nil, "Financial aid", 100, nil, "Monthly expenses", "=C27"], :style => [nil, label, money, nil, label, money]
25
+ sheet.add_row [nil, "Allowance from mom & dad", 20000, nil, "Semester expenses", "=F19"], :style => [nil, label, money, nil, label, money]
26
+ sheet.add_row [nil, "Total", "=SUM(C6:C8)", nil, "Difference", "=F6 - SUM(F7:F8)"], :style => [nil, t_label, t_money, nil, t_label, t_money]
27
+ sheet.add_row
28
+ sheet.add_row [nil, "What's going out this month.", nil, nil, "Semester Costs"], :style => tbl_header
29
+ sheet.add_row [nil, "Item", "Amount", nil, "Item", "Amount"], :style => [nil, ind_header, col_header, nil, ind_header, col_header]
30
+ sheet.add_row [nil, "Rent", 650, nil, "Tuition", 200], :style => [nil, label, money, nil, label, money]
31
+ sheet.add_row [nil, "Utilities", 120, nil, "Lab fees", 50], :style => [nil, label, money, nil, label, money]
32
+ sheet.add_row [nil, "Cell phone", 100, nil, "Other fees", 10], :style => [nil, label, money, nil, label, money]
33
+ sheet.add_row [nil, "Groceries", 75, nil, "Books", 150], :style => [nil, label, money, nil, label, money]
34
+ sheet.add_row [nil, "Auto expenses", 0, nil, "Deposits", 0], :style => [nil, label, money, nil, label, money]
35
+ sheet.add_row [nil, "Student loans", 0, nil, "Transportation", 30], :style => [nil, label, money, nil, label, money]
36
+ sheet.add_row [nil, "Other loans", 350, nil, "Total", "=SUM(F13:F18)"], :style => [nil, label, money, nil, t_label, t_money]
37
+ sheet.add_row [nil, "Credit cards", 450], :style => [nil, label, money]
38
+ sheet.add_row [nil, "Insurance", 0], :style => [nil, label, money]
39
+ sheet.add_row [nil, "Laundry", 10], :style => [nil, label, money]
40
+ sheet.add_row [nil, "Haircuts", 0], :style => [nil, label, money]
41
+ sheet.add_row [nil, "Medical expenses", 0], :style => [nil, label, money]
42
+ sheet.add_row [nil, "Entertainment", 500], :style => [nil, label, money]
43
+ sheet.add_row [nil, "Miscellaneous", 0], :style => [nil, label, money]
44
+ sheet.add_row [nil, "Total", "=SUM(C13:C26)"], :style => [nil, t_label, t_money]
45
+ sheet.add_chart(Axlsx::Pie3DChart) do |chart|
46
+ chart.title = sheet["B11"]
47
+ chart.add_series :data => sheet["C13:C26"], :labels => sheet["B13:B26"]
48
+ chart.start_at 7, 2
49
+ chart.end_at 12, 15
50
+ end
51
+ sheet.add_chart(Axlsx::Bar3DChart, :barDir => :col) do |chart|
52
+ chart.title = sheet["E11"]
53
+ chart.add_series :labels => sheet["E13:E18"], :data => sheet["F13:F18"]
54
+ chart.start_at 7, 16
55
+ chart.end_at 12, 31
56
+ end
57
+ %w(B4:C4 E4:F4 B11:C11 E11:F11 B2:F2).each { |range| sheet.merge_cells(range) }
58
+ sheet.column_widths 2, nil, nil, 2, nil, nil, 2
59
+ end
60
+ end
61
+ p.use_shared_strings = true
62
+ p.serialize 'axlsx.xlsx'
63
+ end
data/examples/split.rb ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby -w -s
2
+ # -*- coding: utf-8 -*-
3
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
4
+ require 'axlsx'
5
+ p = Axlsx::Package.new
6
+ wb = p.workbook
7
+ wb.add_worksheet name: 'pane' do |sheet|
8
+ sheet.sheet_view.pane do |pane|
9
+ pane.top_left_cell = "B2"
10
+ pane.state = :frozen_split
11
+ pane.y_split = 2
12
+ pane.x_split = 1
13
+ pane.active_pane = :bottom_right
14
+ end
15
+ end
16
+ p.serialize 'pane.xlsx'
@@ -0,0 +1,66 @@
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
+ # A style that overrides top and left border style
52
+ override_border = wb.styles.add_style :border => { :style => :thin, :color =>"FAAC58", :edges => [:right, :top, :left] }, :border_top => { :style => :thick, :color => "01DF74" }, :border_left => { :color => "0101DF" }
53
+
54
+
55
+ wb.add_worksheet do |sheet|
56
+
57
+ # We then apply those styles positionally
58
+ sheet.add_row [123, "123", Time.now], style: [nil, large_font, predefined_format]
59
+ sheet.add_row [123, "123", Date.new(2012, 9, 14)], style: [large_font, nil, custom_format]
60
+ sheet.add_row [123, "123", Date.new(2000, 9, 12)] # This uses the axlsx default format_code (14)
61
+ sheet.add_row [123, "123", Time.now], style: [large_font, override_border, predefined_format]
62
+ end
63
+
64
+ end
65
+ p.serialize 'styles.xlsx'
66
+
@@ -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
+
@@ -0,0 +1,21 @@
1
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
+ require 'axlsx'
3
+ p = Axlsx::Package.new
4
+ p.workbook do |wb|
5
+ wb.styles do |s|
6
+ wrap_text = s.add_style :fg_color=> "FFFFFF",
7
+ :b => true,
8
+ :bg_color => "004586",
9
+ :sz => 12,
10
+ :border => { :style => :thin, :color => "00" },
11
+ :alignment => { :horizontal => :center,
12
+ :vertical => :center ,
13
+ :wrap_text => true}
14
+ wb.add_worksheet(:name => 'wrap text') do |sheet|
15
+ sheet.add_row ['Torp, White and Cronin'], :style => wrap_text
16
+ # Forcing the column to be a bit narrow so we can see if the text wrap.
17
+ sheet.column_info.first.width = 5
18
+ end
19
+ end
20
+ end
21
+ p.serialize 'wrap_text.xlsx'
data/lib/axlsx.rb ADDED
@@ -0,0 +1,168 @@
1
+ # encoding: UTF-8
2
+ require 'htmlentities'
3
+ require 'axlsx/version.rb'
4
+ require 'mimemagic'
5
+
6
+ require 'axlsx/util/simple_typed_list.rb'
7
+ require 'axlsx/util/constants.rb'
8
+ require 'axlsx/util/validators.rb'
9
+ require 'axlsx/util/accessors.rb'
10
+ require 'axlsx/util/serialized_attributes'
11
+ require 'axlsx/util/options_parser'
12
+ # to be included with parsable intitites.
13
+ #require 'axlsx/util/parser.rb'
14
+ require 'axlsx/util/string'
15
+ require 'axlsx/util/mime_type_utils'
16
+
17
+ require 'axlsx/stylesheet/styles.rb'
18
+
19
+ require 'axlsx/doc_props/app.rb'
20
+ require 'axlsx/doc_props/core.rb'
21
+ require 'axlsx/content_type/content_type.rb'
22
+ require 'axlsx/rels/relationships.rb'
23
+
24
+ require 'axlsx/drawing/drawing.rb'
25
+ require 'axlsx/workbook/workbook.rb'
26
+ require 'axlsx/package.rb'
27
+ #required gems
28
+ require 'nokogiri'
29
+ require 'zip'
30
+
31
+ #core dependencies
32
+ require 'bigdecimal'
33
+ require 'time'
34
+
35
+ #if object does not have this already, I am borrowing it from active_support.
36
+ # I am a very big fan of activesupports instance_values method, but do not want to require nor include the entire
37
+ # library just for this one method.
38
+ if !Object.respond_to?(:instance_values)
39
+ Object.send :public # patch for 1.8.7 as it uses private scope
40
+ Object.send :define_method, :instance_values do
41
+ Hash[instance_variables.map { |name| [name.to_s[1..-1], instance_variable_get(name)] }]
42
+ end
43
+ end
44
+
45
+ # xlsx generation with charts, images, automated column width, customizable styles
46
+ # and full schema validation. Axlsx excels at helping you generate beautiful
47
+ # Office Open XML Spreadsheet documents without having to understand the entire
48
+ # ECMA specification. Check out the README for some examples of how easy it is.
49
+ # Best of all, you can validate your xlsx file before serialization so you know
50
+ # for sure that anything generated is going to load on your client's machine.
51
+ module Axlsx
52
+
53
+ # determines the cell range for the items provided
54
+ def self.cell_range(cells, absolute=true)
55
+ return "" unless cells.first.is_a? Cell
56
+ cells = sort_cells(cells)
57
+ reference = "#{cells.first.reference(absolute)}:#{cells.last.reference(absolute)}"
58
+ if absolute
59
+ escaped_name = cells.first.row.worksheet.name.gsub '&apos;', "''"
60
+ "'#{escaped_name}'!#{reference}"
61
+ else
62
+ reference
63
+ end
64
+ end
65
+
66
+ # sorts the array of cells provided to start from the minimum x,y to
67
+ # the maximum x.y#
68
+ # @param [Array] cells
69
+ # @return [Array]
70
+ def self.sort_cells(cells)
71
+ cells.sort { |x, y| [x.index, x.row.row_index] <=> [y.index, y.row.row_index] }
72
+ end
73
+
74
+ #global reference html entity encoding
75
+ # @return [HtmlEntities]
76
+ def self.coder
77
+ @@coder ||= ::HTMLEntities.new
78
+ end
79
+
80
+ # returns the x, y position of a cell
81
+ def self.name_to_indices(name)
82
+ raise ArgumentError, 'invalid cell name' unless name.size > 1
83
+ # capitalization?!?
84
+ v = name[/[A-Z]+/].reverse.chars.reduce({:base=>1, :i=>0}) do |val, c|
85
+ val[:i] += ((c.bytes.first - 64) * val[:base]); val[:base] *= 26; val
86
+ end
87
+ [v[:i]-1, ((name[/[1-9][0-9]*/]).to_i)-1]
88
+ end
89
+
90
+ # converts the column index into alphabetical values.
91
+ # @note This follows the standard spreadsheet convention of naming columns A to Z, followed by AA to AZ etc.
92
+ # @return [String]
93
+ def self.col_ref(index)
94
+ chars = ''
95
+ while index >= 26 do
96
+ index, char = index.divmod(26)
97
+ chars.prepend((char + 65).chr)
98
+ index -= 1
99
+ end
100
+ chars.prepend((index + 65).chr)
101
+ chars
102
+ end
103
+
104
+ # @return [String] The alpha(column)numeric(row) reference for this sell.
105
+ # @example Relative Cell Reference
106
+ # ws.rows.first.cells.first.r #=> "A1"
107
+ def self.cell_r(c_index, r_index)
108
+ col_ref(c_index) << (r_index+1).to_s
109
+ end
110
+
111
+ # Creates an array of individual cell references based on an excel reference range.
112
+ # @param [String] range A cell range, for example A1:D5
113
+ # @return [Array]
114
+ def self.range_to_a(range)
115
+ range.match(/^(\w+?\d+)\:(\w+?\d+)$/)
116
+ start_col, start_row = name_to_indices($1)
117
+ end_col, end_row = name_to_indices($2)
118
+ (start_row..end_row).to_a.map do |row_num|
119
+ (start_col..end_col).to_a.map do |col_num|
120
+ cell_r(col_num, row_num)
121
+ end
122
+ end
123
+ end
124
+
125
+ # performs the increadible feat of changing snake_case to CamelCase
126
+ # @param [String] s The snake case string to camelize
127
+ # @return [String]
128
+ def self.camel(s="", all_caps = true)
129
+ s = s.to_s
130
+ s = s.capitalize if all_caps
131
+ s.gsub(/_(.)/){ $1.upcase }
132
+ end
133
+
134
+ # returns the provided string with all invalid control charaters
135
+ # removed.
136
+ # @param [String] str The string to process
137
+ # @return [String]
138
+ def self.sanitize(str)
139
+ str.delete!(CONTROL_CHARS)
140
+ str
141
+ end
142
+
143
+ # If value is boolean return 1 or 0
144
+ # else return the value
145
+ # @param [Object] value The value to process
146
+ # @return [Object]
147
+ def self.booleanize(value)
148
+ if value == true || value == false
149
+ value ? 1 : 0
150
+ else
151
+ value
152
+ end
153
+ end
154
+
155
+ # Instructs the serializer to not try to escape cell value input.
156
+ # This will give you a huge speed bonus, but if you content has <, > or other xml character data
157
+ # the workbook will be invalid and excel will complain.
158
+ def self.trust_input
159
+ @trust_input ||= false
160
+ end
161
+
162
+ # @param[Boolean] trust_me A boolean value indicating if the cell value content is to be trusted
163
+ # @return [Boolean]
164
+ # @see Axlsx::trust_input
165
+ def self.trust_input=(trust_me)
166
+ @trust_input = trust_me
167
+ end
168
+ end