rangefromList static method

A1Range rangefromList(
  1. List<A1Partial?> listFrom,
  2. List<A1Partial?> listTo, {
  3. Object? tag,
  4. A1? anchor,
})

Conveniance function for determining range from a list of partials

Implementation

static A1Range rangefromList(
    List<A1Partial?> listFrom, List<A1Partial?> listTo,
    {Object? tag, A1? anchor}) {
  // clean the nulls and create from list
  final fromItems = listFrom.where((element) => element != null);
  final fromColumns =
      fromItems.map((A1Partial? e) => e?.column ?? 0).toList();
  fromColumns.sort();
  final fromColumn = fromColumns.first;
  final fromRows = fromItems.map((A1Partial? e) => e?.row ?? 0).toList();
  fromRows.sort();
  final fromRow = fromRows.first;

  // clean the nulls and create to list
  final toItems = listTo.where((element) => element != null);
  final toColumns =
      toItems.map((A1Partial? e) => e?.column ?? A1.maxColumns).toList();
  toColumns.sort();

  final toColumn = toColumns.last;
  final toRows = toItems.map((A1Partial? e) => e?.row ?? A1.maxRows).toList();
  toRows.sort();
  final toRow = toRows.last;

  return A1Range.fromPartials(
    A1Partial.fromVector(fromColumn, fromRow),
    A1Partial.fromVector(toColumn == A1.maxColumns ? null : toColumn,
        toRow == A1.maxRows ? null : toRow),
    tag: tag,
    anchor: anchor,
  );
}