addStyle method

void addStyle(
  1. CellStyle style
)

Add styles to the collection

final Workbook workbook = Workbook();
final Worksheet sheet = workbook.worksheets[0];
// Creating new style.
final CellStyle cellStyle1 = CellStyle(workbook);
cellStyle1.name = 'Style1';
cellStyle1.backColor = '#FF5050';
cellStyle1.fontName = 'Aldhabi';
cellStyle1.fontColor = '#138939';
cellStyle1.fontSize = 16;
cellStyle1.bold = true;
cellStyle1.italic = true;
cellStyle1.underline = true;
cellStyle1.rotation = 120;
cellStyle1.hAlign = HAlignType.center;
cellStyle1.vAlign = VAlignType.bottom;
cellStyle1.indent = 1;
cellStyle1.borders.all.lineStyle = LineStyle.double;
cellStyle1.borders.all.color = '#FFFF66';
cellStyle1.numberFormat = '#,##0.00';
cellStyle1.wrapText = true;
 // Add style to collections.
workbook.styles.addStyle(cellStyle1);
final Range range1 = sheet.getRangeByIndex(1, 1);
range1.text = 'Hello';
range1.cellStyle = cellStyle1;
final List<int> bytes = workbook.saveAsStream();
File('CellStyle.xlsx').writeAsBytes(bytes);
workbook.dispose();

Implementation

void addStyle(CellStyle style) {
  int index = 0;
  index = workbook.styles._styles.length;
  style.index = index;
  _dictStyles[style.name] = style;
  _styles.add(style);
}