Skip to content
Office Open

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

JSON
{
  "worksheets": [
    {
      "name": "Sheet1",
      "rows": [
        {
          "cells": [
            { "value": "Bold" },
            {
              "value": "Styled",
              "style": {
                "font": {
                  "bold": true,
                  "italic": true,
                  "size": 14,
                  "color": { "rgb": "FFFF0000" },
                  "font": "Arial"
                }
              }
            }
          ]
        }
      ]
    }
  ]
}

#Fill Styles

JSON
{
  "worksheets": [
    {
      "name": "Sheet1",
      "rows": [
        {
          "cells": [
            {
              "value": "Yellow",
              "style": { "fill": { "foregroundColor": { "rgb": "FFFFFF00" } } }
            },
            { "value": "Blue", "style": { "fill": { "foregroundColor": { "rgb": "FF4472C4" } } } }
          ]
        }
      ]
    }
  ]
}

#Border Styles

JSON
{
  "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" } }
                }
              }
            }
          ]
        }
      ]
    }
  ]
}

Border styles: thin, medium, thick, dotted, dashed, double, hair, mediumDashed, dashDot, mediumDashDot, dashDotDot, mediumDashDotDot, slantDashDot, none.

#Alignment

JSON
{
  "worksheets": [
    {
      "name": "Sheet1",
      "rows": [
        {
          "cells": [
            {
              "value": "Centered",
              "style": {
                "alignment": { "horizontal": "center", "vertical": "center", "wrapText": true }
              }
            }
          ]
        }
      ]
    }
  ]
}

#Combining Styles

Styles are combined and deduplicated automatically:

JSON
{
  "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 }] }
      ]
    }
  ]
}

Repeated use of the same style object reuses the same cellXf index — no unnecessary duplication in the output file.

#Font Options Reference

OptionTypeDescription
boldbooleanBold formatting
italicbooleanItalic formatting
underlinebooleanUnderline
strikebooleanStrikethrough
sizenumberFont size in points
colorColorOptionsSpreadsheet color (CT_Color): rgb ARGB hex, theme, tint, indexed or auto
fontstringFont family name

#Border Options Reference

OptionTypeDescription
stylestringthin, medium, thick, dotted, dashed, etc.
colorColorOptionsCT_Color (rgb ARGB / theme / tint / indexed / auto)

#Alignment Options Reference

OptionTypeDescription
horizontalstringgeneral, left, center, right, fill, justify, centerContinuous, distributed
verticalstringtop, center, bottom, justify, distributed
wrapTextbooleanWrap text within cell
textRotationnumberText rotation in degrees
indentnumberIndent level