Styles and Layout
Witan supports workbook styling and worksheet layout operations used by Excel's visible grid: fills, fonts, borders, alignment, number formats, rich text, row heights, column widths, hidden rows and columns, outline metadata, and autofit.
Use this page for direct formatting and layout changes. For rule-driven formatting, see Conditional Formatting.
Cell Styles
Use setStyle on a cell or range:
witan xlsx exec report.xlsx --save --stdin <<'WITAN'
await xlsx.setStyle(wb, "Summary!A1:D1", {
fill: { color: "#1F4E78" },
font: { color: "#FFFFFF", bold: true },
alignment: { horizontal: "center", vertical: "center" },
border: {
bottom: { style: "thin", color: "#D9EAF7" }
}
})
WITAN
Use getStyle to inspect a cell's resolved style model:
const style = await xlsx.getStyle(wb, "Summary!A1")
Style payloads support:
| Style area | Fields |
|---|---|
| Fill | Solid color, pattern fill, pattern color, and gradient fill |
| Font | Name, size, color, bold, italic, strike, underline, and vertical alignment |
| Alignment | Horizontal/vertical alignment, rotation, wrap text, shrink-to-fit, indent, reading order, and auto-indent |
| Border | Top, bottom, left, right, and diagonal borders with style and color |
| Number format | Excel number format strings |
| Protection | Locked and formula-hidden flags |
| Rich text | Text runs with per-run font styling |
Pass null for a style area to clear that area.
Number Formats
Set Excel number formats directly with numberFormat. The same Excel-compatible formatter is used for workbook display text, rendering, lint format analysis, and chart labels that link to source-cell formats.
await xlsx.setStyle(wb, "Summary!B2:B20", {
numberFormat: "$#,##0.00;[Red]($#,##0.00);-"
})
Witan supports the major Excel number-format constructs:
| Area | Support |
|---|---|
| General and built-ins | General plus Excel built-in format IDs, including accounting built-ins |
| Numeric placeholders | 0, #, and ? placeholders, fixed and optional decimals, grouping separators, comma scaling, literals, escaped characters, _ spacing, and * repeat-fill directives |
| Percent | % scaling and percent metadata |
| Currency and accounting | Currency symbols, accounting patterns, and currency identity tags such as [$USD-409] |
| Dates and times | Year/month/day formats, localized month and weekday names, hour/minute/second formats, AM/PM, subseconds, and Excel 1900-date compatibility |
| Elapsed time | [h], [m], and [s] elapsed-time formats |
| Fractions | Proper, improper, and mixed fractions with 0, #, and ? placeholders |
| Scientific notation | Exponent formats such as 0.00E+00 and related E+ / E- patterns |
| Sections and conditions | Positive/negative/zero/text sections, comparison conditions such as [<0], and dedicated zero sections |
| Text formats | @ text placeholders with literal text |
| Color directives | Color sections such as [Red] for rendered color and format metadata |
| Locale tags | [$-...] locale tags for separators and localized month/day names across a broad locale table |
Examples:
await xlsx.setStyle(wb, "Summary!C2:C20", {
numberFormat: '[$-de]d mmmm yyyy'
})
await xlsx.setStyle(wb, "Summary!D2:D20", {
numberFormat: "[h]:mm:ss"
})
await xlsx.setStyle(wb, "Summary!E2:E20", {
numberFormat: '#,##0.0,,"M"'
})
Number formats change displayed text and rendered semantics; they do not change the underlying cell value. Format patterns follow Excel's 255-character number-format limit when parsed for display.
Rich Text
Use richText when one cell needs mixed font runs:
await xlsx.setStyle(wb, "Summary!A1", {
richText: [
{ text: "Revenue ", style: { bold: true } },
{ text: "Q4", style: { italic: true, color: "#666666" } }
]
})
Row And Column Layout
Set row and column dimensions, visibility, outline levels, and collapsed state:
await xlsx.setRowProperties(wb, "Summary", 1, 1, {
height: 24,
hidden: false
})
await xlsx.setColumnProperties(wb, "Summary", "B", "D", {
width: 14,
outlineLevel: 1
})
Use Workbook Structure for row and column insertion/deletion.
Autofit
Like Excel, Witan automatically fits affected row heights when setCells edits cell content.
Use autoFitColumns and autoFitRows after writing content:
const columns = await xlsx.autoFitColumns(wb, "Summary", ["A", "B", "C"], {
minWidth: 8,
maxWidth: 32,
padding: 1
})
const rows = await xlsx.autoFitRows(wb, "Summary", [1, 2, 3], {
minHeight: 15,
maxHeight: 80
})
Autofit uses workbook fonts, number formats, wrapping, merged cells, text rotation, rich text, hidden rows/columns, and other display properties to estimate Excel-style visible dimensions.
Rendering And Linting
Witan Render draws the supported style and layout model, including font fallback, fills, borders, alignment, rich text, row/column geometry, hidden rows and columns, merged cells, and number-format display text.
Witan Lint uses the same layout information for display diagnostics such as clipped text, text overflow, and overlapping objects.
See xlsx API for style signatures and Writing and structure for row, column, and autofit signatures.