axlsx 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +3 -2
  3. data/.yardopts_guide +19 -0
  4. data/CHANGELOG.md +64 -1
  5. data/README.md +105 -87
  6. data/Rakefile +0 -5
  7. data/examples/2010_comments.rb +17 -0
  8. data/examples/anchor_swapping.rb +28 -0
  9. data/examples/auto_filter.rb +16 -0
  10. data/examples/basic_charts.rb +4 -0
  11. data/examples/colored_links.rb +59 -0
  12. data/examples/conditional_formatting/example_conditional_formatting.rb +4 -2
  13. data/examples/example.rb +569 -258
  14. data/examples/ios_preview.rb +14 -0
  15. data/examples/page_setup.rb +11 -0
  16. data/examples/pivot_table.rb +39 -0
  17. data/examples/skydrive/real_example.rb +8 -8
  18. data/examples/styles.rb +66 -0
  19. data/examples/underline.rb +13 -0
  20. data/examples/wrap_text.rb +21 -0
  21. data/lib/axlsx/content_type/abstract_content_type.rb +32 -0
  22. data/lib/axlsx/content_type/content_type.rb +1 -1
  23. data/lib/axlsx/content_type/default.rb +6 -37
  24. data/lib/axlsx/content_type/override.rb +6 -38
  25. data/lib/axlsx/doc_props/app.rb +10 -7
  26. data/lib/axlsx/doc_props/core.rb +6 -1
  27. data/lib/axlsx/drawing/axes.rb +61 -0
  28. data/lib/axlsx/drawing/axis.rb +20 -17
  29. data/lib/axlsx/drawing/bar_3D_chart.rb +31 -22
  30. data/lib/axlsx/drawing/cat_axis.rb +2 -10
  31. data/lib/axlsx/drawing/chart.rb +33 -6
  32. data/lib/axlsx/drawing/d_lbls.rb +21 -31
  33. data/lib/axlsx/drawing/drawing.rb +11 -17
  34. data/lib/axlsx/drawing/graphic_frame.rb +3 -3
  35. data/lib/axlsx/drawing/hyperlink.rb +42 -36
  36. data/lib/axlsx/drawing/line_3D_chart.rb +28 -70
  37. data/lib/axlsx/drawing/line_chart.rb +99 -0
  38. data/lib/axlsx/drawing/line_series.rb +20 -2
  39. data/lib/axlsx/drawing/marker.rb +38 -18
  40. data/lib/axlsx/drawing/num_data.rb +6 -6
  41. data/lib/axlsx/drawing/num_data_source.rb +17 -16
  42. data/lib/axlsx/drawing/one_cell_anchor.rb +28 -21
  43. data/lib/axlsx/drawing/pic.rb +43 -45
  44. data/lib/axlsx/drawing/picture_locking.rb +12 -44
  45. data/lib/axlsx/drawing/pie_3D_chart.rb +2 -1
  46. data/lib/axlsx/drawing/scaling.rb +13 -13
  47. data/lib/axlsx/drawing/scatter_chart.rb +32 -21
  48. data/lib/axlsx/drawing/ser_axis.rb +15 -16
  49. data/lib/axlsx/drawing/series.rb +3 -6
  50. data/lib/axlsx/drawing/str_data.rb +3 -3
  51. data/lib/axlsx/drawing/str_val.rb +7 -8
  52. data/lib/axlsx/drawing/two_cell_anchor.rb +7 -27
  53. data/lib/axlsx/drawing/val_axis.rb +14 -13
  54. data/lib/axlsx/drawing/view_3D.rb +52 -38
  55. data/lib/axlsx/drawing/vml_shape.rb +20 -79
  56. data/lib/axlsx/package.rb +58 -28
  57. data/lib/axlsx/rels/relationship.rb +75 -9
  58. data/lib/axlsx/rels/relationships.rb +8 -1
  59. data/lib/axlsx/stylesheet/border.rb +29 -20
  60. data/lib/axlsx/stylesheet/border_pr.rb +5 -4
  61. data/lib/axlsx/stylesheet/cell_alignment.rb +55 -29
  62. data/lib/axlsx/stylesheet/cell_protection.rb +7 -4
  63. data/lib/axlsx/stylesheet/cell_style.rb +19 -14
  64. data/lib/axlsx/stylesheet/color.rb +20 -17
  65. data/lib/axlsx/stylesheet/dxf.rb +4 -4
  66. data/lib/axlsx/stylesheet/font.rb +22 -22
  67. data/lib/axlsx/stylesheet/gradient_fill.rb +45 -21
  68. data/lib/axlsx/stylesheet/num_fmt.rb +23 -14
  69. data/lib/axlsx/stylesheet/pattern_fill.rb +12 -21
  70. data/lib/axlsx/stylesheet/styles.rb +37 -22
  71. data/lib/axlsx/stylesheet/table_style.rb +17 -16
  72. data/lib/axlsx/stylesheet/table_style_element.rb +15 -11
  73. data/lib/axlsx/stylesheet/table_styles.rb +14 -11
  74. data/lib/axlsx/stylesheet/xf.rb +28 -26
  75. data/lib/axlsx/util/accessors.rb +64 -0
  76. data/lib/axlsx/util/constants.rb +127 -6
  77. data/lib/axlsx/util/options_parser.rb +15 -0
  78. data/lib/axlsx/util/serialized_attributes.rb +79 -0
  79. data/lib/axlsx/util/simple_typed_list.rb +50 -15
  80. data/lib/axlsx/util/validators.rb +51 -16
  81. data/lib/axlsx/version.rb +2 -2
  82. data/lib/axlsx/workbook/defined_name.rb +14 -59
  83. data/lib/axlsx/workbook/shared_strings_table.rb +13 -4
  84. data/lib/axlsx/workbook/workbook.rb +85 -6
  85. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +77 -0
  86. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +94 -0
  87. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +246 -0
  88. data/lib/axlsx/workbook/worksheet/break.rb +37 -0
  89. data/lib/axlsx/workbook/worksheet/cell.rb +109 -107
  90. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +144 -0
  91. data/lib/axlsx/workbook/worksheet/cfvo.rb +15 -15
  92. data/lib/axlsx/workbook/worksheet/cfvos.rb +15 -0
  93. data/lib/axlsx/workbook/worksheet/col.rb +43 -29
  94. data/lib/axlsx/workbook/worksheet/col_breaks.rb +35 -0
  95. data/lib/axlsx/workbook/worksheet/color_scale.rb +62 -28
  96. data/lib/axlsx/workbook/worksheet/comment.rb +28 -37
  97. data/lib/axlsx/workbook/worksheet/comments.rb +3 -3
  98. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +11 -11
  99. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +31 -27
  100. data/lib/axlsx/workbook/worksheet/data_bar.rb +75 -41
  101. data/lib/axlsx/workbook/worksheet/data_validation.rb +61 -62
  102. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +6 -5
  103. data/lib/axlsx/workbook/worksheet/dimension.rb +0 -1
  104. data/lib/axlsx/workbook/worksheet/header_footer.rb +54 -0
  105. data/lib/axlsx/workbook/worksheet/icon_set.rb +20 -20
  106. data/lib/axlsx/workbook/worksheet/page_margins.rb +21 -19
  107. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +44 -0
  108. data/lib/axlsx/workbook/worksheet/page_setup.rb +152 -23
  109. data/lib/axlsx/workbook/worksheet/pane.rb +48 -51
  110. data/lib/axlsx/workbook/worksheet/pivot_table.rb +273 -0
  111. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +66 -0
  112. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +24 -0
  113. data/lib/axlsx/workbook/worksheet/print_options.rb +8 -30
  114. data/lib/axlsx/workbook/worksheet/protected_range.rb +16 -13
  115. data/lib/axlsx/workbook/worksheet/row.rb +59 -83
  116. data/lib/axlsx/workbook/worksheet/row_breaks.rb +33 -0
  117. data/lib/axlsx/workbook/worksheet/selection.rb +30 -38
  118. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +29 -0
  119. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +60 -0
  120. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +49 -4
  121. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +51 -155
  122. data/lib/axlsx/workbook/worksheet/sheet_view.rb +68 -234
  123. data/lib/axlsx/workbook/worksheet/table.rb +25 -19
  124. data/lib/axlsx/workbook/worksheet/table_style_info.rb +51 -0
  125. data/lib/axlsx/workbook/worksheet/tables.rb +1 -1
  126. data/lib/axlsx/workbook/worksheet/worksheet.rb +174 -35
  127. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +6 -5
  128. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +4 -10
  129. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +74 -0
  130. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +38 -0
  131. data/lib/axlsx.rb +55 -5
  132. data/lib/schema/sml.xsd +4 -0
  133. data/test/axlsx.qcachegrind +2226 -0
  134. data/test/benchmark.rb +2 -3
  135. data/test/content_type/tc_default.rb +0 -11
  136. data/test/content_type/tc_override.rb +0 -13
  137. data/test/doc_props/tc_core.rb +7 -0
  138. data/test/drawing/tc_axes.rb +8 -0
  139. data/test/drawing/tc_axis.rb +15 -17
  140. data/test/drawing/tc_bar_3D_chart.rb +6 -0
  141. data/test/drawing/tc_cat_axis.rb +9 -9
  142. data/test/drawing/tc_chart.rb +20 -0
  143. data/test/drawing/tc_d_lbls.rb +14 -4
  144. data/test/drawing/tc_drawing.rb +0 -5
  145. data/test/drawing/tc_graphic_frame.rb +5 -3
  146. data/test/drawing/tc_hyperlink.rb +0 -4
  147. data/test/drawing/tc_line_chart.rb +39 -0
  148. data/test/drawing/tc_line_series.rb +8 -2
  149. data/test/drawing/tc_pic.rb +14 -3
  150. data/test/drawing/tc_ser_axis.rb +13 -12
  151. data/test/drawing/tc_two_cell_anchor.rb +3 -3
  152. data/test/drawing/tc_val_axis.rb +6 -6
  153. data/test/drawing/tc_vml_shape.rb +9 -3
  154. data/test/profile.rb +11 -21
  155. data/test/rels/tc_relationship.rb +32 -9
  156. data/test/rels/tc_relationships.rb +12 -1
  157. data/test/stylesheet/tc_color.rb +6 -0
  158. data/test/stylesheet/tc_styles.rb +15 -2
  159. data/test/tc_axlsx.rb +35 -2
  160. data/test/tc_helper.rb +7 -1
  161. data/test/tc_package.rb +44 -5
  162. data/test/util/tc_serialized_attributes.rb +19 -0
  163. data/test/util/tc_validators.rb +26 -1
  164. data/test/workbook/tc_defined_name.rb +2 -2
  165. data/test/workbook/tc_shared_strings_table.rb +6 -0
  166. data/test/workbook/tc_workbook.rb +38 -1
  167. data/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +38 -0
  168. data/test/workbook/worksheet/auto_filter/tc_filter_column.rb +76 -0
  169. data/test/workbook/worksheet/auto_filter/tc_filters.rb +50 -0
  170. data/test/workbook/worksheet/tc_break.rb +49 -0
  171. data/test/workbook/worksheet/tc_cell.rb +40 -6
  172. data/test/workbook/worksheet/tc_col.rb +11 -1
  173. data/test/workbook/worksheet/tc_color_scale.rb +31 -2
  174. data/test/workbook/worksheet/tc_comment.rb +21 -6
  175. data/test/workbook/worksheet/tc_comments.rb +2 -2
  176. data/test/workbook/worksheet/tc_conditional_formatting.rb +7 -0
  177. data/test/workbook/worksheet/tc_data_bar.rb +7 -0
  178. data/test/workbook/worksheet/tc_date_time_converter.rb +3 -11
  179. data/test/workbook/worksheet/tc_header_footer.rb +151 -0
  180. data/test/workbook/worksheet/tc_page_set_up_pr.rb +15 -0
  181. data/test/workbook/worksheet/tc_page_setup.rb +6 -1
  182. data/test/workbook/worksheet/tc_pane.rb +5 -45
  183. data/test/workbook/worksheet/tc_pivot_table.rb +120 -0
  184. data/test/workbook/worksheet/tc_pivot_table_cache_definition.rb +54 -0
  185. data/test/workbook/worksheet/tc_row.rb +4 -4
  186. data/test/workbook/worksheet/tc_selection.rb +9 -48
  187. data/test/workbook/worksheet/tc_sheet_calc_pr.rb +18 -0
  188. data/test/workbook/worksheet/tc_sheet_format_pr.rb +88 -0
  189. data/test/workbook/worksheet/tc_sheet_pr.rb +27 -0
  190. data/test/workbook/worksheet/tc_sheet_view.rb +39 -39
  191. data/test/workbook/worksheet/{table/tc_table.rb → tc_table.rb} +8 -3
  192. data/test/workbook/worksheet/tc_table_style_info.rb +53 -0
  193. data/test/workbook/worksheet/tc_worksheet.rb +131 -16
  194. data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +55 -0
  195. metadata +97 -64
  196. data/examples/example.xlsx +0 -0
  197. data/examples/example_streamed.xlsx +0 -0
  198. data/examples/extractive.pdf +0 -0
  199. data/examples/image1.gif +0 -0
  200. data/examples/image1.jpg +0 -0
  201. data/examples/image1.png +0 -0
  202. data/examples/no-use_autowidth.xlsx +0 -0
  203. data/examples/sample.png +0 -0
  204. data/examples/scraping_html.rb +0 -91
  205. data/examples/shared_strings_example.xlsx +0 -0
  206. data/examples/sheet_view.rb +0 -34
  207. data/examples/two_cell_anchor_image.rb +0 -11
  208. data/lib/axlsx/workbook/worksheet/auto_filter.rb +0 -34
@@ -0,0 +1,33 @@
1
+ module Axlsx
2
+
3
+ # A collection of break objects that define row breaks (page breaks) for printing and preview
4
+
5
+ class RowBreaks < SimpleTypedList
6
+
7
+ def initialize
8
+ super Break
9
+ end
10
+
11
+ # Adds a row break
12
+ # @param [Hash] options The options for the break to be created.
13
+ # max and man values are fixed.
14
+ # @see Break
15
+ def add_break(options)
16
+ # force feed the excel default
17
+ @list << Break.new(options.merge(:max => 16383, :man => true))
18
+ last
19
+ end
20
+
21
+ # <rowBreaks count="3" manualBreakCount="3">
22
+ # <brk id="1" max="16383" man="1"/>
23
+ # <brk id="7" max="16383" man="1"/>
24
+ # <brk id="13" max="16383" man="1"/>
25
+ # </rowBreaks>
26
+ def to_xml_string(str='')
27
+ return if empty?
28
+ str << '<rowBreaks count="' << @list.size.to_s << '" manualBreakCount="' << @list.size.to_s << '">'
29
+ each { |brk| brk.to_xml_string(str) }
30
+ str << '</rowBreaks>'
31
+ end
32
+ end
33
+ end
@@ -5,15 +5,28 @@ module Axlsx
5
5
  # @note The recommended way to manage the selection pane options is via SheetView#add_selection
6
6
  # @see SheetView#add_selection
7
7
  class Selection
8
-
8
+
9
+ include Axlsx::OptionsParser
10
+ include Axlsx::SerializedAttributes
11
+
12
+ # Creates a new {Selection} object
13
+ # @option options [Cell, String] active_cell Active Cell Location
14
+ # @option options [Integer] active_cell_id Active Cell Index
15
+ # @option options [Symbol] pane Pane
16
+ # @option options [String] sqref Sequence of References
17
+ def initialize(options={})
18
+ @active_cell = @active_cell_id = @pane = @sqref = nil
19
+ parse_options options
20
+ end
21
+
22
+ serializable_attributes :active_cell, :active_cell_id, :pane, :sqref
9
23
  # Active Cell Location
10
24
  # Location of the active cell.
11
25
  # @see type
12
26
  # @return [String]
13
27
  # default nil
14
28
  attr_reader :active_cell
15
-
16
-
29
+
17
30
  # Active Cell Index
18
31
  # 0-based index of the range reference (in the array of references listed in sqref)
19
32
  # containing the active cell. Only used when the selection in sqref is not contiguous.
@@ -24,8 +37,7 @@ module Axlsx
24
37
  # @return [Integer]
25
38
  # default nil
26
39
  attr_reader :active_cell_id
27
-
28
-
40
+
29
41
  # Pane
30
42
  # The pane to which this selection belongs.
31
43
  # Options are
@@ -52,59 +64,39 @@ module Axlsx
52
64
  # @return [Symbol]
53
65
  # default nil
54
66
  attr_reader :pane
55
-
56
-
67
+
57
68
  # Sequence of References
58
69
  # Range of the selection. Can be non-contiguous set of ranges.
59
70
  # @see type
60
71
  # @return [String]
61
72
  # default nil
62
73
  attr_reader :sqref
63
-
64
-
65
- # Creates a new {Selection} object
66
- # @option options [Cell, String] active_cell Active Cell Location
67
- # @option options [Integer] active_cell_id Active Cell Index
68
- # @option options [Symbol] pane Pane
69
- # @option options [String] sqref Sequence of References
70
- def initialize(options={})
71
- #defaults
72
- @active_cell = @active_cell_id = @pane = @sqref = nil
73
-
74
- # write options to instance variables
75
- options.each do |o|
76
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
77
- end
78
- end
79
-
80
-
74
+
81
75
  # @see active_cell
82
76
  def active_cell=(v)
83
77
  cell = (v.class == Axlsx::Cell ? v.r_abs : v)
84
- Axlsx::validate_string(cell)
85
- @active_cell = cell
78
+ Axlsx::validate_string(cell)
79
+ @active_cell = cell
86
80
  end
87
-
88
-
81
+
89
82
  # @see active_cell_id
90
83
  def active_cell_id=(v); Axlsx::validate_unsigned_int(v); @active_cell_id = v end
91
-
92
-
84
+
93
85
  # @see pane
94
- def pane=(v); Axlsx::validate_pane_type(v); @pane = v end
95
-
96
-
86
+ def pane=(v)
87
+ Axlsx::validate_pane_type(v)
88
+ @pane = Axlsx::camel(v, false)
89
+ end
90
+
97
91
  # @see sqref
98
92
  def sqref=(v); Axlsx::validate_string(v); @sqref = v end
99
-
100
-
93
+
101
94
  # Serializes the data validation
102
95
  # @param [String] str
103
96
  # @return [String]
104
97
  def to_xml_string(str = '')
105
98
  str << '<selection '
106
- str << instance_values.map { |key, value| '' << key.gsub(/_(.)/){ $1.upcase } <<
107
- %{="#{[:pane].include?(key.to_sym) ? value.to_s.gsub(/_(.)/){ $1.upcase } : value}"} unless value.nil? }.join(' ')
99
+ serialized_attributes str
108
100
  str << '/>'
109
101
  end
110
102
  end
@@ -0,0 +1,29 @@
1
+ module Axlsx
2
+
3
+ # the SheetCalcPr object for the worksheet
4
+ # This object contains calculation properties for the worksheet.
5
+ class SheetCalcPr
6
+ include Axlsx::OptionsParser
7
+ include Axlsx::SerializedAttributes
8
+ include Axlsx::Accessors
9
+ # creates a new SheetCalcPr
10
+ # @param [Hash] options Options for this object
11
+ # @option [Boolean] full_calc_on_load @see full_calc_on_load
12
+ def initialize(options={})
13
+ @full_calc_on_load = true
14
+ parse_options options
15
+ end
16
+
17
+ boolean_attr_accessor :full_calc_on_load
18
+
19
+ serializable_attributes :full_calc_on_load
20
+
21
+ # Serialize the object
22
+ # @param [String] str the string to append this objects serialized
23
+ # content to.
24
+ # @return [String]
25
+ def to_xml_string(str='')
26
+ str << "<sheetCalcPr #{serialized_attributes}/>"
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,60 @@
1
+ module Axlsx
2
+
3
+ #Sheet formatting properties
4
+ # <xsd:complexType name="CT_SheetFormatPr">
5
+ # <xsd:attribute name="baseColWidth" type="xsd:unsignedInt" use="optional" default="8"/>
6
+ # <xsd:attribute name="defaultColWidth" type="xsd:double" use="optional"/>
7
+ # <xsd:attribute name="defaultRowHeight" type="xsd:double" use="required"/>
8
+ # <xsd:attribute name="customHeight" type="xsd:boolean" use="optional" default="false"/>
9
+ # <xsd:attribute name="zeroHeight" type="xsd:boolean" use="optional" default="false"/>
10
+ # <xsd:attribute name="thickTop" type="xsd:boolean" use="optional" default="false"/>
11
+ # <xsd:attribute name="thickBottom" type="xsd:boolean" use="optional" default="false"/>
12
+ # <xsd:attribute name="outlineLevelRow" type="xsd:unsignedByte" use="optional" default="0"/>
13
+ # <xsd:attribute name="outlineLevelCol" type="xsd:unsignedByte" use="optional" default="0"/>
14
+ #</xsd:complexType>
15
+
16
+ class SheetFormatPr
17
+ include Axlsx::SerializedAttributes
18
+ include Axlsx::OptionsParser
19
+ include Axlsx::Accessors
20
+
21
+ # creates a new sheet_format_pr object
22
+ # @param [Hash] options initialization options
23
+ # @option [Integer] base_col_width Specifies the number of characters of the maximum digit width of the normal style's font. This value does not include margin padding or extra padding for gridlines. It is only the number of characters.
24
+ # @option [Float] default_col_width Default column width measured as the number of characters of the maximum digit width of the normal style's font.
25
+ # @option [Float] default_row_height Default row height measured in point size. Optimization so we don't have to write the height on all rows. This can be written out if most rows have custom height, to achieve the optimization.
26
+ # @option [Boolean] custom_height 'True' if defaultRowHeight value has been manually set, or is different from the default value.
27
+ # @option [Boolean] zero_height 'True' if rows are hidden by default. This setting is an optimization used when most rows of the sheet are hidden.
28
+ # @option [Boolean] think_top 'True' if rows have a thick top border by default.
29
+ # @option [Boolean] thick_bottom 'True' if rows have a thick bottom border by default.
30
+ # @option [Integer] outline_level_row Highest number of outline level for rows in this sheet. These values shall be in synch with the actual sheet outline levels.
31
+ # @option [Integer] outline_level_col Highest number of outline levels for columns in this sheet. These values shall be in synch with the actual sheet outline levels.
32
+ def initialize(options={})
33
+ set_defaults
34
+ parse_options options
35
+ end
36
+
37
+ serializable_attributes :base_col_width, :default_col_width, :default_row_height,
38
+ :custom_height, :zero_height, :thick_top, :thick_bottom,
39
+ :outline_level_row, :outline_level_col
40
+
41
+ float_attr_accessor :default_col_width, :default_row_height
42
+
43
+ boolean_attr_accessor :custom_height, :zero_height, :thick_top, :thick_bottom
44
+
45
+ unsigned_int_attr_accessor :base_col_width, :outline_level_row, :outline_level_col
46
+
47
+ # serializes this object to an xml string
48
+ # @param [String] str The string this objects serialization will be appended to
49
+ # @return [String]
50
+ def to_xml_string(str='')
51
+ str << "<sheetFormatPr #{serialized_attributes}/>"
52
+ end
53
+
54
+ private
55
+ def set_defaults
56
+ @base_col_width = 8
57
+ @default_row_height = 18
58
+ end
59
+ end
60
+ end
@@ -1,24 +1,69 @@
1
1
  module Axlsx
2
2
 
3
3
  # The SheetPr class manages serialization fo a worksheet's sheetPr element.
4
- # Only fit_to_page is implemented
5
4
  class SheetPr
5
+ include Axlsx::OptionsParser
6
+ include Axlsx::Accessors
7
+ include Axlsx::SerializedAttributes
8
+
9
+ serializable_attributes :sync_horizontal,
10
+ :sync_vertical,
11
+ :transtion_evaluation,
12
+ :transition_entry,
13
+ :published,
14
+ :filter_mode,
15
+ :enable_format_conditions_calculation,
16
+ :code_name,
17
+ :sync_ref
18
+
19
+ # These attributes are all boolean so I'm doing a bit of a hand
20
+ # waving magic show to set up the attriubte accessors
21
+ boolean_attr_accessor :sync_horizontal,
22
+ :sync_vertical,
23
+ :transtion_evaluation,
24
+ :transition_entry,
25
+ :published,
26
+ :filter_mode,
27
+ :enable_format_conditions_calculation
28
+
29
+ string_attr_accessor :code_name, :sync_ref
6
30
 
7
31
  # Creates a new SheetPr object
8
32
  # @param [Worksheet] worksheet The worksheet that owns this SheetPr object
9
- def initialize(worksheet)
33
+ def initialize(worksheet, options={})
10
34
  raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
11
35
  @worksheet = worksheet
36
+ parse_options options
12
37
  end
13
38
 
39
+ # The worksheet these properties apply to!
40
+ # @return [Worksheet]
14
41
  attr_reader :worksheet
15
42
 
16
43
  # Serialize the object
17
44
  # @param [String] str serialized output will be appended to this object if provided.
18
45
  # @return [String]
19
46
  def to_xml_string(str = '')
20
- return unless worksheet.fit_to_page?
21
- str << "<sheetPr><pageSetUpPr fitToPage=\"%s\"></pageSetUpPr></sheetPr>" % worksheet.fit_to_page?
47
+ update_properties
48
+ str << "<sheetPr #{serialized_attributes}>"
49
+ page_setup_pr.to_xml_string(str)
50
+ str << "</sheetPr>"
51
+ end
52
+
53
+ # The PageSetUpPr for this sheet pr object
54
+ # @return [PageSetUpPr]
55
+ def page_setup_pr
56
+ @page_setup_pr ||= PageSetUpPr.new
57
+ end
58
+
59
+ private
60
+
61
+ def update_properties
62
+ page_setup_pr.fit_to_page = worksheet.fit_to_page?
63
+ if worksheet.auto_filter.columns.size > 0
64
+ self.filter_mode = 1
65
+ self.enable_format_conditions_calculation = 1
66
+ end
22
67
  end
23
68
  end
24
69
  end
@@ -4,110 +4,9 @@ module Axlsx
4
4
  # The SheetProtection object manages worksheet protection options per sheet.
5
5
  class SheetProtection
6
6
 
7
- # If 1 or true then AutoFilters should not be allowed to operate when the sheet is protected.
8
- # If 0 or false then AutoFilters should be allowed to operate when the sheet is protected.
9
- # @return [Boolean]
10
- # default true
11
- attr_reader :auto_filter
12
-
13
- # If 1 or true then deleting columns should not be allowed when the sheet is protected.
14
- # If 0 or false then deleting columns should be allowed when the sheet is protected.
15
- # @return [Boolean]
16
- # default true
17
- attr_reader :delete_columns
18
-
19
- # If 1 or true then deleting rows should not be allowed when the sheet is protected.
20
- # If 0 or false then deleting rows should be allowed when the sheet is protected.
21
- # @return [Boolean]
22
- # default true
23
- attr_reader :delete_rows
24
-
25
- # If 1 or true then formatting cells should not be allowed when the sheet is protected.
26
- # If 0 or false then formatting cells should be allowed when the sheet is protected.
27
- # @return [Boolean]
28
- # default true
29
- attr_reader :format_cells
30
-
31
- # If 1 or true then formatting columns should not be allowed when the sheet is protected.
32
- # If 0 or false then formatting columns should be allowed when the sheet is protected.
33
- # @return [Boolean]
34
- # default true
35
- attr_reader :format_columns
36
-
37
- # If 1 or true then formatting rows should not be allowed when the sheet is protected.
38
- # If 0 or false then formatting rows should be allowed when the sheet is protected.
39
- # @return [Boolean]
40
- # default true
41
- attr_reader :format_rows
42
-
43
- # If 1 or true then inserting columns should not be allowed when the sheet is protected.
44
- # If 0 or false then inserting columns should be allowed when the sheet is protected.
45
- # @return [Boolean]
46
- # default true
47
- attr_reader :insert_columns
48
-
49
- # If 1 or true then inserting hyperlinks should not be allowed when the sheet is protected.
50
- # If 0 or false then inserting hyperlinks should be allowed when the sheet is protected.
51
- # @return [Boolean]
52
- # default true
53
- attr_reader :insert_hyperlinks
54
-
55
- # If 1 or true then inserting rows should not be allowed when the sheet is protected.
56
- # If 0 or false then inserting rows should be allowed when the sheet is protected.
57
- # @return [Boolean]
58
- # default true
59
- attr_reader :insert_rows
60
-
61
- # If 1 or true then editing of objects should not be allowed when the sheet is protected.
62
- # If 0 or false then objects are allowed to be edited when the sheet is protected.
63
- # @return [Boolean]
64
- # default false
65
- attr_reader :objects
66
-
67
- # If 1 or true then PivotTables should not be allowed to operate when the sheet is protected.
68
- # If 0 or false then PivotTables should be allowed to operate when the sheet is protected.
69
- # @return [Boolean]
70
- # default true
71
- attr_reader :pivot_tables
72
-
73
- # Specifies the salt which was prepended to the user-supplied password before it was hashed using the hashing algorithm
74
- # @return [String]
75
- attr_reader :salt_value
76
-
77
- # If 1 or true then Scenarios should not be edited when the sheet is protected.
78
- # If 0 or false then Scenarios are allowed to be edited when the sheet is protected.
79
- # @return [Boolean]
80
- # default false
81
- attr_reader :scenarios
82
-
83
- # If 1 or true then selection of locked cells should not be allowed when the sheet is protected.
84
- # If 0 or false then selection of locked cells should be allowed when the sheet is protected.
85
- # @return [Boolean]
86
- # default false
87
- attr_reader :select_locked_cells
88
-
89
- # If 1 or true then selection of unlocked cells should not be allowed when the sheet is protected.
90
- # If 0 or false then selection of unlocked cells should be allowed when the sheet is protected.
91
- # @return [Boolean]
92
- # default false
93
- attr_reader :select_unlocked_cells
94
-
95
- # If 1 or true then the sheet is protected.
96
- # If 0 or false then the sheet is not protected.
97
- # @return [Boolean]
98
- # default true
99
- attr_reader :sheet
100
-
101
- # If 1 or true then sorting should not be allowed when the sheet is protected.
102
- # If 0 or false then sorting should be allowed when the sheet is protected.
103
- # @return [Boolean]
104
- # default true
105
- attr_reader :sort
106
-
107
- # Password hash
108
- # @return [String]
109
- # default nil
110
- attr_reader :password
7
+ include Axlsx::OptionsParser
8
+ include Axlsx::SerializedAttributes
9
+ include Axlsx::Accessors
111
10
 
112
11
  # Creates a new SheetProtection instance
113
12
  # @option options [Boolean] sheet @see SheetProtection#sheet
@@ -127,64 +26,62 @@ module Axlsx
127
26
  # @option options [Boolean] pivot_tables @see SheetProtection#pivot_tables
128
27
  # @option options [Boolean] select_unlocked_cells @see SheetProtection#select_unlocked_cells
129
28
  # @option options [String] password. The password required for unlocking. @see SheetProtection#password=
130
- # @option options [Boolean] objects @see SheetProtection#objects
131
29
  def initialize(options={})
132
30
  @objects = @scenarios = @select_locked_cells = @select_unlocked_cells = false
133
31
  @sheet = @format_cells = @format_rows = @format_columns = @insert_columns = @insert_rows = @insert_hyperlinks = @delete_columns = @delete_rows = @sort = @auto_filter = @pivot_tables = true
134
32
  @password = nil
33
+ parse_options options
34
+ end
135
35
 
136
- options.each do |o|
137
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
138
- end
36
+ boolean_attr_accessor :sheet, :objects, :scenarios, :format_cells, :format_columns, :format_rows,
37
+ :insert_columns, :insert_rows, :insert_hyperlinks, :delete_columns, :delete_rows,
38
+ :select_locked_cells, :sort, :auto_filter, :pivot_tables, :select_unlocked_cells
39
+
40
+ serializable_attributes :sheet, :objects, :scenarios, :format_cells, :format_columns, :format_rows,
41
+ :insert_columns, :insert_rows, :insert_hyperlinks, :delete_columns, :delete_rows,
42
+ :select_locked_cells, :sort, :auto_filter, :pivot_tables, :select_unlocked_cells, :salt, :password
43
+
44
+ # Specifies the salt which was prepended to the user-supplied password before it was hashed using the hashing algorithm
45
+ # @return [String]
46
+ attr_reader :salt_value
47
+
48
+ # Password hash
49
+ # @return [String]
50
+ # default nil
51
+ attr_reader :password
52
+
53
+ # This block is intended to implement the salt_value, hash_value and spin count as per the ECMA-376 standard.
54
+ # However, it does not seem to actually work in EXCEL - instead they are using their old retro algorithm shown below
55
+ # defined in the transitional portion of the speck. I am leaving this code in in the hope that someday Ill be able to
56
+ # figure out why it does not work, and if Excel even supports it.
57
+ # def propper_password=(v)
58
+ # @algorithm_name = v == nil ? nil : 'SHA-1'
59
+ # @salt_value = @spin_count = @hash_value = v if v == nil
60
+ # return if v == nil
61
+ # require 'digest/sha1'
62
+ # @spin_count = 10000
63
+ # @salt_value = Digest::SHA1.hexdigest(rand(36**8).to_s(36))
64
+ # @spin_count.times do |count|
65
+ # @hash_value = Digest::SHA1.hexdigest((@hash_value ||= (@salt_value + v.to_s)) + Array(count).pack('V'))
66
+ # end
67
+ # end
68
+
69
+ # encodes password for protection locking
70
+ def password=(v)
71
+ return if v == nil
72
+ @password = create_password_hash(v)
139
73
  end
140
74
 
75
+ # Serialize the object
76
+ # @param [String] str
77
+ # @return [String]
78
+ def to_xml_string(str = '')
79
+ str << '<sheetProtection '
80
+ serialized_attributes str
81
+ str << '/>'
82
+ end
141
83
 
142
- # create validating setters for boolean values
143
- # @return [Boolean]
144
- [:sheet, :objects, :scenarios, :select_locked_cells, :sort,
145
- :select_unlocked_cells, :format_cells, :format_rows, :format_columns,
146
- :insert_columns, :insert_rows, :insert_hyperlinks, :delete_columns,
147
- :delete_rows, :auto_filter, :pivot_tables].each do |f_name|
148
- define_method "#{f_name.to_s}=".to_sym do |v|
149
- Axlsx::validate_boolean(v)
150
- instance_variable_set "@#{f_name.to_s}".to_sym, v
151
- end
152
- end
153
-
154
- # This block is intended to implement the salt_value, hash_value and spin count as per the ECMA-376 standard.
155
- # However, it does not seem to actually work in EXCEL - instead they are using their old retro algorithm shown below
156
- # defined in the transitional portion of the speck. I am leaving this code in in the hope that someday Ill be able to
157
- # figure out why it does not work, and if Excel even supports it.
158
- # def propper_password=(v)
159
- # @algorithm_name = v == nil ? nil : 'SHA-1'
160
- # @salt_value = @spin_count = @hash_value = v if v == nil
161
- # return if v == nil
162
- # require 'digest/sha1'
163
- # @spin_count = 10000
164
- # @salt_value = Digest::SHA1.hexdigest(rand(36**8).to_s(36))
165
- # @spin_count.times do |count|
166
- # @hash_value = Digest::SHA1.hexdigest((@hash_value ||= (@salt_value + v.to_s)) + Array(count).pack('V'))
167
- # end
168
- # end
169
-
170
-
171
-
172
- # encodes password for protection locking
173
- def password=(v)
174
- return if v == nil
175
- @password = create_password_hash(v)
176
- end
177
-
178
- # Serialize the object
179
- # @param [String] str
180
- # @return [String]
181
- def to_xml_string(str = '')
182
- str << '<sheetProtection '
183
- str << instance_values.map{ |k,v| k.gsub(/_(.)/){ $1.upcase } << %{="#{v.to_s}"} }.join(' ')
184
- str << '/>'
185
- end
186
-
187
- private
84
+ private
188
85
  # Creates a password hash for a given password
189
86
  # @return [String]
190
87
  def create_password_hash(password)
@@ -196,7 +93,6 @@ module Axlsx
196
93
  password_as_string[2..3] + password_as_string[0..1]
197
94
  end
198
95
 
199
-
200
96
  # Encodes a given password
201
97
  # Based on the algorithm provided by Daniel Rentz of OpenOffice.
202
98
  # http://www.openoffice.org/sc/excelfileformat.pdf, Revision 1.42, page 115 (21.05.2012)