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",
"rows": [
{
"cells": [
{ "value": "Bold" },
{
"value": "Styled",
"style": {
"font": {
"bold": true,
"italic": true,
"size": 14,
"color": { "rgb": "FFFF0000" },
"font": "Arial"
}
}
}
]
}
]
}
]
}
{
cells: [
{ value: "Bold", style: { font: { bold: true } } },
{ value: "Styled", style: { font: { bold: true, italic: true, size: 14, color: { rgb: "FFFF0000" }, font: "Arial" } } },
],
}
#Fill Styles
{
"worksheets": [
{
"name": "Sheet1",
"rows": [
{
"cells": [
{
"value": "Yellow",
"style": { "fill": { "foregroundColor": { "rgb": "FFFFFF00" } } }
},
{ "value": "Blue", "style": { "fill": { "foregroundColor": { "rgb": "FF4472C4" } } } }
]
}
]
}
]
}
{
cells: [
{ value: "Yellow", style: { fill: { foregroundColor: { rgb: "FFFFFF00" } } } },
{ value: "Blue", style: { fill: { foregroundColor: { rgb: "FF4472C4" } } } },
],
}
#Border Styles
{
"worksheets": [
{
"name": "Sheet1",
"rows": [
{
"cells": [
{
"value": "Bordered",
"style": {
"border": {
"top": { "style": "thin", "color": { "rgb": "FF000000" } },
"bottom": { "style": "thin", "color": { "rgb": "FF000000" } },
"left": { "style": "thin", "color": { "rgb": "FF000000" } },
"right": { "style": "thin", "color": { "rgb": "FF000000" } }
}
}
}
]
}
]
}
]
}
{
value: "Bordered",
style: {
border: {
top: { style: "thin", color: { rgb: "FF000000" } },
bottom: { style: "thin", color: { rgb: "FF000000" } },
left: { style: "thin", color: { rgb: "FF000000" } },
right: { style: "thin", color: { rgb: "FF000000" } },
},
},
}
Border styles: thin, medium, thick, dotted, dashed, double, hair, mediumDashed, dashDot, mediumDashDot, dashDotDot, mediumDashDotDot, slantDashDot, none.
#Alignment
{
"worksheets": [
{
"name": "Sheet1",
"rows": [
{
"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",
"rows": [
{
"cells": [
{
"value": "Name",
"style": {
"font": { "bold": true, "color": { "rgb": "FFFFFFFF" } },
"fill": { "foregroundColor": { "rgb": "FF4472C4" } },
"alignment": { "horizontal": "center" }
}
},
{
"value": "Score",
"style": {
"font": { "bold": true, "color": { "rgb": "FFFFFFFF" } },
"fill": { "foregroundColor": { "rgb": "FF4472C4" } },
"alignment": { "horizontal": "center" }
}
}
]
},
{ "cells": [{ "value": "Alice" }, { "value": 95 }] }
]
}
]
}
const headerStyle = {
font: { bold: true, color: { rgb: "FFFFFFFF" } },
fill: { foregroundColor: { rgb: "FF4472C4" } },
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 | ColorOptions | Spreadsheet color (CT_Color): rgb ARGB hex, theme, tint, indexed or auto |
font | string | Font family name |
#Border Options Reference
| Option | Type | Description |
|---|---|---|
style | string | thin, medium, thick, dotted, dashed, etc. |
color | ColorOptions | CT_Color (rgb ARGB / theme / tint / indexed / auto) |
#Alignment Options Reference
| Option | Type | Description |
|---|---|---|
horizontal | string | general, left, center, right, fill, justify, centerContinuous, distributed |
vertical | string | top, center, bottom, justify, distributed |
wrapText | boolean | Wrap text within cell |
textRotation | number | Text rotation in degrees |
indent | number | Indent level |