autoFitColumn method
Changes the width of the specified column to achieve the best fit.
// Create a new Excel Document.
final Workbook workbook = Workbook();
// Accessing sheet via index.
final Worksheet sheet = workbook.worksheets[0];
final Range range = sheet.getRangeByName('A1');
range.setText('Test for AutoFit Column');
// Auto Fit column.
sheet.autoFitColumn(1);
// save and dispose.
final List<int> bytes = workbook.saveAsStream();
saveAsExcel(bytes, 'AutoFitColumn.xlsx');
workbook.dispose();
Implementation
void autoFitColumn(int colIndex) {
final Range range = getRangeByIndex(
getFirstRow(), getFirstColumn(), getLastRow(), getLastColumn());
range.autoFitToColumn(colIndex, colIndex);
}