def store_ai(id, type, formula, format_index = 0)   # :nodoc:
    formula = '' if formula == [""]

    record       = 0x1051     # Record identifier.
    length       = 0x0008     # Number of bytes to follow.
    # id                      # Link index.
    # type                    # Reference type.
    # formula                 # Pre-parsed formula.
    # format_index            # Num format index.
    grbit        = 0x0000     # Option flags.

    ruby_19 { formula = convert_to_ascii_if_ascii(formula) }

    formula_length  = formula.bytesize
    length += formula_length

    header = [record, length].pack('vv')
    data   = [id].pack('C')
    data  += [type].pack('C')
    data  += [grbit].pack('v')
    data  += [format_index].pack('v')
    data  += [formula_length].pack('v')
    if formula.respond_to?(:to_array)
      data +=
        ruby_18 { formula[0] } ||
        ruby_19 { formula[0].encode('BINARY') }
    else
      data +=
        ruby_18 { formula                  unless formula.nil? } ||
        ruby_19 { formula.encode('BINARY') unless formula.nil? }
    end

    append(header, data)
  end
def store_ai(id, type, formula, format_index = 0)   # :nodoc:
    formula = '' if formula == [""]

    record       = 0x1051     # Record identifier.
    length       = 0x0008     # Number of bytes to follow.
    # id                      # Link index.
    # type                    # Reference type.
    # formula                 # Pre-parsed formula.
    # format_index            # Num format index.
    grbit        = 0x0000     # Option flags.

    ruby_19 { formula = convert_to_ascii_if_ascii(formula) }

    formula_length  = formula.bytesize
    length += formula_length

    header = [record, length].pack('vv')
    data   = [id].pack('C')
    data  += [type].pack('C')
    data  += [grbit].pack('v')
    data  += [format_index].pack('v')
    data  += [formula_length].pack('v')
    if formula.respond_to?(:to_array)
      data +=
        ruby_18 { formula[0] } ||
        ruby_19 { formula[0].encode('BINARY') }
    else
      data +=
        ruby_18 { formula                  unless formula.nil? } ||
        ruby_19 { formula.encode('BINARY') unless formula.nil? }
    end

    append(header, data)
  end
Write the AI chart BIFF record.