findByValue method

Future<List<Cell>> findByValue(
  1. Object value, {
  2. int fromRow = 1,
  3. int fromColumn = 1,
  4. int length = -1,
})

Find cells by value.

These cells cannot be updated by WorksheetAsCells insert method, Cell's post method instead.

value - value to look for

fromRow - optional (defaults to 1), index of a first row in which value looked for (rows before fromRow will be skipped), rows start at index 1

fromColumn - optional (defaults to 1), index of a first column in which value looked for (columns before fromColumn will be skipped), columns start at index 1 (column A)

length - optional (defaults to -1), the length of a table area in which value looked for, starting from fromRow and fromColumn if length is -1, all rows after fromRow and all columns after fromColumn will be used

Returns cells as Future List.

Throws GSheetsException.

Implementation

Future<List<Cell>> findByValue(
  Object value, {
  int fromRow = 1,
  int fromColumn = 1,
  int length = -1,
}) async {
  final valueString = parseString(value);
  final cells = <Cell>[];
  var rows = await _ws.values.allRows(
    fromRow: fromRow,
    fromColumn: fromColumn,
    length: length,
  );
  if (length > 0) rows = rows.take(length).toList();
  var rowNumber = fromRow;
  for (var row in rows) {
    var colNumber = fromColumn;
    for (var val in row) {
      if (val == valueString) {
        cells.add(Cell._(_ws, rowNumber, colNumber, val, false));
      }
      colNumber++;
    }
    rowNumber++;
  }
  return cells;
}