XLSX
Cells & Data
Cell data types, row structure, and basic data entry
Cells are the building blocks of worksheets. Each cell holds a value and optional style.
Cell Values
{
"worksheets": [
{
"name": "Sheet1",
"children": [{ "cells": [{ "value": "Hello" }, { "value": 42 }, { "value": true }] }]
}
]
}
import { Workbook, Packer } from "@office-open/xlsx";
const wb = new Workbook({
worksheets: [
{
name: "Sheet1",
children: [{ cells: [{ value: "Hello" }, { value: 42 }, { value: true }] }],
},
],
});
Supported value types:
| Type | Example | Description |
|---|---|---|
string | { value: "Hello" } | Shared string reference |
number | { value: 42 } | Inline numeric value |
boolean | { value: true } | Boolean value (0/1) |
Date | { value: new Date("2024-01-01") } | Serial number |
null | { value: null } | Empty cell (skipped) |
Styled Cells
Apply styles directly to cells:
{
"worksheets": [
{
"name": "Sheet1",
"children": [
{
"cells": [
{
"value": "Header",
"style": { "font": { "bold": true }, "fill": { "color": "4472C4" } }
},
{ "value": 100, "style": { "numFmt": "#,##0" } }
]
}
]
}
]
}
{
cells: [
{ value: "Header", style: { font: { bold: true }, fill: { color: "4472C4" } } },
{ value: 100, style: { numFmt: "#,##0" } },
],
}
See Styles for the full list of style options.
Row Heights
Set custom row heights:
{
"worksheets": [
{
"name": "Sheet1",
"children": [{ "cells": [{ "value": "Tall row" }], "height": 30 }]
}
]
}
{
cells: [{ value: "Tall row" }],
height: 30, // Height in points
}
Hidden Rows
{
"worksheets": [
{
"name": "Sheet1",
"children": [
{ "cells": [{ "value": "Visible" }] },
{ "cells": [{ "value": "Hidden" }], "hidden": true }
]
}
]
}
{
cells: [{ value: "Visible" }],
},
{
cells: [{ value: "Hidden" }],
hidden: true,
},
Number Formats
Common number format patterns:
| Pattern | Input | Display |
|---|---|---|
#,##0 | 1234 | 1,234 |
#,##0.00 | 1234.5 | 1,234.50 |
0% | 0.85 | 85% |
yyyy-mm-dd | Date | 2024-01-01 |
Cell Options Reference
| Option | Type | Description |
|---|---|---|
value | string | number | boolean | Date | null | Cell value |
style | StyleOptions | Cell style (see Styles) |
Row Options Reference
| Option | Type | Description |
|---|---|---|
cells | CellOptions[] | Array of cells |
height | number | Row height in points |
hidden | boolean | Hide the row |