axlsx-alt 3.0.0

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