diff options
| author | Geremia Taglialatela <[email protected]> | 2023-04-08 11:55:52 +0200 |
|---|---|---|
| committer | Geremia Taglialatela <[email protected]> | 2023-04-08 11:55:52 +0200 |
| commit | 48f392fb7752f14153126e9d154b4f9e2eef8fa7 (patch) | |
| tree | 35e6e5052cb33a7cd5245df137c80d4ec7cb9346 | |
| parent | 55526805cf28cc91a22df5811b26cd23bdefa8d3 (diff) | |
| download | caxlsx-48f392fb7752f14153126e9d154b4f9e2eef8fa7.tar.gz caxlsx-48f392fb7752f14153126e9d154b4f9e2eef8fa7.zip | |
Fix Layout/EmptyLineAfterGuardClause offenses
```
rubocop --only Layout/EmptyLineAfterGuardClause -a
```
44 files changed, 90 insertions, 5 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 08ae966d..f0d4799e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -36,11 +36,6 @@ Layout/ArgumentAlignment: - 'lib/axlsx/workbook/worksheet/sheet_view.rb' - 'lib/axlsx/workbook/worksheet/table_style_info.rb' -# Offense count: 90 -# This cop supports safe autocorrection (--autocorrect). -Layout/EmptyLineAfterGuardClause: - Enabled: false - # Offense count: 58 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment. diff --git a/lib/axlsx/drawing/axes.rb b/lib/axlsx/drawing/axes.rb index 0e4403ab..314f28c3 100644 --- a/lib/axlsx/drawing/axes.rb +++ b/lib/axlsx/drawing/axes.rb @@ -8,6 +8,7 @@ module Axlsx # must come first (we assume a Ruby 1.9+ Hash or an OrderedHash). def initialize(options = {}) raise(ArgumentError, "CatAxis must come first") if options.keys.include?(:cat_axis) && options.keys.first != :cat_axis + options.each do |name, axis_class| add_axis(name, axis_class) end diff --git a/lib/axlsx/drawing/d_lbls.rb b/lib/axlsx/drawing/d_lbls.rb index d997d9a9..213008e6 100644 --- a/lib/axlsx/drawing/d_lbls.rb +++ b/lib/axlsx/drawing/d_lbls.rb @@ -10,6 +10,7 @@ module Axlsx # creates a new DLbls object def initialize(chart_type, options = {}) raise ArgumentError, 'chart_type must inherit from Chart' unless [Chart, LineChart].include?(chart_type.superclass) + @chart_type = chart_type initialize_defaults parse_options options @@ -49,6 +50,7 @@ module Axlsx # @return [Symbol] def d_lbl_pos return unless [Pie3DChart, LineChart].include? @chart_type + @d_lbl_pos ||= :bestFit end @@ -60,6 +62,7 @@ module Axlsx # @param [Symbol] label_position the postion you want to use. def d_lbl_pos=(label_position) return unless [Pie3DChart, LineChart].include? @chart_type + Axlsx::RestrictionValidator.validate 'DLbls#d_lbl_pos', [:bestFit, :b, :ctr, :inBase, :inEnd, :l, :outEnd, :r, :t], label_position @d_lbl_pos = label_position end @@ -72,6 +75,7 @@ module Axlsx instance_vals = Axlsx.instance_values_for(self) %w(d_lbl_pos show_legend_key show_val show_cat_name show_ser_name show_percent show_bubble_size show_leader_lines).each do |key| next unless instance_vals.keys.include?(key) && instance_vals[key] != nil + str << "<c:#{Axlsx::camel(key, false)} val='#{instance_vals[key]}' />" end str << '</c:dLbls>' @@ -80,6 +84,7 @@ module Axlsx # nills out d_lbl_pos and show_leader_lines as these attributes, while valid in the spec actually chrash excel for any chart type other than pie charts. def validate_attributes_for_chart_type return if [Pie3DChart, LineChart].include? @chart_type + @d_lbl_pos = nil @show_leader_lines = nil end diff --git a/lib/axlsx/drawing/pic.rb b/lib/axlsx/drawing/pic.rb index 7d9cb532..64e5a877 100644 --- a/lib/axlsx/drawing/pic.rb +++ b/lib/axlsx/drawing/pic.rb @@ -73,6 +73,7 @@ module Axlsx Axlsx::validate_string(v) RestrictionValidator.validate 'Pic.image_src', ALLOWED_MIME_TYPES, MimeTypeUtils.get_mime_type(v) raise ArgumentError, "File does not exist" unless File.exist?(v) + @image_src = v end @@ -116,6 +117,7 @@ module Axlsx # @see OneCellAnchor.width def width return unless @anchor.is_a?(OneCellAnchor) + @anchor.width end @@ -187,6 +189,7 @@ module Axlsx # Changes the anchor to a one cell anchor. def use_one_cell_anchor return if @anchor.is_a?(OneCellAnchor) + new_anchor = OneCellAnchor.new(@anchor.drawing, :start_at => [@anchor.from.col, @anchor.from.row]) swap_anchor(new_anchor) end @@ -194,6 +197,7 @@ module Axlsx #changes the anchor type to a two cell anchor def use_two_cell_anchor return if @anchor.is_a?(TwoCellAnchor) + new_anchor = TwoCellAnchor.new(@anchor.drawing, :start_at => [@anchor.from.col, @anchor.from.row]) swap_anchor(new_anchor) end diff --git a/lib/axlsx/drawing/view_3D.rb b/lib/axlsx/drawing/view_3D.rb index 1adf9e28..23bd4952 100644 --- a/lib/axlsx/drawing/view_3D.rb +++ b/lib/axlsx/drawing/view_3D.rb @@ -108,6 +108,7 @@ module Axlsx def element_for_attribute(name, namespace = '') val = Axlsx.instance_values_for(self)[name] return "" if val == nil + "<%s:%s val='%s'/>" % [namespace, Axlsx::camel(name, false), val] end end diff --git a/lib/axlsx/drawing/vml_drawing.rb b/lib/axlsx/drawing/vml_drawing.rb index e314b736..4e9c5b0d 100644 --- a/lib/axlsx/drawing/vml_drawing.rb +++ b/lib/axlsx/drawing/vml_drawing.rb @@ -5,6 +5,7 @@ module Axlsx # @param [Comments] comments the comments object this drawing is associated with def initialize(comments) raise ArgumentError, "you must provide a comments object" unless comments.is_a?(Comments) + @comments = comments end diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb index f249073c..a0a77949 100644 --- a/lib/axlsx/package.rb +++ b/lib/axlsx/package.rb @@ -105,6 +105,7 @@ module Axlsx confirm_valid, zip_command = parse_serialize_options(options, secondary_options) return false unless !confirm_valid || self.validate.empty? + zip_provider = if zip_command ZipCommand.new(zip_command) else @@ -128,6 +129,7 @@ module Axlsx end return false unless !confirm_valid || self.validate.empty? + Relationship.initialize_ids_cache zip = write_parts(Zip::OutputStream.new(StringIO.new.binmode, true)) stream = zip.close_buffer @@ -383,6 +385,7 @@ module Axlsx if invalid_keys.any? raise ArgumentError.new("Invalid keyword arguments: #{invalid_keys}") end + [options.fetch(:confirm_valid, false), options.fetch(:zip_command, nil)] else warn "[DEPRECATION] Axlsx::Package#serialize with confirm_valid as a boolean is deprecated. " + diff --git a/lib/axlsx/stylesheet/color.rb b/lib/axlsx/stylesheet/color.rb index 28afaf11..4f358a78 100644 --- a/lib/axlsx/stylesheet/color.rb +++ b/lib/axlsx/stylesheet/color.rb @@ -54,6 +54,7 @@ module Axlsx v = v * 3 if v.size == 2 v = v.rjust(8, 'FF') raise ArgumentError, "Invalid color rgb value: #{v}." unless v.match(/[0-9A-F]{8}/) + @rgb = v end diff --git a/lib/axlsx/stylesheet/styles.rb b/lib/axlsx/stylesheet/styles.rb index e55e2c95..2a210776 100644 --- a/lib/axlsx/stylesheet/styles.rb +++ b/lib/axlsx/stylesheet/styles.rb @@ -292,6 +292,7 @@ module Axlsx # @return [CellProtection] def parse_protection_options(options = {}) return if (options.keys & [:hidden, :locked]).empty? + CellProtection.new(options) end @@ -302,6 +303,7 @@ module Axlsx # @see CellAlignment def parse_alignment_options(options = {}) return unless options[:alignment] + CellAlignment.new options[:alignment] end @@ -322,6 +324,7 @@ module Axlsx # @return [Font|Integer] def parse_font_options(options = {}) return if (options.keys & [:fg_color, :sz, :b, :i, :u, :strike, :outline, :shadow, :charset, :family, :font_name]).empty? + Axlsx.instance_values_for(fonts.first).each do |key, value| # Thanks for that 1.8.7 - cant do a simple merge... options[key.to_sym] = value unless options.keys.include?(key.to_sym) @@ -338,6 +341,7 @@ module Axlsx # @return [Fill|Integer] def parse_fill_options(options = {}) return unless options[:bg_color] + color = Color.new(:rgb => options[:bg_color]) dxf = options[:type] == :dxf color_key = dxf ? :bgColor : :fgColor diff --git a/lib/axlsx/util/serialized_attributes.rb b/lib/axlsx/util/serialized_attributes.rb index 9d46de75..eeac6e74 100644 --- a/lib/axlsx/util/serialized_attributes.rb +++ b/lib/axlsx/util/serialized_attributes.rb @@ -77,6 +77,7 @@ module Axlsx attrs.each do |attribute_name| value = values[attribute_name.to_s] next if value.nil? + value = yield value if block_given? element_name = Axlsx.camel(attribute_name, false) str << "<#{element_name}>#{value}</#{element_name}>" diff --git a/lib/axlsx/util/simple_typed_list.rb b/lib/axlsx/util/simple_typed_list.rb index 36651f1f..51b8a8d5 100644 --- a/lib/axlsx/util/simple_typed_list.rb +++ b/lib/axlsx/util/simple_typed_list.rb @@ -12,6 +12,7 @@ module Axlsx @allowed_types = type else raise ArgumentError, "Type must be a Class object or array of Class objects" unless type.is_a? Class + @allowed_types = [type] end @serialize_as = serialize_as unless serialize_as.nil? @@ -37,6 +38,7 @@ module Axlsx # any non populated cell in the matrix will be a nil value def transpose return @list.clone if @list.size == 0 + row_count = @list.size max_column_count = @list.map { |row| row.cells.size }.max result = Array.new(max_column_count) { Array.new(row_count) } @@ -105,6 +107,7 @@ module Axlsx def delete(v) return unless include? v raise ArgumentError, "Item is protected and cannot be deleted" if protected? index(v) + @list.delete v end @@ -114,6 +117,7 @@ module Axlsx def delete_at(index) @list[index] raise ArgumentError, "Item is protected and cannot be deleted" if protected? index + @list.delete_at index end @@ -125,6 +129,7 @@ module Axlsx def []=(index, v) DataTypeValidator.validate :SimpleTypedList_insert, @allowed_types, v raise ArgumentError, "Item is protected and cannot be changed" if protected? index + @list[index] = v v end @@ -137,6 +142,7 @@ module Axlsx def insert(index, v) DataTypeValidator.validate :SimpleTypedList_insert, @allowed_types, v raise ArgumentError, "Item is protected and cannot be changed" if protected? index + @list.insert(index, v) v end @@ -145,6 +151,7 @@ module Axlsx # @param [Integer] index def protected? index return false unless locked_at.is_a? Integer + index < locked_at end diff --git a/lib/axlsx/util/validators.rb b/lib/axlsx/util/validators.rb index 266709b0..99099f60 100644 --- a/lib/axlsx/util/validators.rb +++ b/lib/axlsx/util/validators.rb @@ -9,6 +9,7 @@ module Axlsx # @return [Boolean] true if validation succeeds. def self.validate(name, choices, v) raise ArgumentError, (ERR_RESTRICTION % [v.to_s, name, choices.inspect]) unless choices.include?(v) + true end end diff --git a/lib/axlsx/workbook/defined_name.rb b/lib/axlsx/workbook/defined_name.rb index 4b819d4c..6fe1f6e9 100644 --- a/lib/axlsx/workbook/defined_name.rb +++ b/lib/axlsx/workbook/defined_name.rb @@ -120,6 +120,7 @@ module Axlsx def to_xml_string(str = '') raise ArgumentError, 'you must specify the name for this defined name. Please read the documentation for Axlsx::DefinedName for more details' unless name + str << ('<definedName ' << 'name="' << name << '" ') serialized_attributes str str << ('>' << @formula << '</definedName>') diff --git a/lib/axlsx/workbook/defined_names.rb b/lib/axlsx/workbook/defined_names.rb index 30f80fcb..017c6d96 100644 --- a/lib/axlsx/workbook/defined_names.rb +++ b/lib/axlsx/workbook/defined_names.rb @@ -11,6 +11,7 @@ module Axlsx # @return [String] def to_xml_string(str = '') return if empty? + str << '<definedNames>' each { |defined_name| defined_name.to_xml_string(str) } str << '</definedNames>' diff --git a/lib/axlsx/workbook/workbook.rb b/lib/axlsx/workbook/workbook.rb index fde5d259..73388718 100644 --- a/lib/axlsx/workbook/workbook.rb +++ b/lib/axlsx/workbook/workbook.rb @@ -383,6 +383,7 @@ require 'axlsx/workbook/worksheet/selection.rb' sheet_name = cell_def.split('!')[0] if cell_def.match('!') worksheet = self.worksheets.select { |s| s.name == sheet_name }.first raise ArgumentError, 'Unknown Sheet' unless sheet_name && worksheet.is_a?(Worksheet) + worksheet[cell_def.gsub(/.+!/, "")] end diff --git a/lib/axlsx/workbook/workbook_views.rb b/lib/axlsx/workbook/workbook_views.rb index 025d083b..41010d0d 100644 --- a/lib/axlsx/workbook/workbook_views.rb +++ b/lib/axlsx/workbook/workbook_views.rb @@ -11,6 +11,7 @@ module Axlsx # @return [String] def to_xml_string(str = '') return if empty? + str << "<bookViews>" each { |view| view.to_xml_string(str) } str << '</bookViews>' diff --git a/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb b/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb index ac630f69..9e753759 100644 --- a/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +++ b/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb @@ -8,6 +8,7 @@ module Axlsx # @param [Worksheet] worksheet def initialize(worksheet) raise ArgumentError, 'you must provide a worksheet' unless worksheet.is_a?(Worksheet) + @worksheet = worksheet end @@ -24,6 +25,7 @@ module Axlsx # @return [String] def defined_name return unless range + Axlsx.cell_range(range.split(':').collect { |name| worksheet.name_to_cell(name) }) end @@ -57,6 +59,7 @@ module Axlsx columns.each do |column| rows.each do |row| next if row.hidden + column.apply(row, column_offset) end end @@ -66,6 +69,7 @@ module Axlsx # @return [String] def to_xml_string(str = '') return unless range + str << "<autoFilter ref='#{range}'>" columns.each { |filter_column| filter_column.to_xml_string(str) } str << "</autoFilter>" diff --git a/lib/axlsx/workbook/worksheet/auto_filter/filters.rb b/lib/axlsx/workbook/worksheet/auto_filter/filters.rb index da43a471..48f78038 100644 --- a/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +++ b/lib/axlsx/workbook/worksheet/auto_filter/filters.rb @@ -41,6 +41,7 @@ module Axlsx # TODO implement this for date filters as well! def apply(cell) return false unless cell + filter_items.each do |filter| return false if cell.value == filter.val end @@ -97,6 +98,7 @@ module Axlsx def date_group_items=(options) options.each do |date_group| raise ArgumentError, "date_group_items should be an array of hashes specifying the options for each date_group_item" unless date_group.is_a?(Hash) + date_group_items << DateGroupItem.new(date_group) end end @@ -144,6 +146,7 @@ include Axlsx::SerializedAttributes def initialize(options = {}) raise ArgumentError, "You must specify a year for date time grouping" unless options[:year] raise ArgumentError, "You must specify a date_time_grouping when creating a DateGroupItem for auto filter" unless options[:date_time_grouping] + parse_options options end diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb index a9685dac..cc668208 100644 --- a/lib/axlsx/workbook/worksheet/cell.rb +++ b/lib/axlsx/workbook/worksheet/cell.rb @@ -351,6 +351,7 @@ module Axlsx Axlsx::validate_unsigned_int(v) count = styles.cellXfs.size raise ArgumentError, "Invalid cellXfs id" unless v < count + @style = v end @@ -465,6 +466,7 @@ module Axlsx # Utility method for setting inline style attributes def set_run_style(validator, attr, value) return unless INLINE_STYLES.include?(attr.to_sym) + Axlsx.send(validator, value) unless validator.nil? self.instance_variable_set :"@#{attr.to_s}", value @is_text_run = true @@ -512,6 +514,7 @@ module Axlsx # @see Axlsx#date1904 def cast_value(v) return v if v.is_a?(RichText) || v.nil? + case type when :date self.style = STYLE_DATE if self.style == 0 diff --git a/lib/axlsx/workbook/worksheet/cell_serializer.rb b/lib/axlsx/workbook/worksheet/cell_serializer.rb index 15113fcd..94a1f93a 100644 --- a/lib/axlsx/workbook/worksheet/cell_serializer.rb +++ b/lib/axlsx/workbook/worksheet/cell_serializer.rb @@ -10,6 +10,7 @@ module Axlsx def to_xml_string(row_index, column_index, cell, str = '') str << ('<c r="' << Axlsx::cell_r(column_index, row_index) << '" s="' << cell.style.to_s << '" ') return str << '/>' if cell.value.nil? + method = cell.type self.send(method, cell, str) str << '</c>' diff --git a/lib/axlsx/workbook/worksheet/cfvo.rb b/lib/axlsx/workbook/worksheet/cfvo.rb index 773745f4..faa5d88a 100644 --- a/lib/axlsx/workbook/worksheet/cfvo.rb +++ b/lib/axlsx/workbook/worksheet/cfvo.rb @@ -46,6 +46,7 @@ module Axlsx # @see val def val=(v) raise ArgumentError, "#{v.inspect} must respond to to_s" unless v.respond_to?(:to_s) + @val = v.to_s end diff --git a/lib/axlsx/workbook/worksheet/col.rb b/lib/axlsx/workbook/worksheet/col.rb index 0b39024f..da3a9364 100644 --- a/lib/axlsx/workbook/worksheet/col.rb +++ b/lib/axlsx/workbook/worksheet/col.rb @@ -87,6 +87,7 @@ module Axlsx def outline_level=(v) Axlsx.validate_unsigned_numeric(v) raise ArgumentError, 'outlineLevel must be between 0 and 7' unless 0 <= v && v <= 7 + @outline_level = v end alias :outlineLevel= :outline_level= diff --git a/lib/axlsx/workbook/worksheet/col_breaks.rb b/lib/axlsx/workbook/worksheet/col_breaks.rb index 763e4268..78ccc565 100644 --- a/lib/axlsx/workbook/worksheet/col_breaks.rb +++ b/lib/axlsx/workbook/worksheet/col_breaks.rb @@ -25,6 +25,7 @@ module Axlsx # </colBreaks> def to_xml_string(str = '') return if empty? + str << ('<colBreaks count="' << size.to_s << '" manualBreakCount="' << size.to_s << '">') each { |brk| brk.to_xml_string(str) } str << '</colBreaks>' diff --git a/lib/axlsx/workbook/worksheet/cols.rb b/lib/axlsx/workbook/worksheet/cols.rb index 7d93e603..5b808b54 100644 --- a/lib/axlsx/workbook/worksheet/cols.rb +++ b/lib/axlsx/workbook/worksheet/cols.rb @@ -4,6 +4,7 @@ module Axlsx class Cols < SimpleTypedList def initialize(worksheet) raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet) + super Col @worksheet = worksheet end @@ -13,6 +14,7 @@ module Axlsx # @return [String] def to_xml_string(str = '') return if empty? + str << '<cols>' each { |item| item.to_xml_string(str) } str << '</cols>' diff --git a/lib/axlsx/workbook/worksheet/comment.rb b/lib/axlsx/workbook/worksheet/comment.rb index c2c94219..80ea8c4b 100644 --- a/lib/axlsx/workbook/worksheet/comment.rb +++ b/lib/axlsx/workbook/worksheet/comment.rb @@ -13,6 +13,7 @@ module Axlsx # @option [Boolean] visible This controls the visiblity of the associated vml_shape. def initialize(comments, options = {}) raise ArgumentError, "A comment needs a parent comments object" unless comments.is_a?(Comments) + @visible = true @comments = comments parse_options options diff --git a/lib/axlsx/workbook/worksheet/comments.rb b/lib/axlsx/workbook/worksheet/comments.rb index 3ec2ba01..452b198f 100644 --- a/lib/axlsx/workbook/worksheet/comments.rb +++ b/lib/axlsx/workbook/worksheet/comments.rb @@ -25,6 +25,7 @@ module Axlsx # @param [Worksheet] worksheet The sheet that these comments belong to. def initialize(worksheet) raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet) + super(Comment) @worksheet = worksheet @vml_drawing = VmlDrawing.new(self) @@ -39,6 +40,7 @@ module Axlsx raise ArgumentError, "Comment require an author" unless options[:author] raise ArgumentError, "Comment requires text" unless options[:text] raise ArgumentError, "Comment requires ref" unless options[:ref] + self << Comment.new(self, options) yield last if block_given? last diff --git a/lib/axlsx/workbook/worksheet/conditional_formattings.rb b/lib/axlsx/workbook/worksheet/conditional_formattings.rb index ad2e9c97..8b510ab9 100644 --- a/lib/axlsx/workbook/worksheet/conditional_formattings.rb +++ b/lib/axlsx/workbook/worksheet/conditional_formattings.rb @@ -4,6 +4,7 @@ module Axlsx # creates a new Tables object def initialize(worksheet) raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet) + super ConditionalFormatting @worksheet = worksheet end @@ -15,6 +16,7 @@ module Axlsx # serialize the conditional formattings def to_xml_string(str = "") return if empty? + each { |item| item.to_xml_string(str) } end end diff --git a/lib/axlsx/workbook/worksheet/data_validations.rb b/lib/axlsx/workbook/worksheet/data_validations.rb index 46cebe29..9c07da42 100644 --- a/lib/axlsx/workbook/worksheet/data_validations.rb +++ b/lib/axlsx/workbook/worksheet/data_validations.rb @@ -4,6 +4,7 @@ module Axlsx # creates a new Tables object def initialize(worksheet) raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet) + super DataValidation @worksheet = worksheet end @@ -15,6 +16,7 @@ module Axlsx # serialize the conditional formattings def to_xml_string(str = "") return if empty? + str << "<dataValidations count='#{size}'>" each { |item| item.to_xml_string(str) } str << '</dataValidations>' diff --git a/lib/axlsx/workbook/worksheet/dimension.rb b/lib/axlsx/workbook/worksheet/dimension.rb index eaf0d038..013097c8 100644 --- a/lib/axlsx/workbook/worksheet/dimension.rb +++ b/lib/axlsx/workbook/worksheet/dimension.rb @@ -20,6 +20,7 @@ module Axlsx # to. def initialize(worksheet) raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet) + @worksheet = worksheet end @@ -35,6 +36,7 @@ module Axlsx # @return [String] def to_xml_string(str = '') return if worksheet.rows.empty? + str << "<dimension ref=\"%s\"></dimension>" % sqref end @@ -56,6 +58,7 @@ module Axlsx # @return [String] def dimension_reference(cell, default) return default unless cell.respond_to?(:r) + cell.r end end diff --git a/lib/axlsx/workbook/worksheet/merged_cells.rb b/lib/axlsx/workbook/worksheet/merged_cells.rb index 60d95003..f54fd252 100644 --- a/lib/axlsx/workbook/worksheet/merged_cells.rb +++ b/lib/axlsx/workbook/worksheet/merged_cells.rb @@ -5,6 +5,7 @@ module Axlsx # @param [Worksheet] worksheet def initialize(worksheet) raise ArgumentError, 'you must provide a worksheet' unless worksheet.is_a?(Worksheet) + super String end @@ -27,6 +28,7 @@ module Axlsx # @return [String] def to_xml_string(str = '') return if empty? + str << "<mergeCells count='#{size}'>" each { |merged_cell| str << "<mergeCell ref='#{merged_cell}'></mergeCell>" } str << '</mergeCells>' diff --git a/lib/axlsx/workbook/worksheet/page_margins.rb b/lib/axlsx/workbook/worksheet/page_margins.rb index de0d099b..a0967817 100644 --- a/lib/axlsx/workbook/worksheet/page_margins.rb +++ b/lib/axlsx/workbook/worksheet/page_margins.rb @@ -67,6 +67,7 @@ module Axlsx def set(margins) margins.select do |k, v| next unless [:left, :right, :top, :bottom, :header, :footer].include? k + send("#{k}=", v) end end diff --git a/lib/axlsx/workbook/worksheet/pivot_tables.rb b/lib/axlsx/workbook/worksheet/pivot_tables.rb index 018fc6a7..c27162c3 100644 --- a/lib/axlsx/workbook/worksheet/pivot_tables.rb +++ b/lib/axlsx/workbook/worksheet/pivot_tables.rb @@ -4,6 +4,7 @@ module Axlsx # creates a new Tables object def initialize(worksheet) raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet) + super PivotTable @worksheet = worksheet end @@ -15,6 +16,7 @@ module Axlsx # returns the relationships required by this collection def relationships return [] if empty? + map { |pivot_table| Relationship.new(pivot_table, PIVOT_TABLE_R, "../#{pivot_table.pn}") } end end diff --git a/lib/axlsx/workbook/worksheet/protected_ranges.rb b/lib/axlsx/workbook/worksheet/protected_ranges.rb index d16dbbd6..aa627315 100644 --- a/lib/axlsx/workbook/worksheet/protected_ranges.rb +++ b/lib/axlsx/workbook/worksheet/protected_ranges.rb @@ -6,6 +6,7 @@ module Axlsx def initialize(worksheet) raise ArgumentError, 'You must provide a worksheet' unless worksheet.is_a?(Worksheet) + super ProtectedRange @worksheet = worksheet end @@ -27,6 +28,7 @@ module Axlsx # @return [String] def to_xml_string(str = '') return if empty? + str << '<protectedRanges>' each { |range| range.to_xml_string(str) } str << '</protectedRanges>' diff --git a/lib/axlsx/workbook/worksheet/rich_text_run.rb b/lib/axlsx/workbook/worksheet/rich_text_run.rb index 368b10ce..78639575 100644 --- a/lib/axlsx/workbook/worksheet/rich_text_run.rb +++ b/lib/axlsx/workbook/worksheet/rich_text_run.rb @@ -175,6 +175,7 @@ module Axlsx # @return [Array] def autowidth(widtharray) return if value.nil? + if styles.cellXfs[style].alignment && styles.cellXfs[style].alignment.wrap_text first = true value.to_s.split(/\r?\n/, -1).each do |line| @@ -194,6 +195,7 @@ module Axlsx # Utility method for setting inline style attributes def set_run_style(validator, attr, value) return unless INLINE_STYLES.include?(attr.to_sym) + Axlsx.send(validator, value) unless validator.nil? self.instance_variable_set :"@#{attr.to_s}", value end @@ -236,6 +238,7 @@ module Axlsx # imagemagick and loading metrics for every character. def font_size return sz if sz + font = styles.fonts[styles.cellXfs[style].fontId] || styles.fonts[0] (font.b || (defined?(@b) && @b)) ? (font.sz * 1.5) : font.sz end diff --git a/lib/axlsx/workbook/worksheet/row_breaks.rb b/lib/axlsx/workbook/worksheet/row_breaks.rb index b05e0587..2da31719 100644 --- a/lib/axlsx/workbook/worksheet/row_breaks.rb +++ b/lib/axlsx/workbook/worksheet/row_breaks.rb @@ -23,6 +23,7 @@ module Axlsx # </rowBreaks> def to_xml_string(str = '') return if empty? + str << ('<rowBreaks count="' << self.size.to_s << '" manualBreakCount="' << self.size.to_s << '">') each { |brk| brk.to_xml_string(str) } str << '</rowBreaks>' diff --git a/lib/axlsx/workbook/worksheet/sheet_data.rb b/lib/axlsx/workbook/worksheet/sheet_data.rb index f245d07c..f6a27b0e 100644 --- a/lib/axlsx/workbook/worksheet/sheet_data.rb +++ b/lib/axlsx/workbook/worksheet/sheet_data.rb @@ -5,6 +5,7 @@ module Axlsx # @param [Worksheet] worksheet The worksheet that owns this sheet data. def initialize(worksheet) raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet) + @worksheet = worksheet end diff --git a/lib/axlsx/workbook/worksheet/sheet_pr.rb b/lib/axlsx/workbook/worksheet/sheet_pr.rb index a870e4a3..9d6c0b5e 100644 --- a/lib/axlsx/workbook/worksheet/sheet_pr.rb +++ b/lib/axlsx/workbook/worksheet/sheet_pr.rb @@ -31,6 +31,7 @@ module Axlsx # @param [Worksheet] worksheet The worksheet that owns this SheetPr object def initialize(worksheet, options = {}) raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet) + @worksheet = worksheet @outline_pr = nil parse_options options diff --git a/lib/axlsx/workbook/worksheet/sheet_protection.rb b/lib/axlsx/workbook/worksheet/sheet_protection.rb index 3ca17737..68202f08 100644 --- a/lib/axlsx/workbook/worksheet/sheet_protection.rb +++ b/lib/axlsx/workbook/worksheet/sheet_protection.rb @@ -66,6 +66,7 @@ module Axlsx # encodes password for protection locking def password=(v) return if v == nil + @password = create_password_hash(v) end diff --git a/lib/axlsx/workbook/worksheet/tables.rb b/lib/axlsx/workbook/worksheet/tables.rb index 69e59fe5..20ba4789 100644 --- a/lib/axlsx/workbook/worksheet/tables.rb +++ b/lib/axlsx/workbook/worksheet/tables.rb @@ -4,6 +4,7 @@ module Axlsx # creates a new Tables object def initialize(worksheet) raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet) + super Table @worksheet = worksheet end @@ -15,6 +16,7 @@ module Axlsx # returns the relationships required by this collection def relationships return [] if empty? + map { |table| Relationship.new(table, TABLE_R, "../#{table.pn}") } end @@ -23,6 +25,7 @@ module Axlsx # @return [String] def to_xml_string(str = "") return if empty? + str << "<tableParts count='#{size}'>" each { |table| str << "<tablePart r:id='#{table.rId}'/>" } str << '</tableParts>' diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index 18daaeeb..d8451e9f 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -169,6 +169,7 @@ module Axlsx # @see #page_setup def fit_to_page? return false unless Axlsx.instance_values_for(self).keys.include?('page_setup') + page_setup.fit_to_page? end @@ -526,6 +527,7 @@ module Axlsx def column_widths(*widths) widths.each_with_index do |value, index| next if value == nil + Axlsx::validate_unsigned_numeric(value) unless value == nil find_or_create_column_info(index).width = value end @@ -733,9 +735,11 @@ module Axlsx DataTypeValidator.validate :worksheet_name, String, name # ignore first character (BOM) after encoding to utf16 because Excel does so, too. raise ArgumentError, (ERR_SHEET_NAME_EMPTY) if name.empty? + character_length = name.encode("utf-16")[1..-1].encode("utf-16").bytesize / 2 raise ArgumentError, (ERR_SHEET_NAME_TOO_LONG % name) if character_length > WORKSHEET_MAX_NAME_LENGTH raise ArgumentError, (ERR_SHEET_NAME_CHARACTER_FORBIDDEN % name) if WORKSHEET_NAME_FORBIDDEN_CHARS.any? { |char| name.include? char } + name = Axlsx::coder.encode(name) sheet_names = @workbook.worksheets.reject { |s| s == self }.map { |s| s.name } raise ArgumentError, (ERR_DUPLICATE_SHEET_NAME % name) if sheet_names.include?(name) @@ -828,6 +832,7 @@ module Axlsx def add_autofilter_defined_name_to_workbook return if !auto_filter.range + workbook.add_defined_name auto_filter.defined_name, name: '_xlnm._FilterDatabase', local_sheet_id: index, hidden: 1 end end diff --git a/lib/axlsx/workbook/worksheet/worksheet_comments.rb b/lib/axlsx/workbook/worksheet/worksheet_comments.rb index c40587ae..29ea6fc8 100644 --- a/lib/axlsx/workbook/worksheet/worksheet_comments.rb +++ b/lib/axlsx/workbook/worksheet/worksheet_comments.rb @@ -6,6 +6,7 @@ module Axlsx # param [Worksheet] worksheet The worksheet comments in thes object belong to def initialize(worksheet) raise ArugumentError, 'You must provide a worksheet' unless worksheet.is_a?(Worksheet) + @worksheet = worksheet end @@ -28,6 +29,7 @@ module Axlsx # @return [Relationships] def relationships return [] unless has_comments? + comments.relationships end @@ -49,6 +51,7 @@ module Axlsx # @return [String] def to_xml_string(str = '') return unless has_comments? + str << "<legacyDrawing r:id='#{drawing_rId}' />" end end diff --git a/lib/axlsx/workbook/worksheet/worksheet_drawing.rb b/lib/axlsx/workbook/worksheet/worksheet_drawing.rb index e461ffa9..c2819393 100644 --- a/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +++ b/lib/axlsx/workbook/worksheet/worksheet_drawing.rb @@ -8,6 +8,7 @@ module Axlsx # @param [Worksheet] worksheet def initialize(worksheet) raise ArgumentError, 'you must provide a worksheet' unless worksheet.is_a?(Worksheet) + @worksheet = worksheet @drawing = nil end @@ -43,6 +44,7 @@ module Axlsx # @return [Relationship] def relationship return unless has_drawing? + Relationship.new(self, DRAWING_R, "../#{drawing.pn}") end @@ -50,6 +52,7 @@ module Axlsx # @param [String] str def to_xml_string(str = '') return unless has_drawing? + str << "<drawing r:id='#{relationship.Id}'/>" end end diff --git a/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb b/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb index bda87995..f20d671d 100644 --- a/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +++ b/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb @@ -49,6 +49,7 @@ module Axlsx # @return [Relationship] def relationship return unless @target == :external + Relationship.new(self, HYPERLINK_R, location, :target_mode => :External) end diff --git a/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb b/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb index 5c49fdb3..4771efb1 100644 --- a/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +++ b/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb @@ -21,6 +21,7 @@ module Axlsx # @return Array def relationships return [] if empty? + map { |hyperlink| hyperlink.relationship } end @@ -28,6 +29,7 @@ module Axlsx # @return [String] def to_xml_string(str = '') return if empty? + str << '<hyperlinks>' each { |hyperlink| hyperlink.to_xml_string(str) } str << '</hyperlinks>' |
