Marks a class as a sheet class and configures its sheet: title, preset, shared style sheets, template, layout options and the header and body slots.
Mandatory on every class passed to SheetData. A class without it violates rule V-01.
Not inherited. Every exported class carries its own @ExcelSheet. Superclasses that only contribute columns do not need it.
Can take its configuration from a template. With template, the class takes from a sheet template every attribute it does not set itself (section 6.1.13).
Every attribute is optional. With all defaults, the sheet has no title, a frozen header, auto-sized columns, no auto-filter, no frame, and no style other than the application default preset (which is NONE unless configured).
Summary of the attributes:
Attribute
Type
Default
title
String
"" (no title)
titleStyle
String
"" (no style)
preset
TablePreset
INHERIT (template, then application default)
accentColor
String
"" (template, then application default)
styleSheets
Class<?>[]
{}
freezeHeader
Toggle
INHERIT (template, then frozen)
autoFilter
Toggle
INHERIT (template, then no auto-filter)
autoSizeColumns
Toggle
INHERIT (template, then auto-sized)
outerBorder
Border
INHERIT (template, then no frame)
outerBorderColor
String
"" (template, then automatic colour)
header
HeaderStyles
@HeaderStyles (no slot set)
body
BodyStyles
@BodyStyles (no slot set)
template
Class<?>
ExcelSheetTemplate.None.class (no template)
When the class references a template, “template, then …” means that an attribute left unset on the class is taken from the template, and the default applies only when the template leaves it unset too.
Adds a row above the header. The text is written in the first column and the cell is merged across all the columns of the table. Every cell of the title row receives the title style.
Interactions
The title has no role: header and body slots never apply to it. It is outside the outer frame. It is frozen together with the header when the header is frozen. It is excluded from the auto-filter. Its style is the preset title layer (if any) followed by titleStyle. With one column, there is nothing to merge: the title stays in the single cell.
Validation
None on the text itself. titleStyle requires a title (V-15).
the name of a style available to the class: declared on the class, on one of its styleSheets or on one of the style sheets of its template
Effect
Applied to every cell of the title row, after the preset title layer.
Interactions
Allowed only when title is set. When empty, the title style of the template applies, if any. A title style set by the template is ignored, without error, when the class has no title.
Validation
V-15 when title is empty; V-06 when the name does not exist.
INHERIT uses the preset of the template, if the class references one, otherwise the application default preset (SheetsmithDefaults.preset, property sheetsmith.preset, NONE unless configured). NONE applies no preset regardless of the application default. LIGHT, MEDIUM and DARK apply the corresponding preset.
Interactions
The preset is the lowest level of the title, header and body cascades: every declared style overrides it attribute by attribute. The colours of the preset come from the effective accent colour. A class that references a template cannot set a preset: the template chooses it.
"", meaning the accent colour of the template, if it sets one, otherwise the application default accent colour (#4472C4 unless configured)
Allowed values
#RRGGBB in upper or lower case, or the name of an Apache POI IndexedColors constant (see section 8.2)
Effect
The colour from which the preset derives every tone. Hexadecimal values are normalised to upper case.
Interactions
Has an effect only when the effective preset is not NONE. Wins over the accent colour of the template: the same template can be used in different colours.
The named styles of the listed style sheets become available to the slots of this class, as if declared on it.
Interactions
A style declared on the sheet class with the same name as a style of a style sheet replaces it entirely (no merge). Listing the same style sheet twice has no effect. The order of the list has no effect. With a template, the styles of these style sheets win over the styles with the same name of the style sheets of the template, and a style sheet listed both here and in the template is not a conflict.
Validation
V-09 for a listed class without @ExcelStyleSheet (its styles are then ignored, so references to them also report V-06). V-08 when two listed style sheets declare the same name.
Toggle.INHERIT: the choice of the template, if any, otherwise frozen
Effect
TRUE freezes the rows up to and including the header, so they stay visible while scrolling. When the sheet has a title, the title row is frozen too. No column is frozen. FALSE freezes nothing.
Toggle.INHERIT: the choice of the template, if any, otherwise no auto-filter
Effect
TRUE adds an Excel auto-filter covering all the columns, from the header row to the last data row. With no data rows, it covers the header row only. The title is never included. FALSE adds none.
Toggle.INHERIT: the choice of the template, if any, otherwise automatic sizing
Effect
TRUE sizes every column without an explicit width to its content. FALSE leaves those columns at the width chosen by the spreadsheet application.
Interactions
Columns with @ExcelColumn.width are never auto-sized. Wins over the template.
Validation
None.
How sizing works:
Sizing is delegated to Apache POI, which measures the text with the fonts installed on the machine (Java AWT).
On servers or containers without installed fonts, or without the AWT native libraries, that measurement can fail. sheetsmith then falls back to an estimate: the length in characters of the longest value of the column as Excel displays it (with its format applied, so dates and numbers are measured as shown), header included and title excluded, plus 2 characters, capped at 255.
The time spent sizing grows with the number of rows. For large sheets, disable it and set explicit widths: see section 14.3.
A known behaviour concerns a sheet with a title and a single column: see section 14.4.
@ExcelSheet(autoSizeColumns=Toggle.FALSE)
publicrecord LargeRow(
@ExcelColumn(header="Id", order=10, width=10) long id,
Draws a frame around the header and the data rows with a single attribute: along the top of the header row, the left side of the first column, the right side of the last column, and the bottom of the last data row (or of the header row when there are no data rows). The title is never framed.
Interactions
Any value other than INHERIT, NONE included, is applied to those edges: NONE therefore removes, on the edges, borders that a preset or a base style would draw. In the cascade, the frame sits above the preset, the base slots and the odd and even slots, and below the first and last row and column slots, the column slots and the column header style: a style at those levels that sets a border side overrides the frame on that side.
Validation
None.
Edges set by the frame, per cell:
Cell
Sides set by the frame
Header, every column
top
Header, first column
left
Header, last column
right
Header, every column, only when there are no data rows
"", meaning the frame colour of the template, if any, otherwise the automatic colour (usually black)
Allowed values
#RRGGBB or an IndexedColors name
Effect
Colour of the frame edges. Hexadecimal values are normalised to upper case.
Interactions
Has an effect only when a frame is drawn. Each of outerBorder and outerBorderColor is taken from the template separately: a frame colour set by the template stays when the class changes the accent colour.
The named styles of the header row: see section 6.7. Each slot set here wins over the same slot of the template; the slots left empty keep the style named by the template.
The named styles of the data rows at table level: see section 6.8. Each slot set here wins over the same slot of the template; the slots left empty keep the style named by the template.
ExcelSheetTemplate.None.class, meaning no template
Allowed values
a class annotated with @ExcelSheetTemplate
Effect
The class takes from the template every attribute it does not set itself: preset, accent colour, style sheets, title style, layout options, frame and slots. The styles of the style sheets of the template become available to the class, as the weakest level.
Interactions
Every attribute set on the sheet class wins over the template, except preset, which must stay INHERIT. Slots are taken one by one. The precise rules are in section 10.10. A template cannot reference another template.
Validation
V-21 when the class is not a template; V-22 when preset is set too. The template itself is validated with rules V-06, V-08, V-09, V-13 and V-23 to V-25, and its errors name the template class.