Sha256: 4a14fc24e792308fe7fda85d77a43a41ebff41f5ae1a8ea9d453ca828356e552

Contents?: true

Size: 1.98 KB

Versions: 8

Compression:

Stored size: 1.98 KB

Contents

# frozen_string_literal: true

require_relative 'table_part/autofilter'
require_relative 'table_part/extension_list'
require_relative 'table_part/table_style_info'
require_relative 'table_part/table_columns'
module OoxmlParser
  # Class for `tablePart` data
  class TablePart < OOXMLDocumentObject
    # @return [String] id of table part
    attr_reader :id
    attr_accessor :name, :display_name, :reference, :autofilter, :columns
    # @return [ExtensionList] list of extensions
    attr_accessor :extension_list
    # @return [TableColumns] list of table columns
    attr_reader :table_columns
    # @return [TableStyleInfo] describe style of table
    attr_accessor :table_style_info

    # Parse TablePart object
    # @param node [Nokogiri::XML:Element] node to parse
    # @return [TablePart] result of parsing
    def parse(node)
      node.attributes.each do |key, value|
        case key
        when 'id'
          @id = value.value.to_s
        end
      end
      link_to_table_part_xml = root_object.get_link_from_rels(@id)
      doc = parse_xml(root_object.unpacked_folder + link_to_table_part_xml.gsub('..', 'xl'))
      table_node = doc.xpath('xmlns:table').first
      table_node.attributes.each do |key, value|
        case key
        when 'name'
          @name = value.value.to_s
        when 'displayName'
          @display_name = value.value.to_s
        when 'ref'
          @reference = Coordinates.parser_coordinates_range value.value.to_s
        end
      end
      table_node.xpath('*').each do |node_child|
        case node_child.name
        when 'autoFilter'
          @autofilter = Autofilter.new(parent: self).parse(node_child)
        when 'extLst'
          @extension_list = ExtensionList.new(parent: self).parse(node_child)
        when 'tableColumns'
          @table_columns = TableColumns.new(parent: self).parse(node_child)
        when 'tableStyleInfo'
          @table_style_info = TableStyleInfo.new(parent: self).parse(node_child)
        end
      end
      self
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ooxml_parser-0.37.1 lib/ooxml_parser/xlsx_parser/workbook/worksheet/table_part.rb
ooxml_parser-0.37.0 lib/ooxml_parser/xlsx_parser/workbook/worksheet/table_part.rb
ooxml_parser-0.36.1 lib/ooxml_parser/xlsx_parser/workbook/worksheet/table_part.rb
ooxml_parser-0.36.0 lib/ooxml_parser/xlsx_parser/workbook/worksheet/table_part.rb
ooxml_parser-0.35.0 lib/ooxml_parser/xlsx_parser/workbook/worksheet/table_part.rb
ooxml_parser-0.34.2 lib/ooxml_parser/xlsx_parser/workbook/worksheet/table_part.rb
ooxml_parser-0.34.1 lib/ooxml_parser/xlsx_parser/workbook/worksheet/table_part.rb
ooxml_parser-0.34.0 lib/ooxml_parser/xlsx_parser/workbook/worksheet/table_part.rb