class Axlsx::FilterColumn

The filterColumn collection identifies a particular column in the AutoFilter range and specifies filter information that has been applied to this column. If a column in the AutoFilter range has no criteria specified, then there is no corresponding filterColumn collection expressed for that column.

Constants

FILTERS

Allowed filters

Attributes

col_id[R]

Zero-based index indicating the AutoFilter column to which this filter information applies. @return [Integer]

filter[R]

The actual filter being dealt with here This could be any one of the allowed filter types

Public Class Methods

new(col_id, filter_type, options = {}) { |filter| ... } click to toggle source

Creates a new FilterColumn object @note This class yeilds its filter object as that is where the vast majority of processing will be done @param [Integer|Cell] col_id The zero based index for the column to which this filter will be applied @param [Symbol] filter_type The symbolized class name of the filter to apply to this column. @param [Hash] options options for this object and the filter @option [Boolean] hidden_button @see hidden_button @option [Boolean] show_button @see show_button

# File lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb, line 18
def initialize(col_id, filter_type, options = {})
  RestrictionValidator.validate 'FilterColumn.filter', FILTERS, filter_type
  #Axlsx::validate_unsigned_int(col_id)
  self.col_id = col_id
  parse_options options
  @filter = Axlsx.const_get(Axlsx.camel(filter_type)).new(options)
  yield @filter if block_given?
end

Public Instance Methods

apply(row, offset) click to toggle source

Apply the filters for this column @param [Array] row A row from a worksheet that needs to be filtered.

# File lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb, line 67
def apply(row, offset)
  row.hidden = @filter.apply(row.cells[offset+col_id.to_i])
end
col_id=(column_index) click to toggle source

Sets the col_id attribute for this filter column. @param [Integer | Cell] column_index The zero based index of the column to which this filter applies.

When you specify a cell, the column index will be read off the cell

@return [Integer]

# File lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb, line 58
def col_id=(column_index)
  column_index = column_index.col if column_index.is_a?(Cell)
  Axlsx.validate_unsigned_int column_index
  @col_id = column_index
end
hidden_button() click to toggle source

Flag indicating whether the AutoFilter button for this column is hidden. @return [Boolean]

# File lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb, line 50
def hidden_button
  @hidden_button ||= false
end
hidden_button=(hidden) click to toggle source

@param [Boolean] hidden Flag indicating whether the AutoFilter button for this column is hidden. @return [Boolean]

# File lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb, line 72
def hidden_button=(hidden)
  Axlsx.validate_boolean hidden
  @hidden_button = hidden
end
show_button() click to toggle source

Flag indicating whether the filter button is visible. When the cell containing the filter button is merged with another cell, the filter button can be hidden, and not drawn. @return [Boolean]

# File lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb, line 44
def show_button
  @show_button ||= true
end
show_button=(show) click to toggle source

Flag indicating whether the AutoFilter button is show. This is undocumented in the spec, but exists in the schema file as an optional attribute. @param [Boolean] show Show or hide the button @return [Boolean]

# File lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb, line 82
def show_button=(show)
  Axlsx.validate_boolean show
  @show_botton = show
end
to_xml_string(str='') click to toggle source

Serialize the object to xml

# File lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb, line 88
def to_xml_string(str='')
  str << "<filterColumn #{serialized_attributes}>"
  @filter.to_xml_string(str)
  str << "</filterColumn>"
end