add method

Style add(
  1. String styleName
)

Add styles to the collection

final Workbook workbook = Workbook();
final Worksheet sheet = workbook.worksheets[0];
// Creating Global cell style.
final Style style = workbook.styles.add('style');
style.backColor = '#37D8E9';
style.fontName = 'Times  Roman';
style.fontSize = 20;
style.fontColor = '#C67878';
style.italic = true;
style.bold = true;
style.underline = true;
style.wrapText = true;
style.hAlign = HAlignType.left;
style.vAlign = VAlignType.bottom;
style.rotation = 90;
style.borders.all.lineStyle = LineStyle.thick;
style.borders.all.color = '#9954CC';
style.numberFormat = '_(\$* #,##0_)';
final Range range1 = sheet.getRangeByIndex(3, 4);
range1.number = 10;
range1.cellStyle = style;
final List<int> bytes = workbook.saveAsStream();
File('CellStyle.xlsx').writeAsBytes(bytes);
workbook.dispose();

Implementation

Style add(String styleName) {
  if (styleName == '') {
    throw Exception('name should not be empty');
  }

  if (_dictStyles.containsKey(styleName) &&
      !workbook.styles._defaultStyleNames.contains(styleName)) {
    throw Exception('Name of style must be unique.');
  }

  final Style style = CellStyle(_book, styleName);
  (style as CellStyle).isGlobalStyle = true;
  int index = 0;
  if (workbook.styles._defaultStyleNames.contains(style.name)) {
    _initializeStyleCollections(style.name, style);
    style._builtinId = workbook.styles._defaultStyleNames.indexOf(style.name);
  }
  index = workbook.styles._styles.length;
  style.index = index;
  _dictStyles[styleName] = style;
  _styles.add(style);
  return style;
}