removeRow method
If sheet
exists and rowIndex < maxRows
then it removes row at index = rowIndex
Implementation
void removeRow(int rowIndex) {
if (rowIndex < 0 || rowIndex >= _maxRows) {
return;
}
_checkMaxRow(rowIndex);
bool updateSpanCell = false;
for (int i = 0; i < _spanList.length; i++) {
_Span? spanObj = _spanList[i];
if (spanObj == null) {
continue;
}
int startColumn = spanObj.columnSpanStart,
startRow = spanObj.rowSpanStart,
endColumn = spanObj.columnSpanEnd,
endRow = spanObj.rowSpanEnd;
if (rowIndex <= endRow) {
_Span newSpanObj = _Span();
if (rowIndex < startRow) {
startRow -= 1;
}
endRow -= 1;
if (/* startRow >= endRow */
(rowIndex == (endRow + 1)) &&
(rowIndex == (rowIndex < startRow ? startRow + 1 : startRow))) {
_spanList[i] = null;
} else {
newSpanObj._start = [startRow, startColumn];
newSpanObj._end = [endRow, endColumn];
_spanList[i] = newSpanObj;
}
updateSpanCell = true;
_excel._mergeChanges = true;
}
if (_spanList[i] != null) {
String rc = getSpanCellId(startColumn, startRow, endColumn, endRow);
if (!_spannedItems.contains(rc)) {
_spannedItems.add(rc);
}
}
}
_cleanUpSpanMap();
if (updateSpanCell) {
_excel._mergeChangeLookup = sheetName;
}
if (_sheetData.isNotEmpty) {
Map<int, Map<int, Data>> _data = Map<int, Map<int, Data>>();
if (rowIndex <= maxRows - 1) {
/// do the shifting task
List<int> sortedKeys = _sheetData.keys.toList()..sort();
sortedKeys.forEach((rowKey) {
if (rowKey < rowIndex && _sheetData[rowKey] != null) {
_data[rowKey] = Map<int, Data>.from(_sheetData[rowKey]!);
}
if (rowIndex == rowKey && _sheetData[rowKey] != null) {
_sheetData.remove(rowKey);
}
if (rowIndex < rowKey && _sheetData[rowKey] != null) {
_data[rowKey - 1] = Map<int, Data>.from(_sheetData[rowKey]!);
_sheetData.remove(rowKey);
}
});
_sheetData = Map<int, Map<int, Data>>.from(_data);
}
//_countRowAndCol();
} else {
_maxRows = 0;
_maxCols = 0;
}
if (_maxRows - 1 <= rowIndex) {
_maxRows -= 1;
}
}