Styling topic
Everything that controls how a cell looks: CellStyle gathers font, colour,
fill, borders, and alignment; ExcelColor names a colour; Border a cell edge;
and GradientFill a gradient. Number formatting lives in its own category
(see NumFormat).
Apply a style when writing a cell, or set it on an existing cell:
sheet.updateCell(
CellIndex.indexByString('A1'),
TextCellValue('Header'),
cellStyle: CellStyle(
bold: true,
italic: true,
fontSize: 14,
fontColorHex: ExcelColor.white,
backgroundColorHex: ExcelColor.fromHexString('#21A366'),
horizontalAlign: HorizontalAlign.Center,
verticalAlign: VerticalAlign.Center,
textWrapping: TextWrapping.WrapText,
),
);
Colours can be a literal hex, or a theme/indexed reference that round-trips as such:
ExcelColor.fromHexString('#2962FF'); // literal RGB
ExcelColor.theme(ThemeColor.accent1, tint: -0.2); // darker accent 1
ExcelColor.indexed(10); // legacy palette index
Borders are per edge; each takes a BorderStyle and an optional colour:
sheet.cell(CellIndex.indexByString('A1')).cellStyle = CellStyle(
leftBorder: Border(borderStyle: BorderStyle.Thin),
rightBorder: Border(borderStyle: BorderStyle.Thin),
topBorder: Border(borderStyle: BorderStyle.Medium),
bottomBorder:
Border(borderStyle: BorderStyle.Medium, borderColorHex: ExcelColor.red),
);
Fills can be solid (backgroundColorHex), a pattern
(CellStyle.fillPattern with FillPatternType), or a gradient:
sheet.cell(CellIndex.indexByString('A2')).cellStyle = CellStyle(
gradientFill: GradientFill.linear(degree: 90, stops: [
GradientStop(0, ExcelColor.fromHexString('#2962FF')),
GradientStop(1, ExcelColor.white),
]),
);
Classes
- Border Styling
- Represents a border on one side of a cell.
- CellStyle Styling
- Styling class for cells.
- ExcelColor Styling
- Represents a color value for use in cell styling.
- GradientFill Styling
- A gradient cell fill, a smooth blend between two or more colour stops.
- GradientStop Styling
-
One colour stop of a GradientFill: color placed at position along the
gradient (
0.0= start,1.0= end). A gradient needs at least two stops.
Enums
- BorderStyle Styling
- Available border line styles in Excel.
- ColorType Styling
- Color type category.
- FillPatternType Styling
-
Cell fill pattern.
solidfills the cell with a single colour (the cell style'sbackgroundColor); the other patterns draw a hatch/shade using thebackgroundColoras the pattern colour over an optionalfillBackgroundColor. - FontFamily Styling
- Available font families.
- FontScheme Styling
- Font scheme setting.
- GradientType Styling
- The geometry of a GradientFill.
- HorizontalAlign Styling
- Horizontal alignment of cell content.
- TextWrapping Styling
- Text wrapping mode for cells.
- ThemeColor Styling
-
The twelve document-theme color slots, in the order Excel indexes them in
styles.xml(theme="N"). Use with ExcelColor.theme to author a color that follows the workbook's theme. - Underline Styling
- Text underline style.
- VerticalAlign Styling
- Vertical alignment of cell content.