class OoxmlParser::XlsxColumnProperties

Properties of XLSX column

Attributes

best_fit[RW]

@return [True, False] Flag indicating if the specified column(s) is set to ‘best fit’

custom_width[RW]

@return [True, False] is width custom

from[R]

@return [Integer] First column affected by this ‘column info’ record.

hidden[R]

@return [True, False] Flag indicating if the specified column(s) is hidden

max[R]

@return [Integer] Last column affected by this ‘column info’ record.

min[R]

@return [Integer] First column affected by this ‘column info’ record.

style[RW]
to[R]

@return [Integer] Last column affected by this ‘column info’ record.

width[R]

@return [Float] width, in readable format

width_raw[R]

@return [Float] width in pixel, as stored in xml structure

Public Instance Methods

parse(node) click to toggle source

Parse XlsxColumnProperties object @param node [Nokogiri::XML:Element] node to parse @return [XlsxColumnProperties] result of parsing

# File lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_columns/xlsx_column_properties.rb, line 27
def parse(node)
  node.attributes.each do |key, value|
    case key
    when 'min'
      @min = value.value.to_i
    when 'max'
      @max = value.value.to_i
    when 'style'
      @style = root_object.style_sheet.cell_xfs.xf_array[value.value.to_i]
    when 'width'
      @width_raw = value.value.to_f
      @width = calculate_width(@width_raw)
    when 'customWidth'
      @custom_width = option_enabled?(node, 'customWidth')
    when 'bestFit'
      @best_fit = boolean_attribute_value(value)
    when 'hidden'
      @hidden = boolean_attribute_value(value)
    end
  end
  self
end

Private Instance Methods

calculate_width(value) click to toggle source

TODO: Currently width calculation use some magick number from old time ago

Actual formula is way more complicated and require data about
font max width for single character.
Read more in ECMA-376, §18.3.1.13

@param [Float] value raw value for width @return [Float] width value

# File lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_columns/xlsx_column_properties.rb, line 65
def calculate_width(value)
  value - 0.7109375
end