cellStyle property

Style get cellStyle
Workbook workbook = new Workbook();
Worksheet sheet = workbook.worksheets[0];
Style rangeStyle = sheet.getRangeByName('A1').cellStyle;
rangeStyle.bold = true;
List<int> bytes = workbook.saveAsStream();
File('CellStyleRange.xlsx').writeAsBytes(bytes);
workbook.dispose();

Implementation

Style get cellStyle {
  if (isSingleRange) {
    if (_cellStyle == null && !workbook._saving) {
      _cellStyle = CellStyle(workbook);
      _setRange();
    } else if (_cellStyle != null &&
        !workbook._saving &&
        (_cellStyle! as CellStyle).isGlobalStyle) {
      _cellStyle = (_cellStyle! as CellStyle)._clone();
    }
    return _cellStyle!;
  }
  return CellStyleWrapper(this);
}
set cellStyle (Style value)

Sets the cell style.

Workbook workbook = new Workbook();
Worksheet sheet = workbook.worksheets[0];
Style cellStyle = new CellStyle(workbook);
cellStyle.backColor = '#78921A';
workbook.styles.addStyle(cellStyle);
Range range1 = sheet.getRangeByIndex(1, 1);
range1.cellStyle = cellStyle;
List<int> bytes = workbook.saveAsStream();
File('CellStyleRange.xlsx').writeAsBytes(bytes);
workbook.dispose();

Implementation

set cellStyle(Style value) {
  if (isSingleRange) {
    _cellStyle = (value as CellStyle)._clone();
    _setRange();
  } 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++) {
        final Range range = worksheet.getRangeByIndex(iRow, iCol);
        range._cellStyle = value;
        range._setRange();
      }
    }
  }
}