Sha256: a8c8de58235bfce5e5f0fbd8a466d14c189eca08b7e02646c0d8808293b9c781

Contents?: true

Size: 1.75 KB

Versions: 29

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

module OoxmlParser
  # Properties of XLSX column
  class XlsxColumnProperties < OOXMLDocumentObject
    attr_accessor :from, :to, :width, :style
    # @return [True, False] is width custom
    attr_accessor :custom_width
    # @return [True, False] Flag indicating if the
    # specified column(s) is set to 'best fit'
    attr_accessor :best_fit
    # @return [True, False] Flag indicating if the
    # specified column(s) is hidden
    attr_reader :hidden

    # Parse XlsxColumnProperties object
    # @param node [Nokogiri::XML:Element] node to parse
    # @return [XlsxColumnProperties] result of parsing
    def parse(node)
      node.attributes.each do |key, value|
        case key
        when 'min'
          @from = value.value.to_i
        when 'max'
          @to = value.value.to_i
        when 'style'
          @style = root_object.style_sheet.cell_xfs.xf_array[value.value.to_i]
        when 'width'
          @width = value.value.to_f - 0.7109375
        when 'customWidth'
          @custom_width = option_enabled?(node, 'customWidth')
        when 'bestFit'
          @best_fit = attribute_enabled?(value)
        when 'hidden'
          @hidden = attribute_enabled?(value)
        end
      end
      self
    end

    # Parse list of XlsxColumnProperties
    # @param columns_width_node [Nokogiri::XML:Element] node to parse
    # @param parent [OOXMLDocumentObject] parent of result objects
    # @return [Array<XlsxColumnProperties>] list of XlsxColumnProperties
    def self.parse_list(columns_width_node, parent: nil)
      columns = []
      columns_width_node.xpath('xmlns:col').each do |col_node|
        col = XlsxColumnProperties.new(parent: parent).parse(col_node)
        columns << col
      end
      columns
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
ooxml_parser-0.11.0 lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_column_properties.rb
ooxml_parser-0.10.0 lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_column_properties.rb
ooxml_parser-0.9.1 lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_column_properties.rb
ooxml_parser-0.9.0 lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_column_properties.rb
ooxml_parser-0.8.1 lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_column_properties.rb
ooxml_parser-0.8.0 lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_column_properties.rb
ooxml_parser-0.7.2 lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_column_properties.rb
ooxml_parser-0.7.1 lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_column_properties.rb
ooxml_parser-0.7.0 lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_column_properties.rb