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,10 +1,10 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # Table
4
5
  # @note Worksheet#add_pivot_table is the recommended way to create tables for your worksheets.
5
6
  # @see README for examples
6
7
  class PivotTableCacheDefinition
7
-
8
8
  include Axlsx::OptionsParser
9
9
 
10
10
  # Creates a new PivotTable object
@@ -26,7 +26,7 @@ module Axlsx
26
26
  # The part name for this table
27
27
  # @return [String]
28
28
  def pn
29
- "#{PIVOT_TABLE_CACHE_DEFINITION_PN % (index+1)}"
29
+ format(PIVOT_TABLE_CACHE_DEFINITION_PN, index + 1)
30
30
  end
31
31
 
32
32
  # The identifier for this cache
@@ -45,22 +45,21 @@ module Axlsx
45
45
  # Serializes the object
46
46
  # @param [String] str
47
47
  # @return [String]
48
- def to_xml_string(str = '')
48
+ def to_xml_string(str = +'')
49
49
  str << '<?xml version="1.0" encoding="UTF-8"?>'
50
- str << ('<pivotCacheDefinition xmlns="' << XML_NS << '" xmlns:r="' << XML_NS_R << '" invalid="1" refreshOnLoad="1" recordCount="0">')
51
- str << '<cacheSource type="worksheet">'
52
- str << ( '<worksheetSource ref="' << pivot_table.range << '" sheet="' << pivot_table.data_sheet.name << '"/>')
53
- str << '</cacheSource>'
54
- str << ( '<cacheFields count="' << pivot_table.header_cells_count.to_s << '">')
50
+ str << '<pivotCacheDefinition xmlns="' << XML_NS << '" xmlns:r="' << XML_NS_R << '" invalid="1" refreshOnLoad="1" recordCount="0">'
51
+ str << '<cacheSource type="worksheet">'
52
+ str << '<worksheetSource ref="' << pivot_table.range << '" sheet="' << pivot_table.data_sheet.name << '"/>'
53
+ str << '</cacheSource>'
54
+ str << '<cacheFields count="' << pivot_table.header_cells_count.to_s << '">'
55
55
  pivot_table.header_cells.each do |cell|
56
- str << ( '<cacheField name="' << cell.clean_value << '" numFmtId="0">')
56
+ str << '<cacheField name="' << cell.clean_value << '" numFmtId="0">'
57
57
  str << '<sharedItems count="0">'
58
58
  str << '</sharedItems>'
59
- str << '</cacheField>'
59
+ str << '</cacheField>'
60
60
  end
61
- str << '</cacheFields>'
61
+ str << '</cacheFields>'
62
62
  str << '</pivotCacheDefinition>'
63
63
  end
64
-
65
64
  end
66
65
  end
@@ -1,11 +1,12 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # A simple, self serializing class for storing pivot tables
4
5
  class PivotTables < SimpleTypedList
5
-
6
6
  # creates a new Tables object
7
7
  def initialize(worksheet)
8
8
  raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
9
+
9
10
  super PivotTable
10
11
  @worksheet = worksheet
11
12
  end
@@ -17,8 +18,8 @@ module Axlsx
17
18
  # returns the relationships required by this collection
18
19
  def relationships
19
20
  return [] if empty?
20
- map{ |pivot_table| Relationship.new(pivot_table, PIVOT_TABLE_R, "../#{pivot_table.pn}") }
21
+
22
+ map { |pivot_table| Relationship.new(pivot_table, PIVOT_TABLE_R, "../#{pivot_table.pn}") }
21
23
  end
22
24
  end
23
-
24
25
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # Options for printing a worksheet. All options are boolean and false by default.
3
5
  #
@@ -5,7 +7,6 @@ module Axlsx
5
7
  # @see Worksheet#print_options
6
8
  # @see Worksheet#initialize
7
9
  class PrintOptions
8
-
9
10
  include Axlsx::OptionsParser
10
11
  include Axlsx::SerializedAttributes
11
12
  include Axlsx::Accessors
@@ -32,7 +33,7 @@ module Axlsx
32
33
  # @note As all attributes default to "false" according to the xml schema definition, the generated xml includes only those attributes that are set to true.
33
34
  # @param [String] str
34
35
  # @return [String]
35
- def to_xml_string(str = '')
36
+ def to_xml_string(str = +'')
36
37
  serialized_tag 'printOptions', str
37
38
  end
38
39
  end
@@ -1,16 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # The Protected Range class represents a set of cells in the worksheet
3
5
  # @note the recommended way to manage protected ranges with via Worksheet#protect_range
4
6
  # @see Worksheet#protect_range
5
7
  class ProtectedRange
6
-
7
8
  include Axlsx::OptionsParser
8
9
  include Axlsx::SerializedAttributes
9
10
 
10
- # Initializes a new protected range object
11
+ # Initializes a new protected range object
11
12
  # @option [String] sqref The cell range reference to protect. This can be an absolute or a relateve range however, it only applies to the current sheet.
12
13
  # @option [String] name An optional name for the protected name.
13
- def initialize(options={})
14
+ def initialize(options = {})
14
15
  parse_options options
15
16
  yield self if block_given?
16
17
  end
@@ -40,8 +41,8 @@ module Axlsx
40
41
  # @param [String] str if this string object is provided we append
41
42
  # our output to that object. Use this - it helps limit the number of
42
43
  # objects created during serialization
43
- def to_xml_string(str="")
44
+ def to_xml_string(str = +'')
44
45
  serialized_tag 'protectedRange', str
45
- end
46
+ end
46
47
  end
47
48
  end
@@ -1,13 +1,14 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # A self serializing collection of ranges that should be protected in
4
5
  # the worksheet
5
6
  class ProtectedRanges < SimpleTypedList
6
-
7
7
  attr_reader :worksheet
8
8
 
9
9
  def initialize(worksheet)
10
10
  raise ArgumentError, 'You must provide a worksheet' unless worksheet.is_a?(Worksheet)
11
+
11
12
  super ProtectedRange
12
13
  @worksheet = worksheet
13
14
  end
@@ -15,20 +16,21 @@ module Axlsx
15
16
  # Adds a protected range
16
17
  # @param [Array|String] cells A string range reference or array of cells that will be protected
17
18
  def add_range(cells)
18
- sqref = if cells.is_a?(String)
19
- cells
20
- elsif cells.is_a?(SimpleTypedList) || cells.is_a?(Array)
21
- Axlsx::cell_range(cells, false)
22
- end
23
- self << ProtectedRange.new(:sqref => sqref, :name => "Range#{size}")
24
- last
19
+ sqref = if cells.is_a?(String)
20
+ cells
21
+ elsif cells.is_a?(SimpleTypedList) || cells.is_a?(Array)
22
+ Axlsx.cell_range(cells, false)
23
+ end
24
+ self << ProtectedRange.new(sqref: sqref, name: "Range#{size}")
25
+ last
25
26
  end
26
27
 
27
28
  # Serializes the protected ranges
28
29
  # @param [String] str
29
30
  # @return [String]
30
- def to_xml_string(str = '')
31
+ def to_xml_string(str = +'')
31
32
  return if empty?
33
+
32
34
  str << '<protectedRanges>'
33
35
  each { |range| range.to_xml_string(str) }
34
36
  str << '</protectedRanges>'
@@ -1,13 +1,13 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # A simple, self serializing class for storing TextRuns
4
5
  class RichText < SimpleTypedList
5
-
6
6
  # creates a new RichText collection
7
7
  # @param [String] text -optional The text to use in creating the first RichTextRun
8
8
  # @param [Object] options -optional The options to use in creating the first RichTextRun
9
9
  # @yield [RichText] self
10
- def initialize(text = nil, options={})
10
+ def initialize(text = nil, options = {})
11
11
  super(RichTextRun)
12
12
  add_run(text, options) unless text.nil?
13
13
  yield self if block_given?
@@ -34,7 +34,7 @@ module Axlsx
34
34
  # Creates and adds a RichTextRun to this collectino
35
35
  # @param [String] text The text to use in creating a new RichTextRun
36
36
  # @param [Object] options The options to use in creating the new RichTextRun
37
- def add_run(text, options={})
37
+ def add_run(text, options = {})
38
38
  self << RichTextRun.new(text, options)
39
39
  end
40
40
 
@@ -47,8 +47,8 @@ module Axlsx
47
47
  # renders the RichTextRuns in this collection
48
48
  # @param [String] str
49
49
  # @return [String]
50
- def to_xml_string(str='')
51
- each{ |run| run.to_xml_string(str) }
50
+ def to_xml_string(str = +'')
51
+ each { |run| run.to_xml_string(str) }
52
52
  str
53
53
  end
54
54
  end
@@ -1,8 +1,8 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # The RichTextRun class creates and self serializing text run.
4
5
  class RichTextRun
5
-
6
6
  include Axlsx::OptionsParser
7
7
 
8
8
  attr_reader :value
@@ -13,7 +13,7 @@ module Axlsx
13
13
  :shadow, :condense, :extend, :u,
14
14
  :vertAlign, :sz, :color, :scheme].freeze
15
15
 
16
- def initialize(value, options={})
16
+ def initialize(value, options = {})
17
17
  self.value = value
18
18
  parse_options(options)
19
19
  end
@@ -27,6 +27,7 @@ module Axlsx
27
27
  # The inline font_name property for the cell
28
28
  # @return [String]
29
29
  attr_reader :font_name
30
+
30
31
  # @see font_name
31
32
  def font_name=(v) set_run_style :validate_string, :font_name, v; end
32
33
 
@@ -53,6 +54,7 @@ module Axlsx
53
54
  # 255  OEM_CHARSET
54
55
  # @return [String]
55
56
  attr_reader :charset
57
+
56
58
  # @see charset
57
59
  def charset=(v) set_run_style :validate_unsigned_int, :charset, v; end
58
60
 
@@ -64,6 +66,7 @@ module Axlsx
64
66
  # 4 Script
65
67
  # 5 Decorative
66
68
  attr_reader :family
69
+
67
70
  # @see family
68
71
  def family=(v)
69
72
  set_run_style :validate_family, :family, v.to_i
@@ -72,42 +75,49 @@ module Axlsx
72
75
  # The inline bold property for the cell
73
76
  # @return [Boolean]
74
77
  attr_reader :b
78
+
75
79
  # @see b
76
80
  def b=(v) set_run_style :validate_boolean, :b, v; end
77
81
 
78
82
  # The inline italic property for the cell
79
83
  # @return [Boolean]
80
84
  attr_reader :i
85
+
81
86
  # @see i
82
87
  def i=(v) set_run_style :validate_boolean, :i, v; end
83
88
 
84
89
  # The inline strike property for the cell
85
90
  # @return [Boolean]
86
91
  attr_reader :strike
92
+
87
93
  # @see strike
88
94
  def strike=(v) set_run_style :validate_boolean, :strike, v; end
89
95
 
90
96
  # The inline outline property for the cell
91
97
  # @return [Boolean]
92
98
  attr_reader :outline
99
+
93
100
  # @see outline
94
101
  def outline=(v) set_run_style :validate_boolean, :outline, v; end
95
102
 
96
103
  # The inline shadow property for the cell
97
104
  # @return [Boolean]
98
105
  attr_reader :shadow
106
+
99
107
  # @see shadow
100
108
  def shadow=(v) set_run_style :validate_boolean, :shadow, v; end
101
109
 
102
110
  # The inline condense property for the cell
103
111
  # @return [Boolean]
104
112
  attr_reader :condense
113
+
105
114
  # @see condense
106
115
  def condense=(v) set_run_style :validate_boolean, :condense, v; end
107
116
 
108
117
  # The inline extend property for the cell
109
118
  # @return [Boolean]
110
119
  attr_reader :extend
120
+
111
121
  # @see extend
112
122
  def extend=(v) set_run_style :validate_boolean, :extend, v; end
113
123
 
@@ -117,23 +127,26 @@ module Axlsx
117
127
  # @return [String]
118
128
  # @note true is for backwards compatability and is reassigned to :single
119
129
  attr_reader :u
130
+
120
131
  # @see u
121
132
  def u=(v)
122
- v = :single if (v == true || v == 1 || v == :true || v == 'true')
133
+ v = :single if v == true || v == 1 || v == :true || v == 'true'
123
134
  set_run_style :validate_cell_u, :u, v
124
135
  end
125
136
 
126
137
  # The inline color property for the cell
127
138
  # @return [Color]
128
139
  attr_reader :color
140
+
129
141
  # @param [String] v The 8 character representation for an rgb color #FFFFFFFF"
130
142
  def color=(v)
131
- @color = v.is_a?(Color) ? v : Color.new(:rgb=>v)
143
+ @color = v.is_a?(Color) ? v : Color.new(rgb: v)
132
144
  end
133
145
 
134
146
  # The inline sz property for the cell
135
147
  # @return [Inteter]
136
148
  attr_reader :sz
149
+
137
150
  # @see sz
138
151
  def sz=(v) set_run_style :validate_unsigned_int, :sz, v; end
139
152
 
@@ -141,6 +154,7 @@ module Axlsx
141
154
  # this must be one of [:baseline, :subscript, :superscript]
142
155
  # @return [Symbol]
143
156
  attr_reader :vertAlign
157
+
144
158
  # @see vertAlign
145
159
  def vertAlign=(v)
146
160
  RestrictionValidator.validate :cell_vertAlign, [:baseline, :subscript, :superscript], v
@@ -151,6 +165,7 @@ module Axlsx
151
165
  # this must be one of [:none, major, minor]
152
166
  # @return [Symbol]
153
167
  attr_reader :scheme
168
+
154
169
  # @see scheme
155
170
  def scheme=(v)
156
171
  RestrictionValidator.validate :cell_scheme, [:none, :major, :minor], v
@@ -162,6 +177,7 @@ module Axlsx
162
177
  # @return [Array]
163
178
  def autowidth(widtharray)
164
179
  return if value.nil?
180
+
165
181
  if styles.cellXfs[style].alignment && styles.cellXfs[style].alignment.wrap_text
166
182
  first = true
167
183
  value.to_s.split(/\r?\n/, -1).each do |line|
@@ -181,31 +197,32 @@ module Axlsx
181
197
  # Utility method for setting inline style attributes
182
198
  def set_run_style(validator, attr, value)
183
199
  return unless INLINE_STYLES.include?(attr.to_sym)
200
+
184
201
  Axlsx.send(validator, value) unless validator.nil?
185
- self.instance_variable_set :"@#{attr.to_s}", value
202
+ instance_variable_set :"@#{attr}", value
186
203
  end
187
204
 
188
205
  # Serializes the RichTextRun
189
206
  # @param [String] str
190
207
  # @return [String]
191
- def to_xml_string(str = '')
208
+ def to_xml_string(str = +'')
192
209
  valid = RichTextRun::INLINE_STYLES
193
- data = Hash[Axlsx.instance_values_for(self).map{ |k, v| [k.to_sym, v] }]
194
- data = data.select { |key, value| valid.include?(key) && !value.nil? }
210
+ data = Axlsx.instance_values_for(self).transform_keys(&:to_sym)
211
+ data = data.select { |key, value| !value.nil? && valid.include?(key) }
195
212
 
196
213
  str << '<r><rPr>'
197
- data.keys.each do |key|
214
+ data.each do |key, val|
198
215
  case key
199
216
  when :font_name
200
- str << ('<rFont val="' << font_name << '"/>')
217
+ str << '<rFont val="' << font_name << '"/>'
201
218
  when :color
202
- str << data[key].to_xml_string
219
+ str << val.to_xml_string
203
220
  else
204
- str << ('<' << key.to_s << ' val="' << xml_value(data[key]) << '"/>')
221
+ str << '<' << key.to_s << ' val="' << xml_value(val) << '"/>'
205
222
  end
206
223
  end
207
- clean_value = Axlsx::trust_input ? @value.to_s : ::CGI.escapeHTML(Axlsx::sanitize(@value.to_s))
208
- str << ('</rPr><t>' << clean_value << '</t></r>')
224
+ clean_value = Axlsx.trust_input ? @value.to_s : ::CGI.escapeHTML(Axlsx.sanitize(@value.to_s))
225
+ str << '</rPr><t>' << clean_value << '</t></r>'
209
226
  end
210
227
 
211
228
  private
@@ -223,8 +240,9 @@ module Axlsx
223
240
  # imagemagick and loading metrics for every character.
224
241
  def font_size
225
242
  return sz if sz
243
+
226
244
  font = styles.fonts[styles.cellXfs[style].fontId] || styles.fonts[0]
227
- (font.b || (defined?(@b) && @b)) ? (font.sz * 1.5) : font.sz
245
+ font.b || (defined?(@b) && @b) ? (font.sz * 1.5) : font.sz
228
246
  end
229
247
 
230
248
  def style
@@ -237,7 +255,7 @@ module Axlsx
237
255
 
238
256
  # Converts the value to the correct XML representation (fixes issues with
239
257
  # Numbers)
240
- def xml_value value
258
+ def xml_value(value)
241
259
  if value == true
242
260
  1
243
261
  elsif value == false
@@ -1,4 +1,5 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # A Row is a single row in a worksheet.
4
5
  # @note The recommended way to manage rows and cells is to use Worksheet#add_row
@@ -6,13 +7,13 @@ module Axlsx
6
7
  class Row < SimpleTypedList
7
8
  include SerializedAttributes
8
9
  include Accessors
9
-
10
+
10
11
  # No support is provided for the following attributes
11
12
  # spans
12
13
  # thickTop
13
14
  # thickBottom
14
15
 
15
- # Creates a new row. New Cell objects are created based on the values, types and style options.
16
+ # Creates a new row. New Cell objects are created based on the values, types and style options.
16
17
  # A new cell is created for each item in the values array. style and types options are applied as follows:
17
18
  # If the types option is defined and is a symbol it is applied to all the cells created.
18
19
  # If the types option is an array, cell types are applied by index for each cell
@@ -24,11 +25,12 @@ module Axlsx
24
25
  # @option options [Array] values
25
26
  # @option options [Array, Symbol] types
26
27
  # @option options [Array, Integer] style
28
+ # @option options [Array, Boolean] escape_formulas
27
29
  # @option options [Float] height the row's height (in points)
28
30
  # @option options [Integer] offset - add empty columns before values
29
31
  # @see Row#array_to_cells
30
32
  # @see Cell
31
- def initialize(worksheet, values=[], options={})
33
+ def initialize(worksheet, values = [], options = {})
32
34
  self.worksheet = worksheet
33
35
  super(Cell, nil, values.size + options[:offset].to_i)
34
36
  self.height = options.delete(:height)
@@ -64,7 +66,7 @@ module Axlsx
64
66
  # @see Row#s
65
67
  def s=(v)
66
68
  Axlsx.validate_unsigned_numeric(v)
67
- @custom_format = true
69
+ @custom_format = true
68
70
  @s = v
69
71
  end
70
72
 
@@ -73,7 +75,7 @@ module Axlsx
73
75
  Axlsx.validate_unsigned_numeric(v)
74
76
  @outline_level = v
75
77
  end
76
-
78
+
77
79
  alias :outlineLevel= :outline_level=
78
80
 
79
81
  # The index of this row in the worksheet
@@ -86,12 +88,9 @@ module Axlsx
86
88
  # @param [Integer] r_index The row index, 0 based.
87
89
  # @param [String] str The string this rows xml will be appended to.
88
90
  # @return [String]
89
- def to_xml_string(r_index, str = '')
90
- serialized_tag('row', str, :r => r_index + 1) do
91
- tmp = '' # time / memory tradeoff, lots of calls to rubyzip costs more
92
- # time..
93
- each_with_index { |cell, c_index| cell.to_xml_string(r_index, c_index, tmp) }
94
- str << tmp
91
+ def to_xml_string(r_index, str = +'')
92
+ serialized_tag('row', str, r: Axlsx.row_ref(r_index)) do
93
+ each_with_index { |cell, c_index| cell.to_xml_string(r_index, c_index, str) }
95
94
  end
96
95
  end
97
96
 
@@ -104,29 +103,38 @@ module Axlsx
104
103
  c
105
104
  end
106
105
 
107
- # sets the color for every cell in this row
106
+ # Sets the color for every cell in this row.
108
107
  def color=(color)
109
- each_with_index do | cell, index |
108
+ each_with_index do |cell, index|
110
109
  cell.color = color.is_a?(Array) ? color[index] : color
111
110
  end
112
111
  end
113
112
 
114
- # sets the style for every cell in this row
113
+ # Sets the style for every cell in this row.
115
114
  def style=(style)
116
- each_with_index do | cell, index |
115
+ each_with_index do |cell, index|
117
116
  cell.style = style.is_a?(Array) ? style[index] : style
118
117
  end
119
118
  end
120
119
 
120
+ # Sets escape_formulas for every cell in this row. This determines whether to treat
121
+ # values starting with an equals sign as formulas or as literal strings.
122
+ # @param [Array, Boolean] value The value to set.
123
+ def escape_formulas=(value)
124
+ each_with_index do |cell, index|
125
+ cell.escape_formulas = value.is_a?(Array) ? value[index] : value
126
+ end
127
+ end
128
+
121
129
  # @see height
122
130
  def height=(v)
123
131
  unless v.nil?
124
- Axlsx::validate_unsigned_numeric(v)
132
+ Axlsx.validate_unsigned_numeric(v)
125
133
  @custom_height = true
126
134
  @ht = v
127
135
  end
128
136
  end
129
-
137
+
130
138
  # return cells
131
139
  def cells
132
140
  self
@@ -135,7 +143,7 @@ module Axlsx
135
143
  private
136
144
 
137
145
  # assigns the owning worksheet for this row
138
- def worksheet=(v) DataTypeValidator.validate :row_worksheet, Worksheet, v; @worksheet=v; end
146
+ def worksheet=(v) DataTypeValidator.validate :row_worksheet, Worksheet, v; @worksheet = v; end
139
147
 
140
148
  # Converts values, types, and style options into cells and associates them with this row.
141
149
  # A new cell is created for each item in the values array.
@@ -146,19 +154,19 @@ module Axlsx
146
154
  # @option options [Array] values
147
155
  # @option options [Array, Symbol] types
148
156
  # @option options [Array, Integer] style
149
- def array_to_cells(values, options={})
157
+ # @option options [Array, Boolean] escape_formulas
158
+ def array_to_cells(values, options = {})
150
159
  DataTypeValidator.validate :array_to_cells, Array, values
151
160
  types, style, formula_values, escape_formulas, offset = options.delete(:types), options.delete(:style), options.delete(:formula_values), options.delete(:escape_formulas), options.delete(:offset)
152
161
  offset.to_i.times { |index| self[index] = Cell.new(self) } if offset
153
162
  values.each_with_index do |value, index|
154
163
  options[:style] = style.is_a?(Array) ? style[index] : style if style
155
164
  options[:type] = types.is_a?(Array) ? types[index] : types if types
156
- options[:escape_formulas] = escape_formulas.is_a?(Array) ? escape_formulas[index] : escape_formulas if escape_formulas
165
+ options[:escape_formulas] = escape_formulas.is_a?(Array) ? escape_formulas[index] : escape_formulas unless escape_formulas.nil?
157
166
  options[:formula_value] = formula_values[index] if formula_values.is_a?(Array)
158
167
 
159
168
  self[index + offset.to_i] = Cell.new(self, value, options)
160
169
  end
161
170
  end
162
171
  end
163
-
164
172
  end
@@ -1,9 +1,9 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # A collection of break objects that define row breaks (page breaks) for printing and preview
4
5
 
5
6
  class RowBreaks < SimpleTypedList
6
-
7
7
  def initialize
8
8
  super Break
9
9
  end
@@ -13,19 +13,20 @@ module Axlsx
13
13
  # max and man values are fixed.
14
14
  # @see Break
15
15
  def add_break(options)
16
- # force feed the excel default
17
- self << Break.new(options.merge(:max => 16383, :man => true))
16
+ # force feed the Excel default
17
+ self << Break.new(options.merge(max: 16383, man: true))
18
18
  last
19
19
  end
20
-
20
+
21
21
  # <rowBreaks count="3" manualBreakCount="3">
22
22
  # <brk id="1" max="16383" man="1"/>
23
23
  # <brk id="7" max="16383" man="1"/>
24
24
  # <brk id="13" max="16383" man="1"/>
25
25
  # </rowBreaks>
26
- def to_xml_string(str='')
26
+ def to_xml_string(str = +'')
27
27
  return if empty?
28
- str << ('<rowBreaks count="' << self.size.to_s << '" manualBreakCount="' << self.size.to_s << '">')
28
+
29
+ str << '<rowBreaks count="' << size.to_s << '" manualBreakCount="' << size.to_s << '">'
29
30
  each { |brk| brk.to_xml_string(str) }
30
31
  str << '</rowBreaks>'
31
32
  end