def store_autofilter(index, operator_1, token_1,   #:nodoc:
                                 join = nil, operator_2 = nil, token_2 = nil)
    record          = 0x009E
    length          = 0x0000

    top10_active    = 0
    top10_direction = 0
    top10_percent   = 0
    top10_value     = 101

    grbit       = join || 0
    optimised_1 = 0
    optimised_2 = 0
    doper_1     = ''
    doper_2     = ''
    string_1    = ''
    string_2    = ''

    # Excel used an optimisation in the case of a simple equality.
    optimised_1 = 1 if               operator_1 == 2
    optimised_2 = 1 if operator_2 && operator_2 == 2

    # Convert non-simple equalities back to type 2. See  parse_filter_tokens().
    operator_1 = 2 if               operator_1 == 22
    operator_2 = 2 if operator_2 && operator_2 == 22

    # Handle a "Top" style expression.
    if operator_1 >= 30
      # Remove the second expression if present.
      operator_2 = nil
      token_2    = nil

      # Set the active flag.
      top10_active    = 1

      if (operator_1 == 30 or operator_1 == 31)
        top10_direction = 1
      end

      if (operator_1 == 31 or operator_1 == 33)
        top10_percent = 1
      end

      if (top10_direction == 1)
        operator_1 = 6
      else
        operator_1 = 3
      end

      top10_value     = token_1.to_i
      token_1         = 0
    end

    grbit     |= optimised_1      << 2
    grbit     |= optimised_2      << 3
    grbit     |= top10_active     << 4
    grbit     |= top10_direction  << 5
    grbit     |= top10_percent    << 6
    grbit     |= top10_value      << 7

    doper_1, string_1 = pack_doper(operator_1, token_1)
    doper_2, string_2 = pack_doper(operator_2, token_2)

    doper_1  = '' unless doper_1
    doper_2  = '' unless doper_2
    string_1 = '' unless string_1
    string_2 = '' unless string_2

    data = [index].pack('v')
    data += [grbit].pack('v')
    data += doper_1 + doper_2 + string_1 + string_2

    length  = data.bytesize
    header  = [record, length].pack('vv')

    prepend(header, data)
  end
def store_autofilter(index, operator_1, token_1,   #:nodoc:
                                 join = nil, operator_2 = nil, token_2 = nil)
    record          = 0x009E
    length          = 0x0000

    top10_active    = 0
    top10_direction = 0
    top10_percent   = 0
    top10_value     = 101

    grbit       = join || 0
    optimised_1 = 0
    optimised_2 = 0
    doper_1     = ''
    doper_2     = ''
    string_1    = ''
    string_2    = ''

    # Excel used an optimisation in the case of a simple equality.
    optimised_1 = 1 if               operator_1 == 2
    optimised_2 = 1 if operator_2 && operator_2 == 2

    # Convert non-simple equalities back to type 2. See  parse_filter_tokens().
    operator_1 = 2 if               operator_1 == 22
    operator_2 = 2 if operator_2 && operator_2 == 22

    # Handle a "Top" style expression.
    if operator_1 >= 30
      # Remove the second expression if present.
      operator_2 = nil
      token_2    = nil

      # Set the active flag.
      top10_active    = 1

      if (operator_1 == 30 or operator_1 == 31)
        top10_direction = 1
      end

      if (operator_1 == 31 or operator_1 == 33)
        top10_percent = 1
      end

      if (top10_direction == 1)
        operator_1 = 6
      else
        operator_1 = 3
      end

      top10_value     = token_1.to_i
      token_1         = 0
    end

    grbit     |= optimised_1      << 2
    grbit     |= optimised_2      << 3
    grbit     |= top10_active     << 4
    grbit     |= top10_direction  << 5
    grbit     |= top10_percent    << 6
    grbit     |= top10_value      << 7

    doper_1, string_1 = pack_doper(operator_1, token_1)
    doper_2, string_2 = pack_doper(operator_2, token_2)

    doper_1  = '' unless doper_1
    doper_2  = '' unless doper_2
    string_1 = '' unless string_1
    string_2 = '' unless string_2

    data = [index].pack('v')
    data += [grbit].pack('v')
    data += doper_1 + doper_2 + string_1 + string_2

    length  = data.bytesize
    header  = [record, length].pack('vv')

    prepend(header, data)
  end
Function to write worksheet AUTOFILTER records. These contain 2 Biff Doper
 structures to represent the 2 possible filter conditions.