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,35 @@
1
+ module Axlsx
2
+
3
+ # The Break class stores the details for row and column page breaks.
4
+ # @see RowBreaks, ColBreaks
5
+ class Break
6
+
7
+ include Axlsx::OptionsParser
8
+ include Axlsx::Accessors
9
+ include Axlsx::SerializedAttributes
10
+
11
+ # Creates a new Break object
12
+ # @param options A hash of attribute options for this break.
13
+ # @option options [Integer] id Zero-based row or column Id of the page break. Breaks occur above the specified row and left of the specified column.
14
+ # @option options [Integer] min Zero-based index of start row or column of the break. For row breaks, specifies column index; for column breaks, specifies row index.
15
+ # @option options [Integer] max Zero-based index of end row or column of the break. For row breaks, specifies column index; for column breaks, specifies row index.
16
+ # @option options [Boolean] man Manual Break flag. 1 means the break is a manually inserted break.
17
+ # @option option [Boolean] pt Flag indicating that a PivotTable created this break.
18
+ def initialize(options={})
19
+ parse_options options
20
+ yield self if block_given?
21
+ end
22
+
23
+ unsigned_int_attr_accessor :id, :min, :max
24
+
25
+ boolean_attr_accessor :man, :pt
26
+
27
+ serializable_attributes :id, :min, :max, :man, :pt
28
+
29
+ # serializes the break to xml
30
+ def to_xml_string(str='')
31
+ serialized_tag('brk', str)
32
+ end
33
+ end
34
+ end
35
+
@@ -0,0 +1,478 @@
1
+ # encoding: UTF-8
2
+ require 'cgi'
3
+ module Axlsx
4
+ # A cell in a worksheet.
5
+ # Cell stores inforamation requried to serialize a single worksheet cell to xml. You must provde the Row that the cell belongs to and the cells value. The data type will automatically be determed if you do not specify the :type option. The default style will be applied if you do not supply the :style option. Changing the cell's type will recast the value to the type specified. Altering the cell's value via the property accessor will also automatically cast the provided value to the cell's type.
6
+ # @note The recommended way to generate cells is via Worksheet#add_row
7
+ #
8
+ # @see Worksheet#add_row
9
+ class Cell
10
+
11
+ include Axlsx::OptionsParser
12
+
13
+ # @param [Row] row The row this cell belongs to.
14
+ # @param [Any] value The value associated with this cell.
15
+ # @option options [Symbol] type The intended data type for this cell. If not specified the data type will be determined internally based on the vlue provided.
16
+ # @option options [Integer] style The index of the cellXfs item to be applied to this cell. If not specified, the default style (0) will be applied.
17
+ # @option options [String] font_name
18
+ # @option options [Integer] charset
19
+ # @option options [String] family
20
+ # @option options [Boolean] b
21
+ # @option options [Boolean] i
22
+ # @option options [Boolean] strike
23
+ # @option options [Boolean] outline
24
+ # @option options [Boolean] shadow
25
+ # @option options [Boolean] condense
26
+ # @option options [Boolean] extend
27
+ # @option options [Boolean] u
28
+ # @option options [Symbol] vertAlign must be one of :baseline, :subscript, :superscript
29
+ # @option options [Integer] sz
30
+ # @option options [String] color an 8 letter rgb specification
31
+ # @option options [Number] formula_value The value to cache for a formula cell.
32
+ # @option options [Symbol] scheme must be one of :none, major, :minor
33
+ def initialize(row, value = nil, options = {})
34
+ @row = row
35
+ # Do not use instance vars if not needed to use less RAM
36
+ # And do not call parse_options on frequently used options
37
+ # to get less GC cycles
38
+ type = options.delete(:type) || cell_type_from_value(value)
39
+ self.type = type unless type == :string
40
+
41
+
42
+ val = options.delete(:style)
43
+ self.style = val unless val.nil? || val == 0
44
+ val = options.delete(:formula_value)
45
+ self.formula_value = val unless val.nil?
46
+
47
+ parse_options(options)
48
+
49
+ self.value = value
50
+ value.cell = self if contains_rich_text?
51
+ end
52
+
53
+ # this is the cached value for formula cells. If you want the values to render in iOS/Mac OSX preview
54
+ # you need to set this.
55
+ attr_accessor :formula_value
56
+
57
+ # An array of available inline styes.
58
+ # TODO change this to a hash where each key defines attr name and validator (and any info the validator requires)
59
+ # then move it out to a module so we can re-use in in other classes.
60
+ # needs to define bla=(v) and bla methods on the class that hook into a
61
+ # set_attr method that kicks the suplied validator and updates the instance_variable
62
+ # for the key
63
+ INLINE_STYLES = [:value, :type, :font_name, :charset,
64
+ :family, :b, :i, :strike, :outline,
65
+ :shadow, :condense, :extend, :u,
66
+ :vertAlign, :sz, :color, :scheme].freeze
67
+
68
+ # An array of valid cell types
69
+ CELL_TYPES = [:date, :time, :float, :integer, :richtext,
70
+ :string, :boolean, :iso_8601, :text].freeze
71
+
72
+ # The index of the cellXfs item to be applied to this cell.
73
+ # @return [Integer]
74
+ # @see Axlsx::Styles
75
+ def style
76
+ defined?(@style) ? @style : 0
77
+ end
78
+
79
+ # The row this cell belongs to.
80
+ # @return [Row]
81
+ attr_reader :row
82
+
83
+ # The cell's data type.
84
+ # Changing the type for a cell will recast the value into that type. If no type option is specified in the constructor, the type is
85
+ # automatically determed.
86
+ # @see Cell#cell_type_from_value
87
+ # @return [Symbol] The type of data this cell's value is cast to.
88
+ # @raise [ArgumentExeption] Cell.type must be one of [:date, time, :float, :integer, :string, :boolean]
89
+ # @note
90
+ # If the value provided cannot be cast into the type specified, type is changed to :string and the following logic is applied.
91
+ # :string to :integer or :float, type conversions always return 0 or 0.0
92
+ # :string, :integer, or :float to :time conversions always return the original value as a string and set the cells type to :string.
93
+ # No support is currently implemented for parsing time strings.
94
+ def type
95
+ defined?(@type) ? @type : :string
96
+ end
97
+
98
+ # @see type
99
+ def type=(v)
100
+ RestrictionValidator.validate :cell_type, CELL_TYPES, v
101
+ @type = v
102
+ self.value = @value unless !defined?(@value) || @value.nil?
103
+ end
104
+
105
+ # The value of this cell.
106
+ # @return [String, Integer, Float, Time, Boolean] casted value based on cell's type attribute.
107
+ attr_reader :value
108
+
109
+ # @see value
110
+ def value=(v)
111
+ #TODO: consider doing value based type determination first?
112
+ @value = cast_value(v)
113
+ end
114
+
115
+ # Indicates that the cell has one or more of the custom cell styles applied.
116
+ # @return [Boolean]
117
+ def is_text_run?
118
+ defined?(@is_text_run) && @is_text_run && !contains_rich_text?
119
+ end
120
+
121
+ def contains_rich_text?
122
+ type == :richtext
123
+ end
124
+
125
+ # Indicates if the cell is good for shared string table
126
+ def plain_string?
127
+ (type == :string || type == :text) && # String typed
128
+ !is_text_run? && # No inline styles
129
+ !@value.nil? && # Not nil
130
+ !@value.empty? && # Not empty
131
+ !@value.start_with?(?=) # Not a formula
132
+ end
133
+
134
+ # The inline font_name property for the cell
135
+ # @return [String]
136
+ attr_reader :font_name
137
+ # @see font_name
138
+ def font_name=(v) set_run_style :validate_string, :font_name, v; end
139
+
140
+ # The inline charset property for the cell
141
+ # As far as I can tell, this is pretty much ignored. However, based on the spec it should be one of the following:
142
+ # 0  ANSI_CHARSET
143
+ # 1 DEFAULT_CHARSET
144
+ # 2 SYMBOL_CHARSET
145
+ # 77 MAC_CHARSET
146
+ # 128 SHIFTJIS_CHARSET
147
+ # 129  HANGUL_CHARSET
148
+ # 130  JOHAB_CHARSET
149
+ # 134  GB2312_CHARSET
150
+ # 136  CHINESEBIG5_CHARSET
151
+ # 161  GREEK_CHARSET
152
+ # 162  TURKISH_CHARSET
153
+ # 163  VIETNAMESE_CHARSET
154
+ # 177  HEBREW_CHARSET
155
+ # 178  ARABIC_CHARSET
156
+ # 186  BALTIC_CHARSET
157
+ # 204  RUSSIAN_CHARSET
158
+ # 222  THAI_CHARSET
159
+ # 238  EASTEUROPE_CHARSET
160
+ # 255  OEM_CHARSET
161
+ # @return [String]
162
+ attr_reader :charset
163
+ # @see charset
164
+ def charset=(v) set_run_style :validate_unsigned_int, :charset, v; end
165
+
166
+ # The inline family property for the cell
167
+ # @return [Integer]
168
+ # 1 Roman
169
+ # 2 Swiss
170
+ # 3 Modern
171
+ # 4 Script
172
+ # 5 Decorative
173
+ attr_reader :family
174
+ # @see family
175
+ def family=(v)
176
+ set_run_style :validate_family, :family, v.to_i
177
+ end
178
+
179
+ # The inline bold property for the cell
180
+ # @return [Boolean]
181
+ attr_reader :b
182
+ # @see b
183
+ def b=(v) set_run_style :validate_boolean, :b, v; end
184
+
185
+ # The inline italic property for the cell
186
+ # @return [Boolean]
187
+ attr_reader :i
188
+ # @see i
189
+ def i=(v) set_run_style :validate_boolean, :i, v; end
190
+
191
+ # The inline strike property for the cell
192
+ # @return [Boolean]
193
+ attr_reader :strike
194
+ # @see strike
195
+ def strike=(v) set_run_style :validate_boolean, :strike, v; end
196
+
197
+ # The inline outline property for the cell
198
+ # @return [Boolean]
199
+ attr_reader :outline
200
+ # @see outline
201
+ def outline=(v) set_run_style :validate_boolean, :outline, v; end
202
+
203
+ # The inline shadow property for the cell
204
+ # @return [Boolean]
205
+ attr_reader :shadow
206
+ # @see shadow
207
+ def shadow=(v) set_run_style :validate_boolean, :shadow, v; end
208
+
209
+ # The inline condense property for the cell
210
+ # @return [Boolean]
211
+ attr_reader :condense
212
+ # @see condense
213
+ def condense=(v) set_run_style :validate_boolean, :condense, v; end
214
+
215
+ # The inline extend property for the cell
216
+ # @return [Boolean]
217
+ attr_reader :extend
218
+ # @see extend
219
+ def extend=(v) set_run_style :validate_boolean, :extend, v; end
220
+
221
+ # The inline underline property for the cell.
222
+ # It must be one of :none, :single, :double, :singleAccounting, :doubleAccounting, true
223
+ # @return [Boolean]
224
+ # @return [String]
225
+ # @note true is for backwards compatability and is reassigned to :single
226
+ attr_reader :u
227
+ # @see u
228
+ def u=(v)
229
+ v = :single if (v == true || v == 1 || v == :true || v == 'true')
230
+ set_run_style :validate_cell_u, :u, v
231
+ end
232
+
233
+ # The inline color property for the cell
234
+ # @return [Color]
235
+ attr_reader :color
236
+ # @param [String] v The 8 character representation for an rgb color #FFFFFFFF"
237
+ def color=(v)
238
+ @color = v.is_a?(Color) ? v : Color.new(:rgb=>v)
239
+ @is_text_run = true
240
+ end
241
+
242
+ # The inline sz property for the cell
243
+ # @return [Inteter]
244
+ attr_reader :sz
245
+ # @see sz
246
+ def sz=(v) set_run_style :validate_unsigned_int, :sz, v; end
247
+
248
+ # The inline vertical alignment property for the cell
249
+ # this must be one of [:baseline, :subscript, :superscript]
250
+ # @return [Symbol]
251
+ attr_reader :vertAlign
252
+ # @see vertAlign
253
+ def vertAlign=(v)
254
+ RestrictionValidator.validate :cell_vertAlign, [:baseline, :subscript, :superscript], v
255
+ set_run_style nil, :vertAlign, v
256
+ end
257
+
258
+ # The inline scheme property for the cell
259
+ # this must be one of [:none, major, minor]
260
+ # @return [Symbol]
261
+ attr_reader :scheme
262
+ # @see scheme
263
+ def scheme=(v)
264
+ RestrictionValidator.validate :cell_scheme, [:none, :major, :minor], v
265
+ set_run_style nil, :scheme, v
266
+ end
267
+
268
+ # The Shared Strings Table index for this cell
269
+ # @return [Integer]
270
+ attr_reader :ssti
271
+
272
+ # @return [Integer] The index of the cell in the containing row.
273
+ def index
274
+ @row.index(self)
275
+ end
276
+
277
+ # @return [String] The alpha(column)numeric(row) reference for this sell.
278
+ # @example Relative Cell Reference
279
+ # ws.rows.first.cells.first.r #=> "A1"
280
+ def r
281
+ Axlsx::cell_r index, @row.row_index
282
+ end
283
+
284
+ # @return [String] The absolute alpha(column)numeric(row) reference for this sell.
285
+ # @example Absolute Cell Reference
286
+ # ws.rows.first.cells.first.r #=> "$A$1"
287
+ def r_abs
288
+ "$#{r.match(%r{([A-Z]+)([0-9]+)})[1,2].join('$')}"
289
+ end
290
+
291
+ # @return [Integer] The cellXfs item index applied to this cell.
292
+ # @raise [ArgumentError] Invalid cellXfs id if the value provided is not within cellXfs items range.
293
+ def style=(v)
294
+ Axlsx::validate_unsigned_int(v)
295
+ count = styles.cellXfs.size
296
+ raise ArgumentError, "Invalid cellXfs id" unless v < count
297
+ @style = v
298
+ end
299
+
300
+ # @return [Array] of x/y coordinates in the sheet for this cell.
301
+ def pos
302
+ [index, row.row_index]
303
+ end
304
+
305
+ # Merges all the cells in a range created between this cell and the cell or string name for a cell provided
306
+ # @see worksheet.merge_cells
307
+ # @param [Cell, String] target The last cell, or str ref for the cell in the merge range
308
+ def merge(target)
309
+ start, stop = if target.is_a?(String)
310
+ [self.r, target]
311
+ elsif(target.is_a?(Cell))
312
+ Axlsx.sort_cells([self, target]).map { |c| c.r }
313
+ end
314
+ self.row.worksheet.merge_cells "#{start}:#{stop}" unless stop.nil?
315
+ end
316
+
317
+ # Serializes the cell
318
+ # @param [Integer] r_index The row index for the cell
319
+ # @param [Integer] c_index The cell index in the row.
320
+ # @param [String] str The string index the cell content will be appended to. Defaults to empty string.
321
+ # @return [String] xml text for the cell
322
+ def to_xml_string(r_index, c_index, str = '')
323
+ CellSerializer.to_xml_string r_index, c_index, self, str
324
+ end
325
+
326
+ def is_formula?
327
+ type == :string && @value.to_s.start_with?(?=)
328
+ end
329
+
330
+ def is_array_formula?
331
+ type == :string && @value.to_s.start_with?('{=') && @value.to_s.end_with?('}')
332
+ end
333
+
334
+ # returns the absolute or relative string style reference for
335
+ # this cell.
336
+ # @param [Boolean] absolute -when false a relative reference will be
337
+ # returned.
338
+ # @return [String]
339
+ def reference(absolute=true)
340
+ absolute ? r_abs : r
341
+ end
342
+
343
+ # Creates a defined name in the workbook for this cell.
344
+ def name=(label)
345
+ row.worksheet.workbook.add_defined_name "#{row.worksheet.name}!#{r_abs}", name: label
346
+ @name = label
347
+ end
348
+
349
+ # returns the name of the cell
350
+ attr_reader :name
351
+
352
+ # Attempts to determine the correct width for this cell's content
353
+ # @return [Float]
354
+ def autowidth
355
+ return if is_formula? || value.nil?
356
+ if contains_rich_text?
357
+ string_width('', font_size) + value.autowidth
358
+ elsif styles.cellXfs[style].alignment && styles.cellXfs[style].alignment.wrap_text
359
+ max_width = 0
360
+ value.to_s.split(/\r?\n/).each do |line|
361
+ width = string_width(line, font_size)
362
+ max_width = width if width > max_width
363
+ end
364
+ max_width
365
+ else
366
+ string_width(value, font_size)
367
+ end
368
+ end
369
+
370
+ # Returns the sanatized value
371
+ # TODO find a better way to do this as it accounts for 30% of
372
+ # processing time in benchmarking...
373
+ def clean_value
374
+ if (type == :string || type == :text) && !Axlsx::trust_input
375
+ Axlsx::sanitize(::CGI.escapeHTML(@value.to_s))
376
+ else
377
+ @value.to_s
378
+ end
379
+ end
380
+
381
+ private
382
+
383
+ def styles
384
+ row.worksheet.styles
385
+ end
386
+
387
+ # Returns the width of a string according to the current style
388
+ # This is still not perfect...
389
+ # - scaling is not linear as font sizes increase
390
+ def string_width(string, font_size)
391
+ font_scale = font_size / 10.0
392
+ (string.to_s.count(Worksheet::THIN_CHARS) + 3.0) * font_scale
393
+ end
394
+
395
+ # we scale the font size if bold style is applied to either the style font or
396
+ # the cell itself. Yes, it is a bit of a hack, but it is much better than using
397
+ # imagemagick and loading metrics for every character.
398
+ def font_size
399
+ return sz if sz
400
+ font = styles.fonts[styles.cellXfs[style].fontId] || styles.fonts[0]
401
+ (font.b || (defined?(@b) && @b)) ? (font.sz * 1.5) : font.sz
402
+ end
403
+
404
+ # Utility method for setting inline style attributes
405
+ def set_run_style(validator, attr, value)
406
+ return unless INLINE_STYLES.include?(attr.to_sym)
407
+ Axlsx.send(validator, value) unless validator.nil?
408
+ self.instance_variable_set :"@#{attr.to_s}", value
409
+ @is_text_run = true
410
+ end
411
+
412
+ # @see ssti
413
+ def ssti=(v)
414
+ Axlsx::validate_unsigned_int(v)
415
+ @ssti = v
416
+ end
417
+
418
+ # Determines the cell type based on the cell value.
419
+ # @note This is only used when a cell is created but no :type option is specified, the following rules apply:
420
+ # 1. If the value is an instance of Date, the type is set to :date
421
+ # 2. If the value is an instance of Time, the type is set to :time
422
+ # 3. If the value is an instance of TrueClass or FalseClass, the type is set to :boolean
423
+ # 4. :float and :integer types are determined by regular expression matching.
424
+ # 5. Anything that does not meet either of the above is determined to be :string.
425
+ # @return [Symbol] The determined type
426
+ def cell_type_from_value(v)
427
+ if v.is_a?(Date)
428
+ :date
429
+ elsif v.is_a?(Time)
430
+ :time
431
+ elsif v.is_a?(TrueClass) || v.is_a?(FalseClass)
432
+ :boolean
433
+ elsif v.to_s =~ Axlsx::NUMERIC_REGEX
434
+ :integer
435
+ elsif v.to_s =~ Axlsx::FLOAT_REGEX
436
+ :float
437
+ elsif v.to_s =~ Axlsx::ISO_8601_REGEX
438
+ :iso_8601
439
+ elsif v.is_a? RichText
440
+ :richtext
441
+ else
442
+ :string
443
+ end
444
+ end
445
+
446
+ # Cast the value into this cells data type.
447
+ # @note
448
+ # About Time - Time in OOXML is *different* from what you might expect. The history as to why is interesting, but you can safely assume that if you are generating docs on a mac, you will want to specify Workbook.1904 as true when using time typed values.
449
+ # @see Axlsx#date1904
450
+ def cast_value(v)
451
+ return v if v.is_a?(RichText) || v.nil?
452
+ case type
453
+ when :date
454
+ self.style = STYLE_DATE if self.style == 0
455
+ v
456
+ when :time
457
+ self.style = STYLE_DATE if self.style == 0
458
+ if !v.is_a?(Time) && v.respond_to?(:to_time)
459
+ v.to_time
460
+ else
461
+ v
462
+ end
463
+ when :float
464
+ v.to_f
465
+ when :integer
466
+ v.to_i
467
+ when :boolean
468
+ v ? 1 : 0
469
+ when :iso_8601
470
+ #consumer is responsible for ensuring the iso_8601 format when specifying this type
471
+ v
472
+ else
473
+ v.to_s
474
+ end
475
+ end
476
+
477
+ end
478
+ end