XLSX
Styles
Fonts, fills, borders, alignment, and number formats
XLSX uses an index-based style system. When you apply a style to a cell, the library automatically deduplicates and registers it.
Font Styles
{
"worksheets": [
{
"name": "Sheet1",
"children": [
{
"cells": [
{ "value": "Bold" },
{
"value": "Styled",
"style": {
"font": {
"bold": true,
"italic": true,
"size": 14,
"color": "FF0000",
"fontName": "Arial"
}
}
}
]
}
]
}
]
}
{
cells: [
{ value: "Bold", style: { font: { bold: true } } },
{ value: "Styled", style: { font: { bold: true, italic: true, size: 14, color: "FF0000", fontName: "Arial" } } },
],
}
Fill Styles
{
"worksheets": [
{
"name": "Sheet1",
"children": [
{
"cells": [
{ "value": "Yellow", "style": { "fill": { "color": "FFFF00" } } },
{ "value": "Blue", "style": { "fill": { "color": "4472C4" } } }
]
}
]
}
]
}
{
cells: [
{ value: "Yellow", style: { fill: { color: "FFFF00" } } },
{ value: "Blue", style: { fill: { color: "4472C4" } } },
],
}
Border Styles
{
"worksheets": [
{
"name": "Sheet1",
"children": [
{
"cells": [
{
"value": "Bordered",
"style": {
"border": {
"top": { "style": "thin", "color": "000000" },
"bottom": { "style": "thin", "color": "000000" },
"left": { "style": "thin", "color": "000000" },
"right": { "style": "thin", "color": "000000" }
}
}
}
]
}
]
}
]
}
{
value: "Bordered",
style: {
border: {
top: { style: "thin", color: "000000" },
bottom: { style: "thin", color: "000000" },
left: { style: "thin", color: "000000" },
right: { style: "thin", color: "000000" },
},
},
}
Border styles: thin, medium, thick, dotted, dashed, double, hair, none.
Alignment
{
"worksheets": [
{
"name": "Sheet1",
"children": [
{
"cells": [
{
"value": "Centered",
"style": {
"alignment": { "horizontal": "center", "vertical": "center", "wrapText": true }
}
}
]
}
]
}
]
}
{
value: "Centered",
style: {
alignment: { horizontal: "center", vertical: "center", wrapText: true },
},
}
Combining Styles
Styles are combined and deduplicated automatically:
{
"worksheets": [
{
"name": "Sheet1",
"children": [
{
"cells": [
{
"value": "Name",
"style": {
"font": { "bold": true, "color": "FFFFFF" },
"fill": { "color": "4472C4" },
"alignment": { "horizontal": "center" }
}
},
{
"value": "Score",
"style": {
"font": { "bold": true, "color": "FFFFFF" },
"fill": { "color": "4472C4" },
"alignment": { "horizontal": "center" }
}
}
]
},
{ "cells": [{ "value": "Alice" }, { "value": 95 }] }
]
}
]
}
const headerStyle = {
font: { bold: true, color: "FFFFFF" },
fill: { color: "4472C4" },
alignment: { horizontal: "center" },
};
{
cells: [
{ value: "Name", style: headerStyle },
{ value: "Score", style: headerStyle },
],
}
Repeated use of the same style object reuses the same cellXf index — no unnecessary duplication in the output file.
Font Options Reference
| Option | Type | Description |
|---|---|---|
bold | boolean | Bold formatting |
italic | boolean | Italic formatting |
underline | boolean | Underline |
strike | boolean | Strikethrough |
size | number | Font size in points |
color | string | Hex color |
fontName | string | Font family name |
Border Options Reference
| Option | Type | Description |
|---|---|---|
style | string | thin, medium, thick, dotted, dashed, etc. |
color | string | Hex color |
Alignment Options Reference
| Option | Type | Description |
|---|---|---|
horizontal | string | left, center, right, fill, justify |
vertical | string | top, center, bottom |
wrapText | boolean | Wrap text within cell |
textRotation | number | Text rotation in degrees |
indent | number | Indent level |