columnIndexOf method

Future<int> columnIndexOf(
  1. Object key, {
  2. bool add = false,
  3. int inRow = 1,
})

Returns index of a column with key value in inRow.

Expands current sheet's size if requested range is out of sheet's bounds.

key - value to look for

inRow - optional (defaults to 1), row index in which key is looked for, rows start at index 1

add - optional (defaults to false), whether the key should be added to inRow in case of absence

Returns Future -1 if not found and add is false.

Throws GSheetsException.

Implementation

Future<int> columnIndexOf(
  Object key, {
  bool add = false,
  int inRow = 1,
}) async {
  final cKey = parseKey(key);
  final columnKeys = await row(inRow);
  var column = columnKeys.indexOf(cKey) + 1;
  if (column < 1) {
    column = -1;
    if (add) {
      await _ws._update(
        values: [cKey],
        range: await _ws._columnRange(columnKeys.length + 1, inRow, 1),
        majorDimension: dimenColumns,
      );
      column = columnKeys.length + 1;
    }
  }
  return column;
}