Class: Axlsx::AutoFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/axlsx/workbook/worksheet/auto_filter.rb

Overview

This class represents an auto filter range in a worksheet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(worksheet) ⇒ AutoFilter

creates a new Autofilter object

Parameters:

Raises:

  • (ArgumentError)


8
9
10
11
# File 'lib/axlsx/workbook/worksheet/auto_filter.rb', line 8

def initialize(worksheet)
  raise ArgumentError, 'you must provide a worksheet' unless worksheet.is_a?(Worksheet)
  @worksheet = worksheet
end

Instance Attribute Details

#rangeString

The range the autofilter should be applied to. This should be a string like 'A1:B8'

Returns:

  • (String)


18
19
20
# File 'lib/axlsx/workbook/worksheet/auto_filter.rb', line 18

def range
  @range
end

#worksheetObject (readonly)

Returns the value of attribute worksheet.



13
14
15
# File 'lib/axlsx/workbook/worksheet/auto_filter.rb', line 13

def worksheet
  @worksheet
end

Instance Method Details

#defined_nameString

the formula for the defined name required for this auto filter

Returns:

  • (String)


22
23
24
25
# File 'lib/axlsx/workbook/worksheet/auto_filter.rb', line 22

def defined_name
  return unless range
  Axlsx.cell_range(range.split(':').collect { |name| worksheet.name_to_cell(name)})
end

#to_xml_string(str = '') ⇒ String

serialize the object

Returns:

  • (String)


29
30
31
# File 'lib/axlsx/workbook/worksheet/auto_filter.rb', line 29

def to_xml_string(str='')
  str << "<autoFilter ref='#{range}'></autoFilter>"
end