cellsAsTsv method
A rectangle covering cells; cells inside the bounding box but not in the
set are emitted as empty fields, so the block keeps its shape on paste.
Implementation
String cellsAsTsv(Iterable<CellRef> cells) {
final list = cells.toList();
if (list.isEmpty) return '';
final rs = list.map((c) => c.row).toList()..sort();
final cs = list.map((c) => c.col).toList()..sort();
final minR = rs.first, maxR = rs.last, minC = cs.first, maxC = cs.last;
final picked = {for (final c in list) (c.row * 100000 + c.col)};
final buf = <String>[];
for (var r = minR; r <= maxR; r++) {
final line = <String>[];
for (var c = minC; c <= maxC; c++) {
line.add(picked.contains(r * 100000 + c) ? _san(cellValue(r, c)) : '');
}
buf.add(line.join('\t'));
}
return buf.join('\n');
}