insertRowIterables method

void insertRowIterables(
  1. List<CellValue?> row,
  2. int rowIndex, {
  3. int startingColumn = 0,
  4. bool overwriteMergedCells = true,
})

Adds the row iterables in the given rowIndex = rowIndex in sheet

startingColumn tells from where we should start putting the row iterables

overwriteMergedCells when set to true will over-write mergedCell and does not jumps to next unqiue cell.

overwriteMergedCells when set to false puts the cell value in next unique cell available and putting the value in merged cells only once.

Implementation

void insertRowIterables(List<CellValue?> row, int rowIndex,
    {int startingColumn = 0, bool overwriteMergedCells = true}) {
  if (row.isEmpty || rowIndex < 0) {
    return;
  }

  _checkMaxRow(rowIndex);
  int columnIndex = 0;
  if (startingColumn > 0) {
    columnIndex = startingColumn;
  }
  _checkMaxColumn(columnIndex + row.length);
  int rowsLength = _maxRows,
      maxIterationIndex = row.length - 1,
      currentRowPosition = 0; // position in [row] iterables

  if (overwriteMergedCells || rowIndex >= rowsLength) {
    // Normally iterating and putting the data present in the [row] as we are on the last index.

    while (currentRowPosition <= maxIterationIndex) {
      _putData(rowIndex, columnIndex, row[currentRowPosition]);
      currentRowPosition++;
      columnIndex++;
    }
  } else {
    // expensive function as per time complexity
    _selfCorrectSpanMap(_excel);
    List<_Span> _spanObjectsList = _getSpannedObjects(rowIndex, columnIndex);

    if (_spanObjectsList.isEmpty) {
      while (currentRowPosition <= maxIterationIndex) {
        _putData(rowIndex, columnIndex, row[currentRowPosition]);
        currentRowPosition++;
        columnIndex++;
      }
    } else {
      while (currentRowPosition <= maxIterationIndex) {
        if (_isInsideSpanObject(_spanObjectsList, columnIndex, rowIndex)) {
          _putData(rowIndex, columnIndex, row[currentRowPosition]);
          currentRowPosition++;
        }
        columnIndex++;
      }
    }
  }
}