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,39 @@
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
+ p.workbook do |wb|
7
+ # define your regular styles
8
+ styles = wb.styles
9
+ title = styles.add_style :sz => 15, :b => true, :u => true
10
+ default = styles.add_style :border => Axlsx::STYLE_THIN_BORDER
11
+ header = styles.add_style :bg_color => '00', :fg_color => 'FF', :b => true
12
+ money = styles.add_style :format_code => '#,###,##0', :border => Axlsx::STYLE_THIN_BORDER
13
+ percent = styles.add_style :num_fmt => Axlsx::NUM_FMT_PERCENT, :border => Axlsx::STYLE_THIN_BORDER
14
+
15
+ # define the style for conditional formatting - its the :dxf bit that counts!
16
+ profitable = styles.add_style :fg_color => 'FF428751', :sz => 12, :type => :dxf, :b => true
17
+
18
+ wb.add_worksheet(:name => 'Scaled Colors') do |ws|
19
+ ws.add_row ['A$$le Q1 Revenue Historical Analysis (USD)'], :style => title
20
+ ws.add_row
21
+ ws.add_row ['Quarter', 'Profit', '% of Total'], :style => header
22
+ ws.add_row ['Q1-2010', '15680000000', '=B4/SUM(B4:B7)'], :style => [default, money, percent]
23
+ ws.add_row ['Q1-2011', '26740000000', '=B5/SUM(B4:B7)'], :style => [default, money, percent]
24
+ ws.add_row ['Q1-2012', '46330000000', '=B6/SUM(B4:B7)'], :style => [default, money, percent]
25
+ ws.add_row ['Q1-2013(est)', '72230000000', '=B7/SUM(B4:B7)'], :style => [default, money, percent]
26
+
27
+ ws.merge_cells 'A1:C1'
28
+
29
+ # Apply conditional formatting to range B4:B7 in the worksheet
30
+ color_scale = Axlsx::ColorScale.new
31
+ ws.add_conditional_formatting 'B4:B7', { :type => :colorScale,
32
+ :operator => :greaterThan,
33
+ :formula => '27000000000',
34
+ :dxfId => profitable,
35
+ :priority => 1,
36
+ :color_scale => color_scale }
37
+ end
38
+ end
39
+ p.serialize 'scaled_colors.xlsx'
@@ -0,0 +1,37 @@
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
+ p.workbook do |wb|
7
+ # define your regular styles
8
+ styles = wb.styles
9
+ title = styles.add_style :sz => 15, :b => true, :u => true
10
+ default = styles.add_style :border => Axlsx::STYLE_THIN_BORDER
11
+ header = styles.add_style :bg_color => '00', :fg_color => 'FF', :b => true
12
+ money = styles.add_style :format_code => '#,###,##0', :border => Axlsx::STYLE_THIN_BORDER
13
+ percent = styles.add_style :num_fmt => Axlsx::NUM_FMT_PERCENT, :border => Axlsx::STYLE_THIN_BORDER
14
+
15
+ # define the style for conditional formatting - its the :dxf bit that counts!
16
+ profitable = styles.add_style :fg_color => 'FF428751', :sz => 12, :type => :dxf, :b => true
17
+
18
+ wb.add_worksheet(:name => 'Downtown traffic') do |ws|
19
+ ws.add_row ['A$$le Q1 Revenue Historical Analysis (USD)'], :style => title
20
+ ws.add_row
21
+ ws.add_row ['Quarter', 'Profit', '% of Total'], :style => header
22
+ ws.add_row ['Q1-2010', '15680000000', '=B4/SUM(B4:B7)'], :style => [default, money, percent]
23
+ ws.add_row ['Q1-2011', '26740000000', '=B5/SUM(B4:B7)'], :style => [default, money, percent]
24
+ ws.add_row ['Q1-2012', '46330000000', '=B6/SUM(B4:B7)'], :style => [default, money, percent]
25
+ ws.add_row ['Q1-2013(est)', '72230000000', '=B7/SUM(B4:B7)'], :style => [default, money, percent]
26
+
27
+ ws.merge_cells 'A1:C1'
28
+
29
+ # Apply conditional formatting to range B3:B7 in the worksheet
30
+ icon_set = Axlsx::IconSet.new
31
+ ws.add_conditional_formatting 'B3:B7', { :type => :iconSet,
32
+ :dxfId => profitable,
33
+ :priority => 1,
34
+ :icon_set => icon_set }
35
+ end
36
+ end
37
+ p.serialize 'stop_and_go.xlsx'
@@ -0,0 +1,50 @@
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 do |ws|
8
+ ws.add_data_validation("A10", {
9
+ :type => :whole,
10
+ :operator => :between,
11
+ :formula1 => '5',
12
+ :formula2 => '10',
13
+ :showErrorMessage => true,
14
+ :errorTitle => 'Wrong input',
15
+ :error => 'Only values between 5 and 10',
16
+ :errorStyle => :information,
17
+ :showInputMessage => true,
18
+ :promptTitle => 'Be carful!',
19
+ :prompt => 'Only values between 5 and 10'})
20
+
21
+ ws.add_data_validation("B10", {
22
+ :type => :textLength,
23
+ :operator => :greaterThan,
24
+ :formula1 => '10',
25
+ :showErrorMessage => true,
26
+ :errorTitle => 'Text is too long',
27
+ :error => 'Max text length is 10 characters',
28
+ :errorStyle => :stop,
29
+ :showInputMessage => true,
30
+ :promptTitle => 'Text length',
31
+ :prompt => 'Max text length is 10 characters'})
32
+
33
+ 8.times do |i|
34
+ ws.add_row [nil, nil, i*2]
35
+ end
36
+
37
+ ws.add_data_validation("C10", {
38
+ :type => :list,
39
+ :formula1 => 'C1:C8',
40
+ :showDropDown => false,
41
+ :showErrorMessage => true,
42
+ :errorTitle => '',
43
+ :error => 'Only values from C1:C8',
44
+ :errorStyle => :stop,
45
+ :showInputMessage => true,
46
+ :promptTitle => '',
47
+ :prompt => 'Only values from C1:C8'})
48
+ end
49
+
50
+ p.serialize 'data_validation.xlsx'
@@ -0,0 +1,875 @@
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
+ examples = []
8
+ examples << :basic
9
+ examples << :custom_styles
10
+ examples << :wrap_text
11
+ examples << :cell_style_override
12
+ examples << :custom_borders
13
+ examples << :surrounding_border
14
+ examples << :deep_custom_borders
15
+ examples << :row_column_style
16
+ examples << :fixed_column_width
17
+ examples << :height
18
+ examples << :outline_level
19
+ examples << :merge_cells
20
+ examples << :images
21
+ examples << :format_dates
22
+ examples << :mbcs
23
+ examples << :formula
24
+ examples << :auto_filter
25
+ examples << :data_types
26
+ examples << :override_data_types
27
+ examples << :hyperlinks
28
+ examples << :number_currency_format
29
+ examples << :venezuela_currency
30
+ examples << :bar_chart
31
+ examples << :chart_gridlines
32
+ examples << :pie_chart
33
+ examples << :line_chart
34
+ examples << :scatter_chart
35
+ examples << :tables
36
+ examples << :fit_to_page
37
+ examples << :hide_gridlines
38
+ examples << :repeated_header
39
+ examples << :defined_name
40
+ examples << :printing
41
+ examples << :header_footer
42
+ examples << :comments
43
+ examples << :panes
44
+ examples << :book_view
45
+ examples << :sheet_view
46
+ examples << :hiding_sheets
47
+ examples << :conditional_formatting
48
+ examples << :streaming
49
+ examples << :shared_strings
50
+ examples << :no_autowidth
51
+ examples << :cached_formula
52
+ examples << :page_breaks
53
+ examples << :rich_text
54
+ examples << :tab_color
55
+
56
+ p = Axlsx::Package.new
57
+ wb = p.workbook
58
+ #```
59
+
60
+ ## A Simple Workbook
61
+
62
+ #```ruby
63
+ if examples.include? :basic
64
+ wb.add_worksheet(:name => "Basic Worksheet") do |sheet|
65
+ sheet.add_row ["First Column", "Second", "Third"]
66
+ sheet.add_row [1, 2, 3]
67
+ sheet.add_row [' preserving whitespace']
68
+ end
69
+ end
70
+ #```
71
+
72
+ #Using Custom Styles
73
+
74
+ #```ruby
75
+ # Each cell allows a single, predified style.
76
+ # When using add_row, the value in the :style array at the same index as the cell's column will be applied to that cell.
77
+ # Alternatively, you can apply a style to an entire row by using an integer value for :style.
78
+ if examples.include? :custom_styles
79
+ wb.styles do |s|
80
+ black_cell = s.add_style :bg_color => "00", :fg_color => "FF", :sz => 14, :alignment => { :horizontal=> :center }
81
+ blue_cell = s.add_style :bg_color => "0000FF", :fg_color => "FF", :sz => 20, :alignment => { :horizontal=> :center }
82
+ wb.add_worksheet(:name => "Custom Styles") do |sheet|
83
+
84
+ # Applies the black_cell style to the first and third cell, and the blue_cell style to the second.
85
+ sheet.add_row ["Text Autowidth", "Second", "Third"], :style => [black_cell, blue_cell, black_cell]
86
+
87
+ # Applies the thin border to all three cells
88
+ sheet.add_row [1, 2, 3], :style => Axlsx::STYLE_THIN_BORDER
89
+ end
90
+ end
91
+ end
92
+
93
+
94
+ #```ruby
95
+ # A simple example of wrapping text. Seems this may not be working in Libre Office so here is an example for me to play with.
96
+ if examples.include? :wrap_text
97
+ wb.styles do |s|
98
+ wrap_text = s.add_style :fg_color=> "FFFFFF",
99
+ :b => true,
100
+ :bg_color => "004586",
101
+ :sz => 12,
102
+ :border => { :style => :thin, :color => "00" },
103
+ :alignment => { :horizontal => :center,
104
+ :vertical => :center ,
105
+ :wrap_text => true}
106
+ wb.add_worksheet(:name => 'wrap text') do |sheet|
107
+ sheet.add_row ['Torp, White and Cronin'], :style=>wrap_text
108
+ sheet.column_info.first.width = 5
109
+ end
110
+ end
111
+ end
112
+
113
+ ##Styling Cell Overrides
114
+
115
+ #```ruby
116
+ #Some of the style attributes can also be set at the cell level. Cell level styles take precedence over Custom Styles shown in the previous example.
117
+ if examples.include? :cell_style_override
118
+ wb.add_worksheet(:name => "Cell Level Style Overrides") do |sheet|
119
+
120
+ # this will set the font size for each cell.
121
+ sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4'], :sz => 16
122
+
123
+ sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
124
+ sheet.add_row %w(u shadow sz b i strike outline)
125
+ sheet.rows.last.cells[0].u = :double
126
+ sheet.rows.last.cells[1].shadow = true
127
+ sheet.rows.last.cells[2].sz = 20
128
+ sheet.rows.last.cells[3].b = true
129
+ sheet.rows.last.cells[4].i = true
130
+ sheet.rows.last.cells[5].strike = true
131
+ sheet.rows.last.cells[6].outline = 1
132
+ # You can also apply cell style overrides to a range of cells
133
+ sheet["A1:D1"].each { |c| c.color = "FF0000" }
134
+ sheet['A1:D2'].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
135
+ end
136
+ end
137
+ ##```
138
+
139
+ ##Using Custom Border Styles
140
+
141
+ #```ruby
142
+ #Axlsx defines a thin border style, but you can easily create and use your own.
143
+ if examples.include? :custom_borders
144
+ wb.styles do |s|
145
+ red_border = s.add_style :border => { :style => :thick, :color =>"FFFF0000", :edges => [:left, :right] }
146
+ blue_border = s.add_style :border => { :style => :thick, :color =>"FF0000FF"}
147
+
148
+ wb.add_worksheet(:name => "Custom Borders") do |sheet|
149
+ sheet.add_row ["wrap", "me", "Up in Red"], :style => red_border
150
+ sheet.add_row [1, 2, 3], :style => blue_border
151
+ end
152
+ end
153
+ end
154
+
155
+ #```ruby
156
+ # More Custom Borders
157
+ if examples.include? :surrounding_border
158
+
159
+ # Stuff like this is why I LOVE RUBY
160
+ # If you dont know about hash default values
161
+ # LEARN IT! LIVE IT! LOVE IT!
162
+ defaults = { :style => :thick, :color => "000000" }
163
+ borders = Hash.new do |hash, key|
164
+ hash[key] = wb.styles.add_style :border => defaults.merge( { :edges => key.to_s.split('_').map(&:to_sym) } )
165
+ end
166
+ top_row = [0, borders[:top_left], borders[:top], borders[:top], borders[:top_right]]
167
+ middle_row = [0, borders[:left], nil, nil, borders[:right]]
168
+ bottom_row = [0, borders[:bottom_left], borders[:bottom], borders[:bottom], borders[:bottom_right]]
169
+
170
+ wb.add_worksheet(:name => "Surrounding Border") do |ws|
171
+ ws.add_row []
172
+ ws.add_row ['', 1,2,3,4], :style => top_row
173
+ ws.add_row ['', 5,6,7,8], :style => middle_row
174
+ ws.add_row ['', 9, 10, 11, 12]
175
+
176
+ #This works too!
177
+ ws.rows.last.style = bottom_row
178
+
179
+ end
180
+ end
181
+
182
+ #```ruby
183
+ # Hacking border styles
184
+ if examples.include? :deep_custom_borders
185
+ wb.styles do |s|
186
+ top_bottom = s.add_style :border => { :style => :thick, :color =>"FFFF0000", :edges => [:top, :bottom] }
187
+ border = s.borders[s.cellXfs[top_bottom].borderId]
188
+ # edit existing border parts
189
+ border.prs.each do |part|
190
+ case part.name
191
+ when :top
192
+ part.color = Axlsx::Color.new(:rgb => "FFFF0000")
193
+ when :bottom
194
+ part.color = Axlsx::Color.new(:rgb => "FF00FF00")
195
+ end
196
+ end
197
+
198
+ border.prs << Axlsx::BorderPr.new(:name => :left, :color => Axlsx::Color.new(:rgb => '0000FF'), :style => :mediumDashed)
199
+ wb.add_worksheet(:name => 'hacked borders') do |sheet|
200
+ sheet.add_row [1,2,3], :style=>top_bottom
201
+ end
202
+ end
203
+ end
204
+ ##```
205
+
206
+
207
+ ##Styling Rows and Columns
208
+
209
+ #```ruby
210
+ if examples.include? :row_column_style
211
+ wb.styles do |s|
212
+ head = s.add_style :bg_color => "00", :fg_color => "FF"
213
+ percent = s.add_style :num_fmt => 9
214
+ wb.add_worksheet(:name => "Columns and Rows") do |sheet|
215
+ # Note: you must add rows to the document *BEFORE* applying column styles to them
216
+ sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4', 'col5']
217
+ sheet.add_row [1, 2, 0.3, 4, 5.0]
218
+ sheet.add_row [1, 2, 0.2, 4, 5.0]
219
+ sheet.add_row [1, 2, 0.1, 4, 5.0]
220
+
221
+ #apply the percent style to the column at index 2 skipping the first row.
222
+ sheet.col_style 2, percent, :row_offset => 1
223
+
224
+ # apply the head style to the first row.
225
+ sheet.row_style 0, head
226
+
227
+ #Hide the 5th column
228
+ sheet.column_info[4].hidden = true
229
+
230
+ #Set the second column outline level
231
+ sheet.column_info[1].outlineLevel = 2
232
+
233
+ sheet.rows[3].hidden = true
234
+ sheet.rows[1].outlineLevel = 2
235
+ end
236
+ end
237
+ end
238
+ ##```
239
+
240
+
241
+ ##Specifying Column Widths
242
+
243
+ #```ruby
244
+ if examples.include? :fixed_column_width
245
+ wb.add_worksheet(:name => "custom column widths") do |sheet|
246
+ sheet.add_row ["I use autowidth and am very wide", "I use a custom width and am narrow"]
247
+ sheet.add_row ['abcdefg', 'This is a very long text and should flow into the right cell', nil, 'xxx' ]
248
+ sheet.column_widths nil, 3, 5, nil
249
+ end
250
+ end
251
+
252
+
253
+ ##Specifying Row height
254
+
255
+ #```ruby
256
+ if examples.include? :height
257
+ wb.styles do |s|
258
+ head = s.add_style :bg_color => "00", :fg_color => "FF"
259
+ wb.add_worksheet(:name => "fixed row height") do |sheet|
260
+ sheet.add_row ["This row will have a fixed height", "It will overwite the default row height"], :height => 30
261
+ sheet.add_row ["This row can have a different height too"], :height => 10, :style => head
262
+ end
263
+ end
264
+ end
265
+
266
+
267
+ #```ruby
268
+ if examples.include? :outline_level
269
+ wb.add_worksheet(name: 'outline_level') do |sheet|
270
+ sheet.add_row [1, 2, 3, Time.now, 5, 149455.15]
271
+ sheet.add_row [1, 2, 5, 6, 5,14100.19]
272
+ sheet.add_row [9500002267, 1212, 1212, 5,14100.19]
273
+ sheet.outline_level_rows 0, 2
274
+ sheet.outline_level_columns 0, 2
275
+ end
276
+ end
277
+ ##```
278
+
279
+ ##Merging Cells.
280
+
281
+ #```ruby
282
+ if examples.include? :merge_cells
283
+ wb.add_worksheet(:name => 'Merging Cells') do |sheet|
284
+ # cell level style overides when adding cells
285
+ sheet.add_row ["col 1", "col 2", "col 3", "col 4"], :sz => 16
286
+ sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
287
+ sheet.add_row [2, 3, 4, "=SUM(A3:C3)"]
288
+ sheet.add_row ["total", "", "", "=SUM(D2:D3)"]
289
+ sheet.merge_cells("A4:C4")
290
+ sheet["A1:D1"].each { |c| c.color = "FF0000"}
291
+ sheet["A1:D4"].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
292
+ end
293
+ end
294
+ ##```
295
+
296
+ ##Add an Image with a hyperlink
297
+
298
+ #```ruby
299
+ if examples.include? :images
300
+ wb.add_worksheet(:name => "Image with Hyperlink") do |sheet|
301
+ img = File.expand_path('../image1.jpeg', __FILE__)
302
+ # specifying the :hyperlink option will add a hyper link to your image.
303
+ #
304
+ # @note - Numbers does not support this part of the specification.
305
+
306
+ sheet.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image|
307
+ image.width=720
308
+ image.height=666
309
+ image.hyperlink.tooltip = "Labeled Link"
310
+ image.start_at 0, 0
311
+ end
312
+
313
+ # position in block
314
+ sheet.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image|
315
+ image.start_at 22, 14
316
+ image.end_at 23, 17
317
+ end
318
+ # all in one go
319
+ sheet.add_image(:image_src => img, :start_at => [15, 33], :end_at => [20, 37], :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com")
320
+ end
321
+ end
322
+ #```
323
+
324
+ ##Using Custom Formatting and date1904
325
+
326
+ #```ruby
327
+ if examples.include? :format_dates
328
+ require 'date'
329
+ wb.styles do |s|
330
+ date = s.add_style(:format_code => "yyyy-mm-dd", :border => Axlsx::STYLE_THIN_BORDER)
331
+ padded = s.add_style(:format_code => "00#", :border => Axlsx::STYLE_THIN_BORDER)
332
+ percent = s.add_style(:format_code => "0000%", :border => Axlsx::STYLE_THIN_BORDER)
333
+ # wb.date1904 = true # Use the 1904 date system (Used by Excel for Mac < 2011)
334
+ wb.add_worksheet(:name => "Formatting Data") do |sheet|
335
+ sheet.add_row ["Custom Formatted Date", "Percent Formatted Float", "Padded Numbers"], :style => Axlsx::STYLE_THIN_BORDER
336
+ sheet.add_row [Date::strptime('2012-01-19','%Y-%m-%d'), 0.2, 32], :style => [date, percent, padded]
337
+ end
338
+ end
339
+ end
340
+ #```
341
+
342
+ ##Asian Language Support
343
+
344
+ #```ruby
345
+ if examples.include? :mbcs
346
+ wb.styles.fonts.first.name = 'Arial Unicode MS'
347
+ wb.add_worksheet(:name => "日本語でのシート名") do |sheet|
348
+ sheet.add_row ["日本語"]
349
+ sheet.add_row ["华语/華語"]
350
+ sheet.add_row ["한국어/조선말"]
351
+ end
352
+ end
353
+ ##```
354
+
355
+ ##Using formula
356
+
357
+ #```ruby
358
+ if examples.include? :formula
359
+ wb.add_worksheet(:name => "Using Formulas") do |sheet|
360
+ sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
361
+ sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
362
+ end
363
+ end
364
+ ##```
365
+
366
+ ##Auto Filter
367
+
368
+ #```ruby
369
+ if examples.include? :auto_filter
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
+ sheet.auto_filter.add_column 3, :filters, :filter_items => ['1.9.2', '1.8.7']
378
+ end
379
+ end
380
+ #```
381
+
382
+ ##Automatic cell types
383
+
384
+
385
+ #```ruby
386
+ if examples.include? :data_types
387
+ wb.add_worksheet(:name => "Automatic cell types") do |sheet|
388
+ date_format = wb.styles.add_style :format_code => 'YYYY-MM-DD'
389
+ time_format = wb.styles.add_style :format_code => 'hh:mm:ss'
390
+ sheet.add_row ["Date", "Time", "String", "Boolean", "Float", "Integer"]
391
+ sheet.add_row [Date.today, Time.now, "value", true, 0.1, 1], :style => [date_format, time_format]
392
+ end
393
+ end
394
+
395
+ #```ruby
396
+ if examples.include? :override_data_types
397
+ wb.add_worksheet(:name => "Override Data Type") do |sheet|
398
+ sheet.add_row ['dont eat my zeros!', '0088'] , :types => [nil, :string]
399
+ end
400
+ end
401
+ # Hyperlinks in worksheet
402
+ if examples.include? :hyperlinks
403
+ wb.add_worksheet(:name => 'hyperlinks') do |sheet|
404
+ # external references
405
+ sheet.add_row ['axlsx']
406
+ sheet.add_hyperlink :location => 'https://github.com/randym/axlsx', :ref => sheet.rows.first.cells.first
407
+ # internal references
408
+ sheet.add_hyperlink :location => "'Next Sheet'!A1", :ref => 'A2', :target => :sheet
409
+ sheet.add_row ['next sheet']
410
+ end
411
+
412
+ wb.add_worksheet(:name => 'Next Sheet') do |sheet|
413
+ sheet.add_row ['hello!']
414
+ end
415
+ end
416
+ ###```
417
+
418
+ ##Number formatting and currency
419
+ if examples.include? :number_currency_format
420
+ wb.add_worksheet(:name => "Formats and Currency") do |sheet|
421
+ currency = wb.styles.add_style :num_fmt => 5
422
+ red_negative = wb.styles.add_style :num_fmt => 8
423
+ comma = wb.styles.add_style :num_fmt => 3
424
+ super_funk = wb.styles.add_style :format_code => '[Green]#'
425
+ sheet.add_row %w(Currency RedNegative Comma Custom)
426
+ sheet.add_row [1500, -122.34, 123456789, 594829], :style=> [currency, red_negative, comma, super_funk]
427
+ end
428
+ end
429
+
430
+ ## Venezuala currency
431
+ if examples.include? :venezuela_currency
432
+ wb.add_worksheet(:name => 'Venezuala_currency') do |sheet|
433
+ number = wb.styles.add_style :format_code => '#.##0\,00'
434
+ sheet.add_row [2.5] , :style => [number]
435
+ end
436
+ end
437
+
438
+ ##Generating A Bar Chart
439
+
440
+ #```ruby
441
+ if examples.include? :bar_chart
442
+ wb.add_worksheet(:name => "Bar Chart") do |sheet|
443
+ sheet.add_row ["A Simple Bar Chart"]
444
+ %w(first second third).each { |label| sheet.add_row [label, rand(24)+1] }
445
+ sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A6", :end_at => "F20") do |chart|
446
+ chart.add_series :data => sheet["B2:B4"], :labels => sheet["A2:A4"], :title => sheet["A1"], :colors => ["00FF00", "0000FF"]
447
+ end
448
+ end
449
+ end
450
+
451
+ ##```
452
+
453
+ ##Hide Gridlines in chart
454
+
455
+ #```ruby
456
+ if examples.include? :chart_gridlines
457
+ wb.add_worksheet(:name => "Chart With No Gridlines") do |sheet|
458
+ sheet.add_row ["Bar Chart without gridlines"]
459
+ %w(first second third).each { |label| sheet.add_row [label, rand(24)+1] }
460
+ sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A6", :end_at => "F20") do |chart|
461
+ chart.add_series :data => sheet["B2:B4"], :labels => sheet["A2:A4"], :colors => ["00FF00", "FF0000"]
462
+ chart.valAxis.gridlines = false
463
+ chart.catAxis.gridlines = false
464
+ end
465
+ end
466
+ end
467
+ #```
468
+
469
+ ##Generating A Pie Chart
470
+
471
+ #```ruby
472
+ if examples.include? :pie_chart
473
+ wb.add_worksheet(:name => "Pie Chart") do |sheet|
474
+ sheet.add_row ["Simple Pie Chart"]
475
+ %w(first second third).each { |label| sheet.add_row [label, rand(24)+1] }
476
+ sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,5], :end_at => [10, 20], :title => "example 3: Pie Chart") do |chart|
477
+ chart.add_series :data => sheet["B2:B4"], :labels => sheet["A2:A4"], :colors => ['FF0000', '00FF00', '0000FF']
478
+ end
479
+ end
480
+ end
481
+ #```
482
+
483
+ ##Generating A Line Chart
484
+
485
+ #```ruby
486
+ if examples.include? :line_chart
487
+ wb.add_worksheet(:name => "Line Chart") do |sheet|
488
+ sheet.add_row ["Simple Line Chart"]
489
+ sheet.add_row %w(first second)
490
+ 4.times do
491
+ sheet.add_row [ rand(24)+1, rand(24)+1]
492
+ end
493
+ sheet.add_chart(Axlsx::Line3DChart, :title => "Simple 3D Line Chart", :rotX => 30, :rotY => 20) do |chart|
494
+ chart.start_at 0, 5
495
+ chart.end_at 10, 20
496
+ chart.add_series :data => sheet["A3:A6"], :title => sheet["A2"], :color => "0000FF"
497
+ chart.add_series :data => sheet["B3:B6"], :title => sheet["B2"], :color => "FF0000"
498
+ chart.catAxis.title = 'X Axis'
499
+ chart.valAxis.title = 'Y Axis'
500
+ end
501
+ sheet.add_chart(Axlsx::LineChart, :title => "Simple Line Chart", :rotX => 30, :rotY => 20) do |chart|
502
+ chart.start_at 0, 21
503
+ chart.end_at 10, 41
504
+ chart.add_series :data => sheet["A3:A6"], :title => sheet["A2"], :color => "FF0000", :show_marker => true, :smooth => true
505
+ chart.add_series :data => sheet["B3:B6"], :title => sheet["B2"], :color => "00FF00"
506
+ chart.catAxis.title = 'X Axis'
507
+ chart.valAxis.title = 'Y Axis'
508
+ end
509
+
510
+ end
511
+ end
512
+ #```
513
+
514
+ ##Generating A Scatter Chart
515
+
516
+ #```ruby
517
+ if examples.include? :scatter_chart
518
+ wb.add_worksheet(:name => "Scatter Chart") do |sheet|
519
+ sheet.add_row ["First", 1, 5, 7, 9]
520
+ sheet.add_row ["", 1, 25, 49, 81]
521
+ sheet.add_row ["Second", 5, 2, 14, 9]
522
+ sheet.add_row ["", 5, 10, 15, 20]
523
+ sheet.add_chart(Axlsx::ScatterChart, :title => "example 7: Scatter Chart") do |chart|
524
+ chart.start_at 0, 4
525
+ chart.end_at 10, 19
526
+ chart.add_series :xData => sheet["B1:E1"], :yData => sheet["B2:E2"], :title => sheet["A1"], :color => "FF0000"
527
+ chart.add_series :xData => sheet["B3:E3"], :yData => sheet["B4:E4"], :title => sheet["A3"], :color => "00FF00"
528
+ end
529
+ end
530
+ end
531
+ #```
532
+
533
+
534
+ ##Tables
535
+
536
+ #```ruby
537
+ if examples.include? :tables
538
+ wb.add_worksheet(:name => "Table") do |sheet|
539
+ sheet.add_row ["Build Matrix"]
540
+ sheet.add_row ["Build", "Duration", "Finished", "Rvm"]
541
+ sheet.add_row ["19.1", "1 min 32 sec", "about 10 hours ago", "1.8.7"]
542
+ sheet.add_row ["19.2", "1 min 28 sec", "about 10 hours ago", "1.9.2"]
543
+ sheet.add_row ["19.3", "1 min 35 sec", "about 10 hours ago", "1.9.3"]
544
+ sheet.add_table "A2:D5", :name => 'Build Matrix', :style_info => { :name => "TableStyleMedium23" }
545
+ end
546
+ end
547
+ #```
548
+
549
+
550
+ ##Fit to page printing
551
+
552
+ #```ruby
553
+ if examples.include? :fit_to_page
554
+ wb.add_worksheet(:name => "fit to page") do |sheet|
555
+ sheet.add_row ['this all goes on one page']
556
+ sheet.page_setup.fit_to :width => 1, :height => 1
557
+ end
558
+ end
559
+ ##```
560
+
561
+
562
+ ##Hide Gridlines in worksheet
563
+
564
+ #```ruby
565
+ if examples.include? :hide_gridlines
566
+ wb.add_worksheet(:name => "No Gridlines") do |sheet|
567
+ sheet.add_row ["This", "Sheet", "Hides", "Gridlines"]
568
+ sheet.sheet_view.show_grid_lines = false
569
+ end
570
+ end
571
+ ##```
572
+
573
+ # Repeat printing of header rows.
574
+ #```ruby
575
+ if examples.include? :repeated_header
576
+ wb.add_worksheet(:name => "repeated header") do |sheet|
577
+ sheet.add_row %w(These Column Header Will Render On Every Printed Sheet)
578
+ 200.times { sheet.add_row %w(1 2 3 4 5 6 7 8) }
579
+ wb.add_defined_name("'repeated header'!$1:$1", :local_sheet_id => sheet.index, :name => '_xlnm.Print_Titles')
580
+ end
581
+ end
582
+
583
+ # Defined Names in formula
584
+ if examples.include? :defined_name
585
+ wb.add_worksheet(:name => 'defined name') do |sheet|
586
+ sheet.add_row [1, 2, 17, '=FOOBAR']
587
+ wb.add_defined_name("'defined name'!$C1", :local_sheet_id => sheet.index, :name => 'FOOBAR')
588
+ end
589
+ end
590
+
591
+ # Sheet Protection and excluding cells from locking.
592
+ if examples.include? :sheet_protection
593
+ unlocked = wb.styles.add_style :locked => false
594
+ wb.add_worksheet(:name => 'Sheet Protection') do |sheet|
595
+ sheet.sheet_protection.password = 'fish'
596
+ sheet.add_row [1, 2 ,3] # These cells will be locked
597
+ sheet.add_row [4, 5, 6], :style => unlocked # these cells will not!
598
+ end
599
+ end
600
+
601
+ ##Specify page margins and other options for printing
602
+
603
+ #```ruby
604
+ if examples.include? :printing
605
+ margins = {:left => 3, :right => 3, :top => 1.2, :bottom => 1.2, :header => 0.7, :footer => 0.7}
606
+ setup = {:fit_to_width => 1, :orientation => :landscape, :paper_width => "297mm", :paper_height => "210mm"}
607
+ options = {:grid_lines => true, :headings => true, :horizontal_centered => true}
608
+ wb.add_worksheet(:name => "print margins", :page_margins => margins, :page_setup => setup, :print_options => options) do |sheet|
609
+ sheet.add_row ["this sheet uses customized print settings"]
610
+ end
611
+ end
612
+ #```
613
+
614
+ ## Add headers and footers to a worksheet
615
+ #``` ruby
616
+ if examples.include? :header_footer
617
+ header_footer = {:different_first => false, :odd_header => '&L&F : &A&R&D &T', :odd_footer => '&C&Pof&N'}
618
+ wb.add_worksheet(:name => "header footer", :header_footer => header_footer) do |sheet|
619
+ sheet.add_row ["this sheet has a header and a footer"]
620
+ end
621
+ end
622
+ #```
623
+
624
+ ## Add Comments to your spreadsheet
625
+ #``` ruby
626
+ if examples.include? :comments
627
+ wb.add_worksheet(:name => 'comments') do |sheet|
628
+ sheet.add_row ['Can we build it?']
629
+ sheet.add_comment :ref => 'A1', :author => 'Bob', :text => 'Yes We Can!'
630
+ sheet.add_comment :ref => 'A2', :author => 'Bob', :text => 'Yes We Can! - but I dont think you need to know about it!', :visible => false
631
+
632
+ end
633
+ end
634
+
635
+ ## Frozen/Split panes
636
+ ## ``` ruby
637
+ if examples.include? :panes
638
+ wb.add_worksheet(:name => 'panes') do |sheet|
639
+ sheet.add_row(['', (0..99).map { |i| "column header #{i}" }].flatten )
640
+ 100.times.with_index { |index| sheet << ["row header", (0..index).to_a].flatten }
641
+ sheet.sheet_view.pane do |pane|
642
+ pane.top_left_cell = "B2"
643
+ pane.state = :frozen_split
644
+ pane.y_split = 1
645
+ pane.x_split = 1
646
+ pane.active_pane = :bottom_right
647
+ end
648
+ end
649
+ end
650
+
651
+ if examples.include? :sheet_view
652
+ ws = wb.add_worksheet(:name => 'SheetView - Split')
653
+ ws.sheet_view do |vs|
654
+ vs.pane do |pane|
655
+ pane.active_pane = :top_right
656
+ pane.state = :split
657
+ pane.x_split = 11080
658
+ pane.y_split = 5000
659
+ pane.top_left_cell = 'C44'
660
+ end
661
+
662
+ vs.add_selection(:top_left, { :active_cell => 'A2', :sqref => 'A2' })
663
+ vs.add_selection(:top_right, { :active_cell => 'I10', :sqref => 'I10' })
664
+ vs.add_selection(:bottom_left, { :active_cell => 'E55', :sqref => 'E55' })
665
+ vs.add_selection(:bottom_right, { :active_cell => 'I57', :sqref => 'I57' })
666
+ end
667
+
668
+ ws = wb.add_worksheet :name => "Sheetview - Frozen"
669
+ ws.sheet_view do |vs|
670
+ vs.pane do |pane|
671
+ pane.state = :frozen
672
+ pane.x_split = 3
673
+ pane.y_split = 4
674
+ end
675
+ end
676
+ end
677
+
678
+ ## Book Views
679
+ #
680
+ ## Book views let you specify which sheet the show as active when the user opens the work book as well as a bunch of other
681
+ ## tuning values for the UI @see Axlsx::WorkbookView
682
+ ## ```ruby
683
+ if examples.include? :book_view
684
+ # when you open example.xml the second sheet is selected, and the horizontal scroll bar is much smaller showing more sheets
685
+ wb.add_view tab_ratio: 800, active_tab: 1
686
+ end
687
+
688
+ ## Hiding Sheets
689
+ ##
690
+ ## Sheets can be hidden with the state attribute
691
+ if examples.include? :hiding_sheets
692
+ wb.add_worksheet name: 'hidden', state: :hidden do |sheet|
693
+ sheet.add_row ['you cant see me!']
694
+ end
695
+ wb.add_worksheet name: 'very hidden', state: :very_hidden do |sheet|
696
+ sheet.add_row ['you really cant see me!']
697
+ end
698
+ end
699
+ # conditional formatting
700
+ #
701
+ if examples.include? :conditional_formatting
702
+ percent = wb.styles.add_style(:format_code => "0.00%", :border => Axlsx::STYLE_THIN_BORDER)
703
+ money = wb.styles.add_style(:format_code => '0,000', :border => Axlsx::STYLE_THIN_BORDER)
704
+ status = wb.styles.add_style(:border => Axlsx::STYLE_THIN_BORDER)
705
+
706
+ # define the style for conditional formatting
707
+ profitable = wb.styles.add_style( :fg_color => "FF428751", :type => :dxf )
708
+ unprofitable = wb.styles.add_style( :fg_color => "FF0000", :type => :dxf )
709
+
710
+ wb.add_worksheet(:name => "Conditional Cell Is") do |sheet|
711
+
712
+ # Generate 20 rosheet of data
713
+ sheet.add_row ["Previous Year Quarterly Profits (JPY)"]
714
+ sheet.add_row ["Quarter", "Profit", "% of Total"]
715
+ offset = 3
716
+ rosheet = 20
717
+ offset.upto(rosheet + offset) do |i|
718
+ sheet.add_row ["Q#{i}", 10000*((rosheet/2-i) * (rosheet/2-i)), "=100*B#{i}/SUM(B3:B#{rosheet+offset})"], :style=>[nil, money, percent]
719
+ end
720
+
721
+ # Apply conditional formatting to range B3:B100 in the worksheet
722
+ sheet.add_conditional_formatting("B3:B100", { :type => :cellIs, :operator => :greaterThan, :formula => "100000", :dxfId => profitable, :priority => 1 })
723
+ # Apply conditional using the between operator; NOTE: supply an array to :formula for between/notBetween
724
+ sheet.add_conditional_formatting("C3:C100", { :type => :cellIs, :operator => :between, :formula => ["0.00%","100.00%"], :dxfId => unprofitable, :priority => 1 })
725
+ end
726
+
727
+ wb.add_worksheet(:name => "Conditional Color Scale") do |sheet|
728
+ sheet.add_row ["Previous Year Quarterly Profits (JPY)"]
729
+ sheet.add_row ["Quarter", "Profit", "% of Total"]
730
+ offset = 3
731
+ rosheet = 20
732
+ offset.upto(rosheet + offset) do |i|
733
+ sheet.add_row ["Q#{i}", 10000*((rosheet/2-i) * (rosheet/2-i)), "=100*B#{i}/SUM(B3:B#{rosheet+offset})"], :style=>[nil, money, percent]
734
+ end
735
+ # color scale has two_tone and three_tone class methods to setup the excel defaults (2011)
736
+ # alternatively, you can pass in {:type => [:min, :max, :percent], :val => [whatever], :color =>[Some RGB String] to create a customized color scale object
737
+
738
+ color_scale = Axlsx::ColorScale.three_tone
739
+ sheet.add_conditional_formatting("B3:B100", { :type => :colorScale, :operator => :greaterThan, :formula => "100000", :dxfId => profitable, :priority => 1, :color_scale => color_scale })
740
+ end
741
+
742
+
743
+ wb.add_worksheet(:name => "Conditional Data Bar") do |sheet|
744
+ sheet.add_row ["Previous Year Quarterly Profits (JPY)"]
745
+ sheet.add_row ["Quarter", "Profit", "% of Total"]
746
+ offset = 3
747
+ rows = 20
748
+ offset.upto(rows + offset) do |i|
749
+ sheet.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent]
750
+ end
751
+ # Apply conditional formatting to range B3:B100 in the worksheet
752
+ data_bar = Axlsx::DataBar.new
753
+ sheet.add_conditional_formatting("B3:B100", { :type => :dataBar, :dxfId => profitable, :priority => 1, :data_bar => data_bar })
754
+ end
755
+
756
+ wb.add_worksheet(:name => "Conditional Format Icon Set") do |sheet|
757
+ sheet.add_row ["Previous Year Quarterly Profits (JPY)"]
758
+ sheet.add_row ["Quarter", "Profit", "% of Total"]
759
+ offset = 3
760
+ rows = 20
761
+ offset.upto(rows + offset) do |i|
762
+ sheet.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent]
763
+ end
764
+ # Apply conditional formatting to range B3:B100 in the worksheet
765
+ icon_set = Axlsx::IconSet.new
766
+ sheet.add_conditional_formatting("B3:B100", { :type => :iconSet, :dxfId => profitable, :priority => 1, :icon_set => icon_set })
767
+ end
768
+
769
+ wb.add_worksheet(:name => "Contains Text") do |sheet|
770
+ sheet.add_row ["Previous Year Quarterly Profits (JPY)"]
771
+ sheet.add_row ["Quarter", "Profit", "% of Total", "Status"]
772
+ offset = 3
773
+ rows = 20
774
+ offset.upto(rows + offset) do |i|
775
+ sheet.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})", (10000*((rows/2-i) * (rows/2-i))) > 100000 ? "PROFIT" : "LOSS"], :style=>[nil, money, percent, status]
776
+ end
777
+ # Apply conditional formatting to range D3:D100 in the worksheet to match words.
778
+ sheet.add_conditional_formatting("D3:D100", { :type => :containsText, :operator => :equal, :text => "PROFIT", :dxfId => profitable, :priority => 1 })
779
+ sheet.add_conditional_formatting("D3:D100", { :type => :containsText, :operator => :equal, :text => "LOSS", :dxfId => unprofitable, :priority => 1 })
780
+ end
781
+ end
782
+
783
+ # Page Breaks
784
+ if examples.include? :page_breaks
785
+ ws = wb.add_worksheet(:name => "page breaks") do |sheet|
786
+ sheet.add_row ["A"] * 10
787
+ sheet.add_row ["A"] * 10
788
+ sheet.add_page_break("B2")
789
+ sheet.sheet_view.view = :page_layout # so you can see the breaks!
790
+ end
791
+ end
792
+
793
+ #Validate and Serialize
794
+
795
+ #```ruby
796
+ # Serialize directly to file
797
+
798
+ p.serialize("example.xlsx")
799
+
800
+ # or
801
+
802
+ #Serialize to a stream
803
+ if examples.include? :streaming
804
+ s = p.to_stream()
805
+ File.open('example_streamed.xlsx', 'w') { |f| f.write(s.read) }
806
+ end
807
+ #```
808
+
809
+ ##Using Shared Strings
810
+
811
+ #```ruby
812
+ # This is required by Numbers
813
+ if examples.include? :shared_strings
814
+ p.use_shared_strings = true
815
+ p.serialize("shared_strings_example.xlsx")
816
+ end
817
+ #```
818
+
819
+ #```ruby
820
+ if examples.include? :no_autowidth
821
+ p = Axlsx::Package.new
822
+ p.use_autowidth = false
823
+ wb = p.workbook
824
+ wb.add_worksheet(:name => "Manual Widths") do | sheet |
825
+ sheet.add_row ['oh look! no autowidth']
826
+ end
827
+ p.serialize("no-use_autowidth.xlsx")
828
+ end
829
+ #```
830
+
831
+ #```ruby
832
+ if examples.include? :cached_formula
833
+ p = Axlsx::Package.new
834
+ p.use_shared_strings = true
835
+ wb = p.workbook
836
+ wb.add_worksheet(:name => "cached formula") do | sheet |
837
+ sheet.add_row [1, 2, '=A1+B1'], :formula_values => [nil, nil, 3]
838
+ end
839
+ p.serialize 'cached_formula.xlsx'
840
+ end
841
+ #```
842
+
843
+ #```ruby
844
+ if examples.include? :rich_text
845
+ p = Axlsx::Package.new
846
+ p.use_shared_strings = true
847
+ wb = p.workbook
848
+ wrap_text = wb.styles.add_style({:alignment => {:horizontal => :center, :vertical => :center, :wrap_text => true}} )
849
+ rt = Axlsx::RichText.new
850
+ rt.add_run('I\'m bold, ', :b => true)
851
+ rt.add_run('I\'m italic, ', :i => true)
852
+ rt.add_run('I\'m strike' + "\n", :strike => true)
853
+ rt.add_run('I\'m bold, italic and strike' + "\n", :b => true, :i => true, :strike => true)
854
+ rt.add_run('I\'m style-less :D')
855
+ wb.add_worksheet(:name => "RichText") do | sheet |
856
+ sheet.add_row [rt], :style => wrap_text
857
+ end
858
+ p.serialize 'rich_text.xlsx'
859
+ end
860
+ #```
861
+
862
+ ##Change tab color of sheet
863
+
864
+ #```ruby
865
+ if examples.include? :tab_color
866
+ p = Axlsx::Package.new
867
+ p.use_shared_strings = true
868
+ wb = p.workbook
869
+ wb.add_worksheet(:name => "Change Tab Color") do |sheet|
870
+ sheet.add_row ["Check", "out", "the", "Tab Color", "below!"]
871
+ sheet.sheet_pr.tab_color = "FFFF6666"
872
+ end
873
+ p.serialize 'tab_color.xlsx'
874
+ end
875
+ ##```