columnWidth property

double get columnWidth

Represents the column width.

Implementation

double get columnWidth {
  final Column? columnObj = worksheet.columns[column];
  if (columnObj != null) {
    return columnObj.width;
  }
  return 0;
}
set columnWidth (double value)

Sets width of all the column in the range, measured in points.

Workbook workbook = new Workbook();
Worksheet sheet = workbook.worksheets[0];
Range range = sheet.getRangeByName('A1');
range.columnWidth = 25;
List<int> bytes = workbook.saveAsStream();
File('ColumnWidth.xlsx').writeAsBytes(bytes);
workbook.dispose();

Implementation

set columnWidth(double value) {
  if (isSingleRange) {
    Column? columnObj = worksheet.columns[column];
    if (columnObj == null) {
      columnObj = Column(_worksheet);
      columnObj.index = column;
      worksheet.columns[column] = columnObj;
    }
    columnObj.width = value;
  } else {
    // ignore: prefer_final_locals
    for (int iRow = row, iLastRow = lastRow; iRow <= iLastRow; iRow++) {
      // ignore: prefer_final_locals
      for (int iCol = column, iLastCol = lastColumn;
          iCol <= iLastCol;
          iCol++) {
        worksheet.getRangeByIndex(iRow, iCol).columnWidth = value;
      }
    }
  }
}