autoFitToRow method
Autofits row by checking only the cells in the row that are specified by column range.
Implementation
void autoFitToRow(int rowIndex, int firstColumn, int lastColumn) {
if (firstColumn == 0 || lastColumn == 0 || firstColumn > lastColumn) {
return;
}
final SizeF maxSize = SizeF(0, 0);
SizeF curSize;
bool hasRotation = false;
bool isMergedAndWrapped = false;
for (int j = firstColumn; j <= lastColumn; j++) {
if (rows[rowIndex] == null || rows[rowIndex]!.ranges[j] == null) {
continue;
}
final Range range = getRangeByIndex(rowIndex, j);
if (range.rowSpan > 1) {
continue;
}
final List<dynamic> result =
_measureCell(range, true, false, isMergedAndWrapped);
curSize = result[0] as SizeF;
isMergedAndWrapped = result[1] as bool;
if (maxSize.fontHeight < curSize.fontHeight &&
!(range.number != null &&
book.standardFontSize == range.cellStyle.fontSize)) {
maxSize.fontHeight = curSize.fontHeight;
}
if (range.cellStyle.rotation > 0 &&
maxSize.fontHeight < curSize.fontWidth &&
!range.isMerged &&
!range.cellStyle.wrapText) {
maxSize.fontHeight = curSize.fontWidth;
hasRotation = true;
}
}
if (maxSize.fontHeight == 0) {
maxSize.fontHeight =
book.measureString(_defaultStandardChar, book.fonts[0]).fontHeight;
}
double newHeight;
if (!hasRotation) {
newHeight = book.convertFromPixel(maxSize.fontHeight, 6);
} else {
newHeight = book.convertFromPixel(maxSize.fontHeight + _standardWidth, 6);
}
if (newHeight > defaultMaxHeight) {
newHeight = defaultMaxHeight;
}
final Range range = getRangeByIndex(rowIndex, firstColumn);
if (newHeight > standardHeight) {
range.setRowHeight(newHeight, isMergedAndWrapped);
} else {
range.setRowHeight(standardHeight, isMergedAndWrapped);
}
}