caxlsx 3.3.0 → 4.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 (151) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -0
  3. data/README.md +25 -7
  4. data/Rakefile +7 -6
  5. data/lib/axlsx/content_type/abstract_content_type.rb +11 -9
  6. data/lib/axlsx/content_type/content_type.rb +7 -9
  7. data/lib/axlsx/content_type/default.rb +4 -6
  8. data/lib/axlsx/content_type/override.rb +3 -5
  9. data/lib/axlsx/doc_props/app.rb +27 -30
  10. data/lib/axlsx/doc_props/core.rb +9 -12
  11. data/lib/axlsx/drawing/area_chart.rb +13 -14
  12. data/lib/axlsx/drawing/area_series.rb +13 -14
  13. data/lib/axlsx/drawing/ax_data_source.rb +3 -6
  14. data/lib/axlsx/drawing/axes.rb +10 -9
  15. data/lib/axlsx/drawing/axis.rb +27 -30
  16. data/lib/axlsx/drawing/bar_3D_chart.rb +17 -18
  17. data/lib/axlsx/drawing/bar_chart.rb +16 -17
  18. data/lib/axlsx/drawing/bar_series.rb +9 -13
  19. data/lib/axlsx/drawing/bubble_chart.rb +8 -9
  20. data/lib/axlsx/drawing/bubble_series.rb +9 -10
  21. data/lib/axlsx/drawing/cat_axis.rb +14 -17
  22. data/lib/axlsx/drawing/chart.rb +25 -28
  23. data/lib/axlsx/drawing/d_lbls.rb +29 -26
  24. data/lib/axlsx/drawing/drawing.rb +60 -62
  25. data/lib/axlsx/drawing/graphic_frame.rb +6 -7
  26. data/lib/axlsx/drawing/hyperlink.rb +12 -13
  27. data/lib/axlsx/drawing/line_3D_chart.rb +13 -15
  28. data/lib/axlsx/drawing/line_chart.rb +13 -14
  29. data/lib/axlsx/drawing/line_series.rb +13 -14
  30. data/lib/axlsx/drawing/marker.rb +14 -16
  31. data/lib/axlsx/drawing/num_data.rb +13 -16
  32. data/lib/axlsx/drawing/num_data_source.rb +11 -13
  33. data/lib/axlsx/drawing/num_val.rb +9 -10
  34. data/lib/axlsx/drawing/one_cell_anchor.rb +10 -10
  35. data/lib/axlsx/drawing/pic.rb +57 -22
  36. data/lib/axlsx/drawing/picture_locking.rb +6 -7
  37. data/lib/axlsx/drawing/pie_3D_chart.rb +6 -9
  38. data/lib/axlsx/drawing/pie_series.rb +9 -12
  39. data/lib/axlsx/drawing/scaling.rb +9 -10
  40. data/lib/axlsx/drawing/scatter_chart.rb +9 -10
  41. data/lib/axlsx/drawing/scatter_series.rb +15 -16
  42. data/lib/axlsx/drawing/ser_axis.rb +9 -11
  43. data/lib/axlsx/drawing/series.rb +8 -8
  44. data/lib/axlsx/drawing/series_title.rb +6 -6
  45. data/lib/axlsx/drawing/str_data.rb +10 -13
  46. data/lib/axlsx/drawing/str_val.rb +8 -9
  47. data/lib/axlsx/drawing/title.rb +23 -27
  48. data/lib/axlsx/drawing/two_cell_anchor.rb +8 -8
  49. data/lib/axlsx/drawing/val_axis.rb +5 -6
  50. data/lib/axlsx/drawing/view_3D.rb +32 -30
  51. data/lib/axlsx/drawing/vml_drawing.rb +19 -20
  52. data/lib/axlsx/drawing/vml_shape.rb +25 -26
  53. data/lib/axlsx/package.rb +81 -79
  54. data/lib/axlsx/rels/relationship.rb +30 -28
  55. data/lib/axlsx/rels/relationships.rb +7 -8
  56. data/lib/axlsx/stylesheet/border.rb +7 -8
  57. data/lib/axlsx/stylesheet/border_pr.rb +8 -8
  58. data/lib/axlsx/stylesheet/cell_alignment.rb +14 -20
  59. data/lib/axlsx/stylesheet/cell_protection.rb +6 -7
  60. data/lib/axlsx/stylesheet/cell_style.rb +12 -14
  61. data/lib/axlsx/stylesheet/color.rb +15 -12
  62. data/lib/axlsx/stylesheet/dxf.rb +7 -9
  63. data/lib/axlsx/stylesheet/fill.rb +3 -5
  64. data/lib/axlsx/stylesheet/font.rb +24 -21
  65. data/lib/axlsx/stylesheet/gradient_fill.rb +9 -9
  66. data/lib/axlsx/stylesheet/gradient_stop.rb +7 -6
  67. data/lib/axlsx/stylesheet/num_fmt.rb +9 -14
  68. data/lib/axlsx/stylesheet/pattern_fill.rb +8 -8
  69. data/lib/axlsx/stylesheet/styles.rb +104 -98
  70. data/lib/axlsx/stylesheet/table_style.rb +8 -9
  71. data/lib/axlsx/stylesheet/table_style_element.rb +7 -8
  72. data/lib/axlsx/stylesheet/table_styles.rb +8 -10
  73. data/lib/axlsx/stylesheet/xf.rb +21 -22
  74. data/lib/axlsx/util/accessors.rb +6 -6
  75. data/lib/axlsx/util/buffered_zip_output_stream.rb +60 -0
  76. data/lib/axlsx/util/constants.rb +119 -108
  77. data/lib/axlsx/util/mime_type_utils.rb +11 -0
  78. data/lib/axlsx/util/options_parser.rb +4 -3
  79. data/lib/axlsx/util/serialized_attributes.rb +45 -21
  80. data/lib/axlsx/util/simple_typed_list.rb +58 -57
  81. data/lib/axlsx/util/storage.rb +38 -41
  82. data/lib/axlsx/util/validators.rb +107 -44
  83. data/lib/axlsx/util/zip_command.rb +10 -12
  84. data/lib/axlsx/version.rb +3 -2
  85. data/lib/axlsx/workbook/defined_name.rb +11 -8
  86. data/lib/axlsx/workbook/defined_names.rb +4 -3
  87. data/lib/axlsx/workbook/shared_strings_table.rb +10 -11
  88. data/lib/axlsx/workbook/workbook.rb +121 -114
  89. data/lib/axlsx/workbook/workbook_view.rb +8 -11
  90. data/lib/axlsx/workbook/workbook_views.rb +4 -4
  91. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +72 -14
  92. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +11 -7
  93. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +24 -21
  94. data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +51 -0
  95. data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +56 -0
  96. data/lib/axlsx/workbook/worksheet/border_creator.rb +30 -25
  97. data/lib/axlsx/workbook/worksheet/break.rb +4 -5
  98. data/lib/axlsx/workbook/worksheet/cell.rb +92 -65
  99. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +32 -28
  100. data/lib/axlsx/workbook/worksheet/cfvo.rb +7 -5
  101. data/lib/axlsx/workbook/worksheet/cfvos.rb +5 -5
  102. data/lib/axlsx/workbook/worksheet/col.rb +9 -10
  103. data/lib/axlsx/workbook/worksheet/col_breaks.rb +8 -7
  104. data/lib/axlsx/workbook/worksheet/color_scale.rb +16 -16
  105. data/lib/axlsx/workbook/worksheet/cols.rb +9 -7
  106. data/lib/axlsx/workbook/worksheet/comment.rb +12 -11
  107. data/lib/axlsx/workbook/worksheet/comments.rb +10 -12
  108. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +12 -8
  109. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +19 -21
  110. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +5 -5
  111. data/lib/axlsx/workbook/worksheet/data_bar.rb +29 -30
  112. data/lib/axlsx/workbook/worksheet/data_validation.rb +34 -33
  113. data/lib/axlsx/workbook/worksheet/data_validations.rb +5 -6
  114. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +8 -8
  115. data/lib/axlsx/workbook/worksheet/dimension.rb +9 -6
  116. data/lib/axlsx/workbook/worksheet/header_footer.rb +4 -3
  117. data/lib/axlsx/workbook/worksheet/icon_set.rb +24 -8
  118. data/lib/axlsx/workbook/worksheet/merged_cells.rb +10 -10
  119. data/lib/axlsx/workbook/worksheet/outline_pr.rb +6 -3
  120. data/lib/axlsx/workbook/worksheet/page_margins.rb +17 -12
  121. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +6 -4
  122. data/lib/axlsx/workbook/worksheet/page_setup.rb +128 -129
  123. data/lib/axlsx/workbook/worksheet/pane.rb +27 -26
  124. data/lib/axlsx/workbook/worksheet/pivot_table.rb +23 -25
  125. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +12 -13
  126. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +5 -4
  127. data/lib/axlsx/workbook/worksheet/print_options.rb +3 -2
  128. data/lib/axlsx/workbook/worksheet/protected_range.rb +6 -5
  129. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +12 -10
  130. data/lib/axlsx/workbook/worksheet/rich_text.rb +6 -6
  131. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +35 -17
  132. data/lib/axlsx/workbook/worksheet/row.rb +30 -22
  133. data/lib/axlsx/workbook/worksheet/row_breaks.rb +8 -7
  134. data/lib/axlsx/workbook/worksheet/selection.rb +16 -16
  135. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +10 -7
  136. data/lib/axlsx/workbook/worksheet/sheet_data.rb +7 -7
  137. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +23 -19
  138. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +11 -7
  139. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +21 -20
  140. data/lib/axlsx/workbook/worksheet/sheet_view.rb +48 -53
  141. data/lib/axlsx/workbook/worksheet/table.rb +13 -13
  142. data/lib/axlsx/workbook/worksheet/table_style_info.rb +6 -5
  143. data/lib/axlsx/workbook/worksheet/tables.rb +7 -5
  144. data/lib/axlsx/workbook/worksheet/worksheet.rb +92 -63
  145. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +10 -8
  146. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +11 -4
  147. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +9 -8
  148. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +7 -5
  149. data/lib/axlsx.rb +75 -47
  150. data/lib/caxlsx.rb +3 -2
  151. metadata +50 -44
@@ -1,11 +1,11 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # Selection options for worksheet panes.
4
5
  #
5
6
  # @note The recommended way to manage the selection pane options is via SheetView#add_selection
6
7
  # @see SheetView#add_selection
7
8
  class Selection
8
-
9
9
  include Axlsx::OptionsParser
10
10
  include Axlsx::SerializedAttributes
11
11
 
@@ -14,7 +14,7 @@ module Axlsx
14
14
  # @option options [Integer] active_cell_id Active Cell Index
15
15
  # @option options [Symbol] pane Pane
16
16
  # @option options [String] sqref Sequence of References
17
- def initialize(options={})
17
+ def initialize(options = {})
18
18
  @active_cell = @active_cell_id = @pane = @sqref = nil
19
19
  parse_options options
20
20
  end
@@ -40,16 +40,16 @@ module Axlsx
40
40
 
41
41
  # Pane
42
42
  # The pane to which this selection belongs.
43
- # Options are
43
+ # Options are
44
44
  # * bottom_left: Bottom left pane, when both vertical and horizontal
45
45
  # splits are applied. This value is also used when only
46
- # a horizontal split has been applied, dividing the pane
47
- # into upper and lower regions. In that case, this value
46
+ # a horizontal split has been applied, dividing the pane
47
+ # into upper and lower regions. In that case, this value
48
48
  # specifies the bottom pane.
49
49
  # * bottom_right: Bottom right pane, when both vertical and horizontal
50
50
  # splits are applied.
51
51
  # * top_left: Top left pane, when both vertical and horizontal splits
52
- # are applied. This value is also used when only a horizontal
52
+ # are applied. This value is also used when only a horizontal
53
53
  # split has been applied, dividing the pane into upper and lower
54
54
  # regions. In that case, this value specifies the top pane.
55
55
  # This value is also used when only a vertical split has
@@ -57,8 +57,8 @@ module Axlsx
57
57
  # regions. In that case, this value specifies the left pane
58
58
  # * top_right: Top right pane, when both vertical and horizontal
59
59
  # splits are applied. This value is also used when only
60
- # a vertical split has been applied, dividing the pane
61
- # into right and left regions. In that case, this value
60
+ # a vertical split has been applied, dividing the pane
61
+ # into right and left regions. In that case, this value
62
62
  # specifies the right pane.
63
63
  # @see type
64
64
  # @return [Symbol]
@@ -74,27 +74,27 @@ module Axlsx
74
74
 
75
75
  # @see active_cell
76
76
  def active_cell=(v)
77
- cell = (v.class == Axlsx::Cell ? v.r_abs : v)
78
- Axlsx::validate_string(cell)
77
+ cell = (v.instance_of?(Axlsx::Cell) ? v.r_abs : v)
78
+ Axlsx.validate_string(cell)
79
79
  @active_cell = cell
80
80
  end
81
81
 
82
82
  # @see active_cell_id
83
- def active_cell_id=(v); Axlsx::validate_unsigned_int(v); @active_cell_id = v end
83
+ def active_cell_id=(v); Axlsx.validate_unsigned_int(v); @active_cell_id = v end
84
84
 
85
85
  # @see pane
86
86
  def pane=(v)
87
- Axlsx::validate_pane_type(v)
88
- @pane = Axlsx::camel(v, false)
87
+ Axlsx.validate_pane_type(v)
88
+ @pane = Axlsx.camel(v, false)
89
89
  end
90
90
 
91
91
  # @see sqref
92
- def sqref=(v); Axlsx::validate_string(v); @sqref = v end
92
+ def sqref=(v); Axlsx.validate_string(v); @sqref = v end
93
93
 
94
94
  # Serializes the data validation
95
95
  # @param [String] str
96
96
  # @return [String]
97
- def to_xml_string(str = '')
97
+ def to_xml_string(str = +'')
98
98
  serialized_tag 'selection', str
99
99
  end
100
100
  end
@@ -1,15 +1,16 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # the SheetCalcPr object for the worksheet
4
5
  # This object contains calculation properties for the worksheet.
5
6
  class SheetCalcPr
6
- include Axlsx::OptionsParser
7
- include Axlsx::SerializedAttributes
8
- include Axlsx::Accessors
7
+ include Axlsx::OptionsParser
8
+ include Axlsx::SerializedAttributes
9
+ include Axlsx::Accessors
9
10
  # creates a new SheetCalcPr
10
11
  # @param [Hash] options Options for this object
11
12
  # @option [Boolean] full_calc_on_load @see full_calc_on_load
12
- def initialize(options={})
13
+ def initialize(options = {})
13
14
  @full_calc_on_load = true
14
15
  parse_options options
15
16
  end
@@ -22,8 +23,10 @@ module Axlsx
22
23
  # @param [String] str the string to append this objects serialized
23
24
  # content to.
24
25
  # @return [String]
25
- def to_xml_string(str='')
26
- str << "<sheetCalcPr #{serialized_attributes}/>"
26
+ def to_xml_string(str = +'')
27
+ str << '<sheetCalcPr '
28
+ serialized_attributes(str)
29
+ str << '/>'
27
30
  end
28
31
  end
29
32
  end
@@ -1,27 +1,27 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # This class manages the serialization of rows for worksheets
4
5
  class SheetData
5
-
6
6
  # Creates a new SheetData object
7
7
  # @param [Worksheet] worksheet The worksheet that owns this sheet data.
8
8
  def initialize(worksheet)
9
9
  raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
10
+
10
11
  @worksheet = worksheet
11
12
  end
12
-
13
+
13
14
  attr_reader :worksheet
14
15
 
15
16
  # Serialize the sheet data
16
17
  # @param [String] str the string this objects serializaton will be concacted to.
17
18
  # @return [String]
18
- def to_xml_string(str = '')
19
+ def to_xml_string(str = +'')
19
20
  str << '<sheetData>'
20
- worksheet.rows.each_with_index do |row, index|
21
- row.to_xml_string(index, str)
21
+ worksheet.rows.each_with_index do |row, index|
22
+ row.to_xml_string(index, str)
22
23
  end
23
24
  str << '</sheetData>'
24
25
  end
25
-
26
26
  end
27
27
  end
@@ -1,17 +1,18 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
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>
3
+ module Axlsx
4
+ # Sheet formatting properties
5
+ # <xsd:complexType name="CT_SheetFormatPr">
6
+ # <xsd:attribute name="baseColWidth" type="xsd:unsignedInt" use="optional" default="8"/>
7
+ # <xsd:attribute name="defaultColWidth" type="xsd:double" use="optional"/>
8
+ # <xsd:attribute name="defaultRowHeight" type="xsd:double" use="required"/>
9
+ # <xsd:attribute name="customHeight" type="xsd:boolean" use="optional" default="false"/>
10
+ # <xsd:attribute name="zeroHeight" type="xsd:boolean" use="optional" default="false"/>
11
+ # <xsd:attribute name="thickTop" type="xsd:boolean" use="optional" default="false"/>
12
+ # <xsd:attribute name="thickBottom" type="xsd:boolean" use="optional" default="false"/>
13
+ # <xsd:attribute name="outlineLevelRow" type="xsd:unsignedByte" use="optional" default="0"/>
14
+ # <xsd:attribute name="outlineLevelCol" type="xsd:unsignedByte" use="optional" default="0"/>
15
+ # </xsd:complexType>
15
16
 
16
17
  class SheetFormatPr
17
18
  include Axlsx::SerializedAttributes
@@ -29,29 +30,32 @@ module Axlsx
29
30
  # @option [Boolean] thick_bottom 'True' if rows have a thick bottom border by default.
30
31
  # @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
32
  # @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
+ def initialize(options = {})
33
34
  set_defaults
34
35
  parse_options options
35
36
  end
36
37
 
37
38
  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
39
+ :custom_height, :zero_height, :thick_top, :thick_bottom,
40
+ :outline_level_row, :outline_level_col
40
41
 
41
42
  float_attr_accessor :default_col_width, :default_row_height
42
43
 
43
44
  boolean_attr_accessor :custom_height, :zero_height, :thick_top, :thick_bottom
44
45
 
45
- unsigned_int_attr_accessor :base_col_width, :outline_level_row, :outline_level_col
46
+ unsigned_int_attr_accessor :base_col_width, :outline_level_row, :outline_level_col
46
47
 
47
48
  # serializes this object to an xml string
48
49
  # @param [String] str The string this objects serialization will be appended to
49
50
  # @return [String]
50
- def to_xml_string(str='')
51
- str << "<sheetFormatPr #{serialized_attributes}/>"
51
+ def to_xml_string(str = +'')
52
+ str << '<sheetFormatPr '
53
+ serialized_attributes(str)
54
+ str << '/>'
52
55
  end
53
56
 
54
57
  private
58
+
55
59
  def set_defaults
56
60
  @base_col_width = 8
57
61
  @default_row_height = 18
@@ -1,5 +1,6 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # The SheetPr class manages serialization of a worksheet's sheetPr element.
4
5
  class SheetPr
5
6
  include Axlsx::OptionsParser
@@ -30,8 +31,9 @@ module Axlsx
30
31
 
31
32
  # Creates a new SheetPr object
32
33
  # @param [Worksheet] worksheet The worksheet that owns this SheetPr object
33
- def initialize(worksheet, options={})
34
+ def initialize(worksheet, options = {})
34
35
  raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
36
+
35
37
  @worksheet = worksheet
36
38
  @outline_pr = nil
37
39
  parse_options options
@@ -48,9 +50,11 @@ module Axlsx
48
50
  # Serialize the object
49
51
  # @param [String] str serialized output will be appended to this object if provided.
50
52
  # @return [String]
51
- def to_xml_string(str = '')
53
+ def to_xml_string(str = +'')
52
54
  update_properties
53
- str << "<sheetPr #{serialized_attributes}>"
55
+ str << '<sheetPr '
56
+ serialized_attributes(str)
57
+ str << '>'
54
58
  tab_color.to_xml_string(str, 'tabColor') if tab_color
55
59
  outline_pr.to_xml_string(str) if @outline_pr
56
60
  page_setup_pr.to_xml_string(str)
@@ -62,7 +66,7 @@ module Axlsx
62
66
  def page_setup_pr
63
67
  @page_setup_pr ||= PageSetUpPr.new
64
68
  end
65
-
69
+
66
70
  # The OutlinePr for this sheet pr object
67
71
  # @return [OutlinePr]
68
72
  def outline_pr
@@ -71,14 +75,14 @@ module Axlsx
71
75
 
72
76
  # @see tab_color
73
77
  def tab_color=(v)
74
- @tab_color ||= Color.new(:rgb => v)
78
+ @tab_color = Color.new(rgb: v)
75
79
  end
76
80
 
77
81
  private
78
82
 
79
83
  def update_properties
80
84
  page_setup_pr.fit_to_page = worksheet.fit_to_page?
81
- if worksheet.auto_filter.columns.size > 0
85
+ unless worksheet.auto_filter.columns.empty?
82
86
  self.filter_mode = 1
83
87
  self.enable_format_conditions_calculation = 1
84
88
  end
@@ -1,9 +1,8 @@
1
- # encoding: UTF-8
2
- module Axlsx
1
+ # frozen_string_literal: true
3
2
 
3
+ module Axlsx
4
4
  # The SheetProtection object manages worksheet protection options per sheet.
5
5
  class SheetProtection
6
-
7
6
  include Axlsx::OptionsParser
8
7
  include Axlsx::SerializedAttributes
9
8
  include Axlsx::Accessors
@@ -26,7 +25,7 @@ module Axlsx
26
25
  # @option options [Boolean] pivot_tables @see SheetProtection#pivot_tables
27
26
  # @option options [Boolean] select_unlocked_cells @see SheetProtection#select_unlocked_cells
28
27
  # @option options [String] password. The password required for unlocking. @see SheetProtection#password=
29
- def initialize(options={})
28
+ def initialize(options = {})
30
29
  @objects = @scenarios = @select_locked_cells = @select_unlocked_cells = false
31
30
  @sheet = @format_cells = @format_rows = @format_columns = @insert_columns = @insert_rows = @insert_hyperlinks = @delete_columns = @delete_rows = @sort = @auto_filter = @pivot_tables = true
32
31
  @password = nil
@@ -34,12 +33,12 @@ module Axlsx
34
33
  end
35
34
 
36
35
  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
36
+ :insert_columns, :insert_rows, :insert_hyperlinks, :delete_columns, :delete_rows,
37
+ :select_locked_cells, :sort, :auto_filter, :pivot_tables, :select_unlocked_cells
39
38
 
40
39
  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
40
+ :insert_columns, :insert_rows, :insert_hyperlinks, :delete_columns, :delete_rows,
41
+ :select_locked_cells, :sort, :auto_filter, :pivot_tables, :select_unlocked_cells, :salt, :password
43
42
 
44
43
  # Specifies the salt which was prepended to the user-supplied password before it was hashed using the hashing algorithm
45
44
  # @return [String]
@@ -50,9 +49,9 @@ module Axlsx
50
49
  # default nil
51
50
  attr_reader :password
52
51
 
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
52
+ # This block is intended to implement the salt_value, hash_value and spin count as per the ECMA-376 standard.
53
+ # However, it does not seem to actually work in EXCEL - instead they are using their old retro algorithm shown below
54
+ # defined in the transitional portion of the speck. I am leaving this code in in the hope that someday Ill be able to
56
55
  # figure out why it does not work, and if Excel even supports it.
57
56
  # def propper_password=(v)
58
57
  # @algorithm_name = v == nil ? nil : 'SHA-1'
@@ -68,48 +67,50 @@ module Axlsx
68
67
 
69
68
  # encodes password for protection locking
70
69
  def password=(v)
71
- return if v == nil
70
+ return if v.nil?
71
+
72
72
  @password = create_password_hash(v)
73
73
  end
74
74
 
75
75
  # Serialize the object
76
76
  # @param [String] str
77
77
  # @return [String]
78
- def to_xml_string(str = '')
78
+ def to_xml_string(str = +'')
79
79
  serialized_tag('sheetProtection', str)
80
80
  end
81
81
 
82
82
  private
83
+
83
84
  # Creates a password hash for a given password
84
85
  # @return [String]
85
86
  def create_password_hash(password)
86
87
  encoded_password = encode_password(password)
87
88
 
88
89
  password_as_hex = [encoded_password].pack("v")
89
- password_as_string = password_as_hex.unpack("H*").first.upcase
90
+ password_as_string = password_as_hex.unpack1("H*").upcase
90
91
 
91
92
  password_as_string[2..3] + password_as_string[0..1]
92
93
  end
93
94
 
94
95
  # Encodes a given password
95
96
  # Based on the algorithm provided by Daniel Rentz of OpenOffice.
96
- # http://www.openoffice.org/sc/excelfileformat.pdf, Revision 1.42, page 115 (21.05.2012)
97
+ # https://www.openoffice.org/sc/excelfileformat.pdf, Revision 1.42, page 115 (21.05.2012)
97
98
  # @return [String]
98
99
  def encode_password(password)
99
100
  i = 0
100
- chars = password.split(//)
101
+ chars = password.chars
101
102
  count = chars.size
102
103
 
103
104
  chars.collect! do |char|
104
105
  i += 1
105
- char = char.unpack('c')[0] << i #ord << i
106
+ char = char.unpack1('c') << i # ord << i
106
107
  low_15 = char & 0x7fff
107
- high_15 = char & 0x7fff << 15
108
+ high_15 = char & (0x7fff << 15)
108
109
  high_15 = high_15 >> 15
109
- char = low_15 | high_15
110
+ low_15 | high_15
110
111
  end
111
112
 
112
- encoded_password = 0x0000
113
+ encoded_password = 0x0000
113
114
  chars.each { |c| encoded_password ^= c }
114
115
  encoded_password ^= count
115
116
  encoded_password ^= 0xCE4B
@@ -1,11 +1,11 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # View options for a worksheet.
4
5
  #
5
6
  # @note The recommended way to manage the sheet view is via Worksheet#sheet_view
6
7
  # @see Worksheet#sheet_view
7
8
  class SheetView
8
-
9
9
  include Axlsx::OptionsParser
10
10
  include Axlsx::Accessors
11
11
  include Axlsx::SerializedAttributes
@@ -30,8 +30,8 @@ module Axlsx
30
30
  # @option options [Integer] zoom_scale_normal Zoom Scale Normal View
31
31
  # @option options [Integer] zoom_scale_page_layout_view Zoom Scale Page Layout View
32
32
  # @option options [Integer] zoom_scale_sheet_layout_view Zoom Scale Page Break Preview
33
- def initialize(options={})
34
- #defaults
33
+ def initialize(options = {})
34
+ # defaults
35
35
  @color_id = @top_left_cell = @pane = nil
36
36
  @right_to_left = @show_formulas = @show_outline_symbols = @show_white_space = @tab_selected = @window_protection = false
37
37
  @default_grid_color = @show_grid_lines = @show_row_col_headers = @show_ruler = @show_zeros = true
@@ -42,16 +42,15 @@ module Axlsx
42
42
  end
43
43
 
44
44
  boolean_attr_accessor :default_grid_color, :right_to_left, :show_formulas, :show_grid_lines,
45
- :show_row_col_headers, :show_ruler, :show_white_space, :show_zeros, :tab_selected, :window_protection, :show_outline_symbols
45
+ :show_row_col_headers, :show_ruler, :show_white_space, :show_zeros, :tab_selected, :window_protection, :show_outline_symbols
46
46
 
47
47
  serializable_attributes :default_grid_color, :right_to_left, :show_formulas, :show_grid_lines,
48
- :show_row_col_headers, :show_ruler, :show_white_space, :show_zeros, :tab_selected, :window_protection, :show_outline_symbols,
49
- :zoom_scale_sheet_layout_view, :zoom_scale_page_layout_view, :zoom_scale_normal, :workbook_view_id,
50
- :view, :top_left_cell, :color_id, :zoom_scale
51
-
48
+ :show_row_col_headers, :show_ruler, :show_white_space, :show_zeros, :tab_selected, :window_protection, :show_outline_symbols,
49
+ :zoom_scale_sheet_layout_view, :zoom_scale_page_layout_view, :zoom_scale_normal, :workbook_view_id,
50
+ :view, :top_left_cell, :color_id, :zoom_scale
52
51
 
53
52
  # instance values that must be serialized as their own elements - e.g. not attributes.
54
- CHILD_ELEMENTS = [ :pane, :selections ]
53
+ CHILD_ELEMENTS = [:pane, :selections].freeze
55
54
 
56
55
  # The pane object for the sheet view
57
56
  # @return [Pane]
@@ -66,11 +65,11 @@ module Axlsx
66
65
  # @return [Hash]
67
66
  attr_reader :selections
68
67
 
69
- #
68
+ #
70
69
  # Color Id
71
70
  # Index to the color value for row/column
72
- # text headings and gridlines. This is an
73
- # 'index color value' (ICV) rather than
71
+ # text headings and gridlines. This is an
72
+ # 'index color value' (ICV) rather than
74
73
  # rgb value.
75
74
  # @see type
76
75
  # @return [Integer]
@@ -78,18 +77,17 @@ module Axlsx
78
77
  attr_reader :color_id
79
78
 
80
79
  # Top Left Visible Cell
81
- # Location of the top left visible cell Location
80
+ # Location of the top left visible cell Location
82
81
  # of the top left visible cell in the bottom right
83
82
  # pane (when in Left-to-Right mode).
84
83
  # @see type
85
84
  # @return [String]
86
85
  # default nil
87
86
  attr_reader :top_left_cell
88
-
89
-
87
+
90
88
  # View Type
91
89
  # Indicates the view type.
92
- # Options are
90
+ # Options are
93
91
  # * normal: Normal view
94
92
  # * page_break_preview: Page break preview
95
93
  # * page_layout: Page Layout View
@@ -99,62 +97,59 @@ module Axlsx
99
97
  attr_reader :view
100
98
 
101
99
  # Workbook View Index
102
- # Zero-based index of this workbook view, pointing
100
+ # Zero-based index of this workbook view, pointing
103
101
  # to a workbookView element in the bookViews collection.
104
102
  # @see type
105
- # @return [Integer]
103
+ # @return [Integer]
106
104
  # default 0
107
105
  attr_reader :workbook_view_id
108
106
 
109
107
  # Zoom Scale
110
- # Window zoom magnification for current view
108
+ # Window zoom magnification for current view
111
109
  # representing percent values. This attribute
112
- # is restricted to values ranging from 10 to 400.
110
+ # is restricted to values ranging from 10 to 400.
113
111
  # Horizontal & Vertical scale together.
114
- # Current view can be Normal, Page Layout, or
112
+ # Current view can be Normal, Page Layout, or
115
113
  # Page Break Preview.
116
114
  # @see type
117
- # @return [Integer]
115
+ # @return [Integer]
118
116
  # default 100
119
117
  attr_reader :zoom_scale
120
118
 
121
-
122
119
  # Zoom Scale Normal View
123
- # Zoom magnification to use when in normal view,
124
- # representing percent values. This attribute is
125
- # restricted to values ranging from 10 to 400.
120
+ # Zoom magnification to use when in normal view,
121
+ # representing percent values. This attribute is
122
+ # restricted to values ranging from 10 to 400.
126
123
  # Horizontal & Vertical scale together.
127
- # Applies for worksheets only; zero implies the
124
+ # Applies for worksheets only; zero implies the
128
125
  # automatic setting.
129
126
  # @see type
130
- # @return [Integer]
127
+ # @return [Integer]
131
128
  # default 0
132
129
  attr_reader :zoom_scale_normal
133
130
 
134
-
135
131
  # Zoom Scale Page Layout View
136
- # Zoom magnification to use when in page layout
137
- # view, representing percent values. This attribute
138
- # is restricted to values ranging from 10 to 400.
132
+ # Zoom magnification to use when in page layout
133
+ # view, representing percent values. This attribute
134
+ # is restricted to values ranging from 10 to 400.
139
135
  # Horizontal & Vertical scale together.
140
- # Applies for worksheets only; zero implies
136
+ # Applies for worksheets only; zero implies
141
137
  # the automatic setting.
142
138
  # @see type
143
- # @return [Integer]
139
+ # @return [Integer]
144
140
  # default 0
145
141
  attr_reader :zoom_scale_page_layout_view
146
142
 
147
-
148
143
  # Zoom Scale Page Break Preview
149
- # Zoom magnification to use when in page break
150
- # preview, representing percent values. This
151
- # attribute is restricted to values ranging
144
+ # Zoom magnification to use when in page break
145
+ # preview, representing percent values. This
146
+ # attribute is restricted to values ranging
152
147
  # from 10 to 400. Horizontal & Vertical scale
153
148
  # together.
154
- # Applies for worksheet only; zero implies
149
+ # Applies for worksheet only; zero implies
155
150
  # the automatic setting.
156
151
  # @see type
157
- # @return [Integer]
152
+ # @return [Integer]
158
153
  # default 0
159
154
  attr_reader :zoom_scale_sheet_layout_view
160
155
 
@@ -163,47 +158,47 @@ module Axlsx
163
158
  # param [Hash] options
164
159
  # return [Selection]
165
160
  def add_selection(pane, options = {})
166
- @selections[pane] = Selection.new(options.merge(:pane => pane))
161
+ @selections[pane] = Selection.new(options.merge(pane: pane))
167
162
  end
168
163
 
169
164
  # @see color_id
170
- def color_id=(v); Axlsx::validate_unsigned_int(v); @color_id = v end
165
+ def color_id=(v); Axlsx.validate_unsigned_int(v); @color_id = v end
171
166
 
172
167
  # @see top_left_cell
173
168
  def top_left_cell=(v)
174
- cell = (v.class == Axlsx::Cell ? v.r_abs : v)
175
- Axlsx::validate_string(cell)
169
+ cell = (v.instance_of?(Axlsx::Cell) ? v.r_abs : v)
170
+ Axlsx.validate_string(cell)
176
171
  @top_left_cell = cell
177
172
  end
178
173
 
179
174
  # @see view
180
- def view=(v); Axlsx::validate_sheet_view_type(v); @view = v end
175
+ def view=(v); Axlsx.validate_sheet_view_type(v); @view = v end
181
176
 
182
177
  # @see workbook_view_id
183
- def workbook_view_id=(v); Axlsx::validate_unsigned_int(v); @workbook_view_id = v end
178
+ def workbook_view_id=(v); Axlsx.validate_unsigned_int(v); @workbook_view_id = v end
184
179
 
185
180
  # @see zoom_scale
186
- def zoom_scale=(v); Axlsx::validate_scale_0_10_400(v); @zoom_scale = v end
181
+ def zoom_scale=(v); Axlsx.validate_scale_0_10_400(v); @zoom_scale = v end
187
182
 
188
183
  # @see zoom_scale_normal
189
- def zoom_scale_normal=(v); Axlsx::validate_scale_0_10_400(v); @zoom_scale_normal = v end
184
+ def zoom_scale_normal=(v); Axlsx.validate_scale_0_10_400(v); @zoom_scale_normal = v end
190
185
 
191
186
  # @see zoom_scale_page_layout_view
192
- def zoom_scale_page_layout_view=(v); Axlsx::validate_scale_0_10_400(v); @zoom_scale_page_layout_view = v end
187
+ def zoom_scale_page_layout_view=(v); Axlsx.validate_scale_0_10_400(v); @zoom_scale_page_layout_view = v end
193
188
 
194
189
  # @see zoom_scale_sheet_layout_view
195
- def zoom_scale_sheet_layout_view=(v); Axlsx::validate_scale_0_10_400(v); @zoom_scale_sheet_layout_view = v end
190
+ def zoom_scale_sheet_layout_view=(v); Axlsx.validate_scale_0_10_400(v); @zoom_scale_sheet_layout_view = v end
196
191
 
197
192
  # Serializes the data validation
198
193
  # @param [String] str
199
194
  # @return [String]
200
- def to_xml_string(str = '')
195
+ def to_xml_string(str = +'')
201
196
  str << '<sheetViews>'
202
197
  str << '<sheetView '
203
198
  serialized_attributes str
204
199
  str << '>'
205
200
  @pane.to_xml_string(str) if @pane
206
- @selections.each do |key, selection|
201
+ @selections.each_value do |selection|
207
202
  selection.to_xml_string(str)
208
203
  end
209
204
  str << '</sheetView>'