caxlsx 3.4.1 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -1
  3. data/README.md +9 -11
  4. data/Rakefile +7 -5
  5. data/examples/generate.rb +3 -1
  6. data/lib/axlsx/content_type/abstract_content_type.rb +12 -4
  7. data/lib/axlsx/content_type/content_type.rb +8 -6
  8. data/lib/axlsx/content_type/default.rb +7 -2
  9. data/lib/axlsx/content_type/override.rb +7 -2
  10. data/lib/axlsx/doc_props/app.rb +95 -26
  11. data/lib/axlsx/doc_props/core.rb +8 -6
  12. data/lib/axlsx/drawing/area_chart.rb +10 -8
  13. data/lib/axlsx/drawing/area_series.rb +20 -12
  14. data/lib/axlsx/drawing/ax_data_source.rb +2 -0
  15. data/lib/axlsx/drawing/axes.rb +6 -4
  16. data/lib/axlsx/drawing/axis.rb +42 -22
  17. data/lib/axlsx/drawing/bar_3D_chart.rb +14 -12
  18. data/lib/axlsx/drawing/bar_chart.rb +13 -11
  19. data/lib/axlsx/drawing/bar_series.rb +20 -9
  20. data/lib/axlsx/drawing/bubble_chart.rb +6 -4
  21. data/lib/axlsx/drawing/bubble_series.rb +8 -6
  22. data/lib/axlsx/drawing/cat_axis.rb +29 -12
  23. data/lib/axlsx/drawing/chart.rb +46 -20
  24. data/lib/axlsx/drawing/d_lbls.rb +10 -8
  25. data/lib/axlsx/drawing/drawing.rb +59 -56
  26. data/lib/axlsx/drawing/graphic_frame.rb +6 -4
  27. data/lib/axlsx/drawing/hyperlink.rb +19 -8
  28. data/lib/axlsx/drawing/line_3D_chart.rb +7 -5
  29. data/lib/axlsx/drawing/line_chart.rb +10 -8
  30. data/lib/axlsx/drawing/line_series.rb +20 -12
  31. data/lib/axlsx/drawing/marker.rb +24 -7
  32. data/lib/axlsx/drawing/num_data.rb +9 -7
  33. data/lib/axlsx/drawing/num_data_source.rb +9 -7
  34. data/lib/axlsx/drawing/num_val.rb +7 -5
  35. data/lib/axlsx/drawing/one_cell_anchor.rb +13 -5
  36. data/lib/axlsx/drawing/pic.rb +26 -15
  37. data/lib/axlsx/drawing/picture_locking.rb +3 -1
  38. data/lib/axlsx/drawing/pie_3D_chart.rb +6 -4
  39. data/lib/axlsx/drawing/pie_chart.rb +36 -0
  40. data/lib/axlsx/drawing/pie_series.rb +23 -9
  41. data/lib/axlsx/drawing/scaling.rb +25 -9
  42. data/lib/axlsx/drawing/scatter_chart.rb +7 -5
  43. data/lib/axlsx/drawing/scatter_series.rb +14 -12
  44. data/lib/axlsx/drawing/ser_axis.rb +13 -5
  45. data/lib/axlsx/drawing/series.rb +13 -5
  46. data/lib/axlsx/drawing/series_title.rb +6 -4
  47. data/lib/axlsx/drawing/str_data.rb +7 -5
  48. data/lib/axlsx/drawing/str_val.rb +6 -4
  49. data/lib/axlsx/drawing/title.rb +13 -14
  50. data/lib/axlsx/drawing/two_cell_anchor.rb +4 -2
  51. data/lib/axlsx/drawing/val_axis.rb +4 -2
  52. data/lib/axlsx/drawing/view_3D.rb +16 -8
  53. data/lib/axlsx/drawing/vml_drawing.rb +18 -16
  54. data/lib/axlsx/drawing/vml_shape.rb +24 -22
  55. data/lib/axlsx/package.rb +73 -67
  56. data/lib/axlsx/rels/relationship.rb +21 -6
  57. data/lib/axlsx/rels/relationships.rb +6 -4
  58. data/lib/axlsx/stylesheet/border.rb +15 -4
  59. data/lib/axlsx/stylesheet/border_pr.rb +19 -6
  60. data/lib/axlsx/stylesheet/cell_alignment.rb +41 -10
  61. data/lib/axlsx/stylesheet/cell_protection.rb +12 -3
  62. data/lib/axlsx/stylesheet/cell_style.rb +33 -8
  63. data/lib/axlsx/stylesheet/color.rb +15 -7
  64. data/lib/axlsx/stylesheet/dxf.rb +34 -9
  65. data/lib/axlsx/stylesheet/fill.rb +7 -2
  66. data/lib/axlsx/stylesheet/font.rb +65 -17
  67. data/lib/axlsx/stylesheet/gradient_fill.rb +12 -4
  68. data/lib/axlsx/stylesheet/gradient_stop.rb +14 -5
  69. data/lib/axlsx/stylesheet/num_fmt.rb +14 -10
  70. data/lib/axlsx/stylesheet/pattern_fill.rb +18 -5
  71. data/lib/axlsx/stylesheet/styles.rb +124 -82
  72. data/lib/axlsx/stylesheet/table_style.rb +19 -6
  73. data/lib/axlsx/stylesheet/table_style_element.rb +15 -4
  74. data/lib/axlsx/stylesheet/table_styles.rb +14 -5
  75. data/lib/axlsx/stylesheet/xf.rb +73 -18
  76. data/lib/axlsx/util/accessors.rb +10 -6
  77. data/lib/axlsx/util/buffered_zip_output_stream.rb +60 -0
  78. data/lib/axlsx/util/constants.rb +117 -104
  79. data/lib/axlsx/util/mime_type_utils.rb +3 -5
  80. data/lib/axlsx/util/options_parser.rb +3 -1
  81. data/lib/axlsx/util/serialized_attributes.rb +42 -17
  82. data/lib/axlsx/util/simple_typed_list.rb +47 -47
  83. data/lib/axlsx/util/storage.rb +11 -10
  84. data/lib/axlsx/util/validators.rb +101 -41
  85. data/lib/axlsx/util/zip_command.rb +10 -10
  86. data/lib/axlsx/version.rb +3 -1
  87. data/lib/axlsx/workbook/defined_name.rb +6 -4
  88. data/lib/axlsx/workbook/defined_names.rb +4 -2
  89. data/lib/axlsx/workbook/shared_strings_table.rb +8 -6
  90. data/lib/axlsx/workbook/workbook.rb +94 -79
  91. data/lib/axlsx/workbook/workbook_view.rb +3 -1
  92. data/lib/axlsx/workbook/workbook_views.rb +4 -2
  93. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +65 -8
  94. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +11 -5
  95. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +11 -7
  96. data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +51 -0
  97. data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +56 -0
  98. data/lib/axlsx/workbook/worksheet/border_creator.rb +5 -3
  99. data/lib/axlsx/workbook/worksheet/break.rb +3 -1
  100. data/lib/axlsx/workbook/worksheet/cell.rb +83 -64
  101. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +31 -27
  102. data/lib/axlsx/workbook/worksheet/cfvo.rb +11 -3
  103. data/lib/axlsx/workbook/worksheet/cfvos.rb +3 -1
  104. data/lib/axlsx/workbook/worksheet/col.rb +5 -3
  105. data/lib/axlsx/workbook/worksheet/col_breaks.rb +6 -4
  106. data/lib/axlsx/workbook/worksheet/color_scale.rb +12 -10
  107. data/lib/axlsx/workbook/worksheet/cols.rb +4 -2
  108. data/lib/axlsx/workbook/worksheet/comment.rb +8 -6
  109. data/lib/axlsx/workbook/worksheet/comments.rb +6 -4
  110. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +16 -5
  111. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +73 -16
  112. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +4 -2
  113. data/lib/axlsx/workbook/worksheet/data_bar.rb +14 -13
  114. data/lib/axlsx/workbook/worksheet/data_validation.rb +69 -28
  115. data/lib/axlsx/workbook/worksheet/data_validations.rb +4 -2
  116. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +7 -5
  117. data/lib/axlsx/workbook/worksheet/dimension.rb +4 -2
  118. data/lib/axlsx/workbook/worksheet/header_footer.rb +4 -2
  119. data/lib/axlsx/workbook/worksheet/icon_set.rb +38 -9
  120. data/lib/axlsx/workbook/worksheet/merged_cells.rb +6 -6
  121. data/lib/axlsx/workbook/worksheet/outline_pr.rb +6 -2
  122. data/lib/axlsx/workbook/worksheet/page_margins.rb +39 -11
  123. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +7 -4
  124. data/lib/axlsx/workbook/worksheet/page_setup.rb +34 -9
  125. data/lib/axlsx/workbook/worksheet/pane.rb +17 -9
  126. data/lib/axlsx/workbook/worksheet/pivot_table.rb +20 -19
  127. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +8 -6
  128. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +3 -1
  129. data/lib/axlsx/workbook/worksheet/print_options.rb +3 -1
  130. data/lib/axlsx/workbook/worksheet/protected_range.rb +3 -1
  131. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +6 -4
  132. data/lib/axlsx/workbook/worksheet/rich_text.rb +3 -1
  133. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +46 -24
  134. data/lib/axlsx/workbook/worksheet/row.rb +11 -9
  135. data/lib/axlsx/workbook/worksheet/row_breaks.rb +7 -5
  136. data/lib/axlsx/workbook/worksheet/selection.rb +15 -7
  137. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +6 -2
  138. data/lib/axlsx/workbook/worksheet/sheet_data.rb +3 -1
  139. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +6 -2
  140. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +8 -4
  141. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +11 -9
  142. data/lib/axlsx/workbook/worksheet/sheet_view.rb +38 -15
  143. data/lib/axlsx/workbook/worksheet/table.rb +9 -7
  144. data/lib/axlsx/workbook/worksheet/table_style_info.rb +4 -2
  145. data/lib/axlsx/workbook/worksheet/tables.rb +4 -2
  146. data/lib/axlsx/workbook/worksheet/worksheet.rb +56 -39
  147. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +4 -2
  148. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +8 -2
  149. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +7 -5
  150. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +5 -3
  151. data/lib/axlsx.rb +56 -42
  152. data/lib/caxlsx.rb +3 -1
  153. metadata +39 -71
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # Pane options for a worksheet.
3
5
  #
@@ -94,33 +96,39 @@ module Axlsx
94
96
 
95
97
  # @see active_pane
96
98
  def active_pane=(v)
97
- Axlsx::validate_pane_type(v)
98
- @active_pane = Axlsx::camel(v.to_s, false)
99
+ Axlsx.validate_pane_type(v)
100
+ @active_pane = Axlsx.camel(v.to_s, false)
99
101
  end
100
102
 
101
103
  # @see state
102
104
  def state=(v)
103
- Axlsx::validate_split_state_type(v)
104
- @state = Axlsx::camel(v.to_s, false)
105
+ Axlsx.validate_split_state_type(v)
106
+ @state = Axlsx.camel(v.to_s, false)
105
107
  end
106
108
 
107
109
  # @see top_left_cell
108
110
  def top_left_cell=(v)
109
- cell = (v.class == Axlsx::Cell ? v.r_abs : v)
110
- Axlsx::validate_string(cell)
111
+ cell = (v.instance_of?(Axlsx::Cell) ? v.r_abs : v)
112
+ Axlsx.validate_string(cell)
111
113
  @top_left_cell = cell
112
114
  end
113
115
 
114
116
  # @see x_split
115
- def x_split=(v); Axlsx::validate_unsigned_int(v); @x_split = v end
117
+ def x_split=(v)
118
+ Axlsx.validate_unsigned_int(v)
119
+ @x_split = v
120
+ end
116
121
 
117
122
  # @see y_split
118
- def y_split=(v); Axlsx::validate_unsigned_int(v); @y_split = v end
123
+ def y_split=(v)
124
+ Axlsx.validate_unsigned_int(v)
125
+ @y_split = v
126
+ end
119
127
 
120
128
  # Serializes the data validation
121
129
  # @param [String] str
122
130
  # @return [String]
123
- def to_xml_string(str = '')
131
+ def to_xml_string(str = +'')
124
132
  finalize
125
133
  serialized_tag 'pane', str
126
134
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # Table
3
5
  # @note Worksheet#add_pivot_table is the recommended way to create tables for your worksheets.
@@ -122,7 +124,7 @@ module Axlsx
122
124
  @data = []
123
125
  v.each do |data_field|
124
126
  if data_field.is_a? String
125
- data_field = { :ref => data_field }
127
+ data_field = { ref: data_field }
126
128
  end
127
129
  data_field.each do |key, value|
128
130
  if key == :num_fmt
@@ -133,7 +135,6 @@ module Axlsx
133
135
  end
134
136
  @data << data_field
135
137
  end
136
- @data
137
138
  end
138
139
 
139
140
  # The pages
@@ -158,13 +159,13 @@ module Axlsx
158
159
  # The part name for this table
159
160
  # @return [String]
160
161
  def pn
161
- "#{PIVOT_TABLE_PN % (index + 1)}"
162
+ format(PIVOT_TABLE_PN, index + 1)
162
163
  end
163
164
 
164
165
  # The relationship part name of this pivot table
165
166
  # @return [String]
166
167
  def rels_pn
167
- "#{PIVOT_TABLE_RELS_PN % (index + 1)}"
168
+ format(PIVOT_TABLE_RELS_PN, index + 1)
168
169
  end
169
170
 
170
171
  # The cache_definition for this pivot table
@@ -184,13 +185,13 @@ module Axlsx
184
185
  # Serializes the object
185
186
  # @param [String] str
186
187
  # @return [String]
187
- def to_xml_string(str = '')
188
+ def to_xml_string(str = +'')
188
189
  str << '<?xml version="1.0" encoding="UTF-8"?>'
189
190
 
190
- str << ('<pivotTableDefinition xmlns="' << XML_NS << '" name="' << name << '" cacheId="' << cache_definition.cache_id.to_s << '"' << (data.size <= 1 ? ' dataOnRows="1"' : '') << ' applyNumberFormats="0" applyBorderFormats="0" applyFontFormats="0" applyPatternFormats="0" applyAlignmentFormats="0" applyWidthHeightFormats="1" dataCaption="Data" showMultipleLabel="0" showMemberPropertyTips="0" useAutoFormatting="1" indent="0" compact="0" compactData="0" gridDropZones="1" multipleFieldFilters="0">')
191
+ str << '<pivotTableDefinition xmlns="' << XML_NS << '" name="' << name << '" cacheId="' << cache_definition.cache_id.to_s << '"' << (data.size <= 1 ? ' dataOnRows="1"' : '') << ' applyNumberFormats="0" applyBorderFormats="0" applyFontFormats="0" applyPatternFormats="0" applyAlignmentFormats="0" applyWidthHeightFormats="1" dataCaption="Data" showMultipleLabel="0" showMemberPropertyTips="0" useAutoFormatting="1" indent="0" compact="0" compactData="0" gridDropZones="1" multipleFieldFilters="0">'
191
192
 
192
- str << ('<location firstDataCol="1" firstDataRow="1" firstHeaderRow="1" ref="' << ref << '"/>')
193
- str << ('<pivotFields count="' << header_cells_count.to_s << '">')
193
+ str << '<location firstDataCol="1" firstDataRow="1" firstHeaderRow="1" ref="' << ref << '"/>'
194
+ str << '<pivotFields count="' << header_cells_count.to_s << '">'
194
195
 
195
196
  header_cell_values.each do |cell_value|
196
197
  subtotal = !no_subtotals_on_headers.include?(cell_value)
@@ -203,13 +204,13 @@ module Axlsx
203
204
  str << '<rowFields count="1"><field x="-2"/></rowFields>'
204
205
  str << '<rowItems count="2"><i><x/></i> <i i="1"><x v="1"/></i></rowItems>'
205
206
  else
206
- str << ('<rowFields count="' << rows.size.to_s << '">')
207
+ str << '<rowFields count="' << rows.size.to_s << '">'
207
208
  rows.each do |row_value|
208
- str << ('<field x="' << header_index_of(row_value).to_s << '"/>')
209
+ str << '<field x="' << header_index_of(row_value).to_s << '"/>'
209
210
  end
210
211
  str << '</rowFields>'
211
- str << ('<rowItems count="' << rows.size.to_s << '">')
212
- rows.size.times do |i|
212
+ str << '<rowItems count="' << rows.size.to_s << '">'
213
+ rows.size.times do
213
214
  str << '<i/>'
214
215
  end
215
216
  str << '</rowItems>'
@@ -219,7 +220,7 @@ module Axlsx
219
220
  str << '<colFields count="1"><field x="-2"/></colFields>'
220
221
  str << "<colItems count=\"#{data.size}\">"
221
222
  str << '<i><x/></i>'
222
- data[1..-1].each_with_index do |datum_value, i|
223
+ (data.size - 1).times do |i|
223
224
  str << "<i i=\"#{i + 1}\"><x v=\"#{i + 1}\"/></i>"
224
225
  end
225
226
  str << '</colItems>'
@@ -227,16 +228,16 @@ module Axlsx
227
228
  str << '<colItems count="1"><i/></colItems>'
228
229
  end
229
230
  else
230
- str << ('<colFields count="' << columns.size.to_s << '">')
231
+ str << '<colFields count="' << columns.size.to_s << '">'
231
232
  columns.each do |column_value|
232
- str << ('<field x="' << header_index_of(column_value).to_s << '"/>')
233
+ str << '<field x="' << header_index_of(column_value).to_s << '"/>'
233
234
  end
234
235
  str << '</colFields>'
235
236
  end
236
237
  unless pages.empty?
237
- str << ('<pageFields count="' << pages.size.to_s << '">')
238
+ str << '<pageFields count="' << pages.size.to_s << '">'
238
239
  pages.each do |page_value|
239
- str << ('<pageField fld="' << header_index_of(page_value).to_s << '"/>')
240
+ str << '<pageField fld="' << header_index_of(page_value).to_s << '"/>'
240
241
  end
241
242
  str << '</pageFields>'
242
243
  end
@@ -244,7 +245,7 @@ module Axlsx
244
245
  str << "<dataFields count=\"#{data.size}\">"
245
246
  data.each do |datum_value|
246
247
  # The correct name prefix in ["Sum","Average", etc...]
247
- str << "<dataField name='#{(datum_value[:subtotal] || '')} of #{datum_value[:ref]}' fld='#{header_index_of(datum_value[:ref])}' baseField='0' baseItem='0'"
248
+ str << "<dataField name='#{datum_value[:subtotal] || ''} of #{datum_value[:ref]}' fld='#{header_index_of(datum_value[:ref])}' baseField='0' baseItem='0'"
248
249
  str << " numFmtId='#{datum_value[:num_fmt]}'" if datum_value[:num_fmt]
249
250
  str << " subtotal='#{datum_value[:subtotal]}' " if datum_value[:subtotal]
250
251
  str << "/>"
@@ -265,7 +266,7 @@ module Axlsx
265
266
  # References for header cells
266
267
  # @return [Array]
267
268
  def header_cell_refs
268
- Axlsx::range_to_a(header_range).first
269
+ Axlsx.range_to_a(header_range).first
269
270
  end
270
271
 
271
272
  # The header cells for the pivot table
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # Table
3
5
  # @note Worksheet#add_pivot_table is the recommended way to create tables for your worksheets.
@@ -24,7 +26,7 @@ module Axlsx
24
26
  # The part name for this table
25
27
  # @return [String]
26
28
  def pn
27
- "#{PIVOT_TABLE_CACHE_DEFINITION_PN % (index + 1)}"
29
+ format(PIVOT_TABLE_CACHE_DEFINITION_PN, index + 1)
28
30
  end
29
31
 
30
32
  # The identifier for this cache
@@ -43,15 +45,15 @@ module Axlsx
43
45
  # Serializes the object
44
46
  # @param [String] str
45
47
  # @return [String]
46
- def to_xml_string(str = '')
48
+ def to_xml_string(str = +'')
47
49
  str << '<?xml version="1.0" encoding="UTF-8"?>'
48
- str << ('<pivotCacheDefinition xmlns="' << XML_NS << '" xmlns:r="' << XML_NS_R << '" invalid="1" refreshOnLoad="1" recordCount="0">')
50
+ str << '<pivotCacheDefinition xmlns="' << XML_NS << '" xmlns:r="' << XML_NS_R << '" invalid="1" refreshOnLoad="1" recordCount="0">'
49
51
  str << '<cacheSource type="worksheet">'
50
- str << ('<worksheetSource ref="' << pivot_table.range << '" sheet="' << pivot_table.data_sheet.name << '"/>')
52
+ str << '<worksheetSource ref="' << pivot_table.range << '" sheet="' << pivot_table.data_sheet.name << '"/>'
51
53
  str << '</cacheSource>'
52
- str << ('<cacheFields count="' << pivot_table.header_cells_count.to_s << '">')
54
+ str << '<cacheFields count="' << pivot_table.header_cells_count.to_s << '">'
53
55
  pivot_table.header_cells.each do |cell|
54
- str << ('<cacheField name="' << cell.clean_value << '" numFmtId="0">')
56
+ str << '<cacheField name="' << cell.clean_value << '" numFmtId="0">'
55
57
  str << '<sharedItems count="0">'
56
58
  str << '</sharedItems>'
57
59
  str << '</cacheField>'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # A simple, self serializing class for storing pivot tables
3
5
  class PivotTables < SimpleTypedList
@@ -5,7 +7,7 @@ module Axlsx
5
7
  def initialize(worksheet)
6
8
  raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
7
9
 
8
- super PivotTable
10
+ super(PivotTable)
9
11
  @worksheet = worksheet
10
12
  end
11
13
 
@@ -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
  #
@@ -31,7 +33,7 @@ module Axlsx
31
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.
32
34
  # @param [String] str
33
35
  # @return [String]
34
- def to_xml_string(str = '')
36
+ def to_xml_string(str = +'')
35
37
  serialized_tag 'printOptions', str
36
38
  end
37
39
  end
@@ -1,3 +1,5 @@
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
@@ -39,7 +41,7 @@ module Axlsx
39
41
  # @param [String] str if this string object is provided we append
40
42
  # our output to that object. Use this - it helps limit the number of
41
43
  # objects created during serialization
42
- def to_xml_string(str = "")
44
+ def to_xml_string(str = +'')
43
45
  serialized_tag 'protectedRange', str
44
46
  end
45
47
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # A self serializing collection of ranges that should be protected in
3
5
  # the worksheet
@@ -7,7 +9,7 @@ module Axlsx
7
9
  def initialize(worksheet)
8
10
  raise ArgumentError, 'You must provide a worksheet' unless worksheet.is_a?(Worksheet)
9
11
 
10
- super ProtectedRange
12
+ super(ProtectedRange)
11
13
  @worksheet = worksheet
12
14
  end
13
15
 
@@ -17,16 +19,16 @@ module Axlsx
17
19
  sqref = if cells.is_a?(String)
18
20
  cells
19
21
  elsif cells.is_a?(SimpleTypedList) || cells.is_a?(Array)
20
- Axlsx::cell_range(cells, false)
22
+ Axlsx.cell_range(cells, false)
21
23
  end
22
- self << ProtectedRange.new(:sqref => sqref, :name => "Range#{size}")
24
+ self << ProtectedRange.new(sqref: sqref, name: "Range#{size}")
23
25
  last
24
26
  end
25
27
 
26
28
  # Serializes the protected ranges
27
29
  # @param [String] str
28
30
  # @return [String]
29
- def to_xml_string(str = '')
31
+ def to_xml_string(str = +'')
30
32
  return if empty?
31
33
 
32
34
  str << '<protectedRanges>'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # A simple, self serializing class for storing TextRuns
3
5
  class RichText < SimpleTypedList
@@ -45,7 +47,7 @@ module Axlsx
45
47
  # renders the RichTextRuns in this collection
46
48
  # @param [String] str
47
49
  # @return [String]
48
- def to_xml_string(str = '')
50
+ def to_xml_string(str = +'')
49
51
  each { |run| run.to_xml_string(str) }
50
52
  str
51
53
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # The RichTextRun class creates and self serializing text run.
3
5
  class RichTextRun
@@ -27,7 +29,9 @@ module Axlsx
27
29
  attr_reader :font_name
28
30
 
29
31
  # @see font_name
30
- def font_name=(v) set_run_style :validate_string, :font_name, v; end
32
+ def font_name=(v)
33
+ set_run_style :validate_string, :font_name, v
34
+ end
31
35
 
32
36
  # The inline charset property for the cell
33
37
  # As far as I can tell, this is pretty much ignored. However, based on the spec it should be one of the following:
@@ -54,7 +58,9 @@ module Axlsx
54
58
  attr_reader :charset
55
59
 
56
60
  # @see charset
57
- def charset=(v) set_run_style :validate_unsigned_int, :charset, v; end
61
+ def charset=(v)
62
+ set_run_style :validate_unsigned_int, :charset, v
63
+ end
58
64
 
59
65
  # The inline family property for the cell
60
66
  # @return [Integer]
@@ -75,49 +81,63 @@ module Axlsx
75
81
  attr_reader :b
76
82
 
77
83
  # @see b
78
- def b=(v) set_run_style :validate_boolean, :b, v; end
84
+ def b=(v)
85
+ set_run_style :validate_boolean, :b, v
86
+ end
79
87
 
80
88
  # The inline italic property for the cell
81
89
  # @return [Boolean]
82
90
  attr_reader :i
83
91
 
84
92
  # @see i
85
- def i=(v) set_run_style :validate_boolean, :i, v; end
93
+ def i=(v)
94
+ set_run_style :validate_boolean, :i, v
95
+ end
86
96
 
87
97
  # The inline strike property for the cell
88
98
  # @return [Boolean]
89
99
  attr_reader :strike
90
100
 
91
101
  # @see strike
92
- def strike=(v) set_run_style :validate_boolean, :strike, v; end
102
+ def strike=(v)
103
+ set_run_style :validate_boolean, :strike, v
104
+ end
93
105
 
94
106
  # The inline outline property for the cell
95
107
  # @return [Boolean]
96
108
  attr_reader :outline
97
109
 
98
110
  # @see outline
99
- def outline=(v) set_run_style :validate_boolean, :outline, v; end
111
+ def outline=(v)
112
+ set_run_style :validate_boolean, :outline, v
113
+ end
100
114
 
101
115
  # The inline shadow property for the cell
102
116
  # @return [Boolean]
103
117
  attr_reader :shadow
104
118
 
105
119
  # @see shadow
106
- def shadow=(v) set_run_style :validate_boolean, :shadow, v; end
120
+ def shadow=(v)
121
+ set_run_style :validate_boolean, :shadow, v
122
+ end
107
123
 
108
124
  # The inline condense property for the cell
109
125
  # @return [Boolean]
110
126
  attr_reader :condense
111
127
 
112
128
  # @see condense
113
- def condense=(v) set_run_style :validate_boolean, :condense, v; end
129
+ def condense=(v)
130
+ set_run_style :validate_boolean, :condense, v
131
+ end
114
132
 
115
133
  # The inline extend property for the cell
116
134
  # @return [Boolean]
117
135
  attr_reader :extend
118
136
 
119
137
  # @see extend
120
- def extend=(v) set_run_style :validate_boolean, :extend, v; end
138
+ def extend=(v)
139
+ set_run_style :validate_boolean, :extend, v
140
+ end
121
141
 
122
142
  # The inline underline property for the cell.
123
143
  # It must be one of :none, :single, :double, :singleAccounting, :doubleAccounting, true
@@ -128,7 +148,7 @@ module Axlsx
128
148
 
129
149
  # @see u
130
150
  def u=(v)
131
- v = :single if (v == true || v == 1 || v == :true || v == 'true')
151
+ v = :single if v == true || v == 1 || v == :true || v == 'true'
132
152
  set_run_style :validate_cell_u, :u, v
133
153
  end
134
154
 
@@ -138,7 +158,7 @@ module Axlsx
138
158
 
139
159
  # @param [String] v The 8 character representation for an rgb color #FFFFFFFF"
140
160
  def color=(v)
141
- @color = v.is_a?(Color) ? v : Color.new(:rgb => v)
161
+ @color = v.is_a?(Color) ? v : Color.new(rgb: v)
142
162
  end
143
163
 
144
164
  # The inline sz property for the cell
@@ -146,7 +166,9 @@ module Axlsx
146
166
  attr_reader :sz
147
167
 
148
168
  # @see sz
149
- def sz=(v) set_run_style :validate_unsigned_int, :sz, v; end
169
+ def sz=(v)
170
+ set_run_style :validate_unsigned_int, :sz, v
171
+ end
150
172
 
151
173
  # The inline vertical alignment property for the cell
152
174
  # this must be one of [:baseline, :subscript, :superscript]
@@ -197,30 +219,30 @@ module Axlsx
197
219
  return unless INLINE_STYLES.include?(attr.to_sym)
198
220
 
199
221
  Axlsx.send(validator, value) unless validator.nil?
200
- self.instance_variable_set :"@#{attr.to_s}", value
222
+ instance_variable_set :"@#{attr}", value
201
223
  end
202
224
 
203
225
  # Serializes the RichTextRun
204
226
  # @param [String] str
205
227
  # @return [String]
206
- def to_xml_string(str = '')
228
+ def to_xml_string(str = +'')
207
229
  valid = RichTextRun::INLINE_STYLES
208
- data = Hash[Axlsx.instance_values_for(self).map { |k, v| [k.to_sym, v] }]
209
- data = data.select { |key, value| valid.include?(key) && !value.nil? }
230
+ data = Axlsx.instance_values_for(self).transform_keys(&:to_sym)
231
+ data = data.select { |key, value| !value.nil? && valid.include?(key) }
210
232
 
211
233
  str << '<r><rPr>'
212
- data.keys.each do |key|
234
+ data.each do |key, val|
213
235
  case key
214
236
  when :font_name
215
- str << ('<rFont val="' << font_name << '"/>')
237
+ str << '<rFont val="' << font_name << '"/>'
216
238
  when :color
217
- str << data[key].to_xml_string
239
+ str << val.to_xml_string
218
240
  else
219
- str << ('<' << key.to_s << ' val="' << xml_value(data[key]) << '"/>')
241
+ str << '<' << key.to_s << ' val="' << xml_value(val) << '"/>'
220
242
  end
221
243
  end
222
- clean_value = Axlsx::trust_input ? @value.to_s : ::CGI.escapeHTML(Axlsx::sanitize(@value.to_s))
223
- str << ('</rPr><t>' << clean_value << '</t></r>')
244
+ clean_value = Axlsx.trust_input ? @value.to_s : ::CGI.escapeHTML(Axlsx.sanitize(@value.to_s))
245
+ str << '</rPr><t>' << clean_value << '</t></r>'
224
246
  end
225
247
 
226
248
  private
@@ -240,7 +262,7 @@ module Axlsx
240
262
  return sz if sz
241
263
 
242
264
  font = styles.fonts[styles.cellXfs[style].fontId] || styles.fonts[0]
243
- (font.b || (defined?(@b) && @b)) ? (font.sz * 1.5) : font.sz
265
+ font.b || (defined?(@b) && @b) ? (font.sz * 1.5) : font.sz
244
266
  end
245
267
 
246
268
  def style
@@ -253,7 +275,7 @@ module Axlsx
253
275
 
254
276
  # Converts the value to the correct XML representation (fixes issues with
255
277
  # Numbers)
256
- def xml_value value
278
+ def xml_value(value)
257
279
  if value == true
258
280
  1
259
281
  elsif value == false
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # A Row is a single row in a worksheet.
3
5
  # @note The recommended way to manage rows and cells is to use Worksheet#add_row
@@ -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
 
@@ -130,7 +129,7 @@ module Axlsx
130
129
  # @see height
131
130
  def height=(v)
132
131
  unless v.nil?
133
- Axlsx::validate_unsigned_numeric(v)
132
+ Axlsx.validate_unsigned_numeric(v)
134
133
  @custom_height = true
135
134
  @ht = v
136
135
  end
@@ -144,7 +143,10 @@ module Axlsx
144
143
  private
145
144
 
146
145
  # assigns the owning worksheet for this row
147
- def worksheet=(v) DataTypeValidator.validate :row_worksheet, Worksheet, v; @worksheet = v; end
146
+ def worksheet=(v)
147
+ DataTypeValidator.validate :row_worksheet, Worksheet, v
148
+ @worksheet = v
149
+ end
148
150
 
149
151
  # Converts values, types, and style options into cells and associates them with this row.
150
152
  # A new cell is created for each item in the values array.
@@ -161,7 +163,7 @@ module Axlsx
161
163
  types, style, formula_values, escape_formulas, offset = options.delete(:types), options.delete(:style), options.delete(:formula_values), options.delete(:escape_formulas), options.delete(:offset)
162
164
  offset.to_i.times { |index| self[index] = Cell.new(self) } if offset
163
165
  values.each_with_index do |value, index|
164
- options[:style] = style.is_a?(Array) ? style[index] : style if style
166
+ options[:style] = (style.is_a?(Array) ? style[index] : style) || worksheet.column_info[index]&.style
165
167
  options[:type] = types.is_a?(Array) ? types[index] : types if types
166
168
  options[:escape_formulas] = escape_formulas.is_a?(Array) ? escape_formulas[index] : escape_formulas unless escape_formulas.nil?
167
169
  options[:formula_value] = formula_values[index] if formula_values.is_a?(Array)
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # A collection of break objects that define row breaks (page breaks) for printing and preview
3
5
 
4
6
  class RowBreaks < SimpleTypedList
5
7
  def initialize
6
- super Break
8
+ super(Break)
7
9
  end
8
10
 
9
11
  # Adds a row break
@@ -11,8 +13,8 @@ module Axlsx
11
13
  # max and man values are fixed.
12
14
  # @see Break
13
15
  def add_break(options)
14
- # force feed the excel default
15
- 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))
16
18
  last
17
19
  end
18
20
 
@@ -21,10 +23,10 @@ module Axlsx
21
23
  # <brk id="7" max="16383" man="1"/>
22
24
  # <brk id="13" max="16383" man="1"/>
23
25
  # </rowBreaks>
24
- def to_xml_string(str = '')
26
+ def to_xml_string(str = +'')
25
27
  return if empty?
26
28
 
27
- str << ('<rowBreaks count="' << self.size.to_s << '" manualBreakCount="' << self.size.to_s << '">')
29
+ str << '<rowBreaks count="' << size.to_s << '" manualBreakCount="' << size.to_s << '">'
28
30
  each { |brk| brk.to_xml_string(str) }
29
31
  str << '</rowBreaks>'
30
32
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # Selection options for worksheet panes.
3
5
  #
@@ -72,27 +74,33 @@ module Axlsx
72
74
 
73
75
  # @see active_cell
74
76
  def active_cell=(v)
75
- cell = (v.class == Axlsx::Cell ? v.r_abs : v)
76
- Axlsx::validate_string(cell)
77
+ cell = (v.instance_of?(Axlsx::Cell) ? v.r_abs : v)
78
+ Axlsx.validate_string(cell)
77
79
  @active_cell = cell
78
80
  end
79
81
 
80
82
  # @see active_cell_id
81
- def active_cell_id=(v); Axlsx::validate_unsigned_int(v); @active_cell_id = v end
83
+ def active_cell_id=(v)
84
+ Axlsx.validate_unsigned_int(v)
85
+ @active_cell_id = v
86
+ end
82
87
 
83
88
  # @see pane
84
89
  def pane=(v)
85
- Axlsx::validate_pane_type(v)
86
- @pane = Axlsx::camel(v, false)
90
+ Axlsx.validate_pane_type(v)
91
+ @pane = Axlsx.camel(v, false)
87
92
  end
88
93
 
89
94
  # @see sqref
90
- def sqref=(v); Axlsx::validate_string(v); @sqref = v end
95
+ def sqref=(v)
96
+ Axlsx.validate_string(v)
97
+ @sqref = v
98
+ end
91
99
 
92
100
  # Serializes the data validation
93
101
  # @param [String] str
94
102
  # @return [String]
95
- def to_xml_string(str = '')
103
+ def to_xml_string(str = +'')
96
104
  serialized_tag 'selection', str
97
105
  end
98
106
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # the SheetCalcPr object for the worksheet
3
5
  # This object contains calculation properties for the worksheet.
@@ -21,8 +23,10 @@ module Axlsx
21
23
  # @param [String] str the string to append this objects serialized
22
24
  # content to.
23
25
  # @return [String]
24
- def to_xml_string(str = '')
25
- str << "<sheetCalcPr #{serialized_attributes}/>"
26
+ def to_xml_string(str = +'')
27
+ str << '<sheetCalcPr '
28
+ serialized_attributes(str)
29
+ str << '/>'
26
30
  end
27
31
  end
28
32
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # This class manages the serialization of rows for worksheets
3
5
  class SheetData
@@ -14,7 +16,7 @@ module Axlsx
14
16
  # Serialize the sheet data
15
17
  # @param [String] str the string this objects serializaton will be concacted to.
16
18
  # @return [String]
17
- def to_xml_string(str = '')
19
+ def to_xml_string(str = +'')
18
20
  str << '<sheetData>'
19
21
  worksheet.rows.each_with_index do |row, index|
20
22
  row.to_xml_string(index, str)