Tables
Use the table property to add structured tabular data to slides.
Basic Table
{
"slides": [
{
"children": [
{
"table": {
"x": "1.3cm",
"y": "1.3cm",
"width": "21.2cm",
"height": "7.9cm",
"rows": [
{ "cells": [{ "text": "Name" }, { "text": "Role" }, { "text": "Department" }] },
{ "cells": [{ "text": "Alice" }, { "text": "Engineer" }, { "text": "Dev" }] },
{ "cells": [{ "text": "Bob" }, { "text": "Designer" }, { "text": "UX" }] }
]
}
}
]
}
]
}
import { generatePresentation } from "@office-open/pptx";
generatePresentation({
slides: [
{
children: [
{
table: {
x: "1.3cm",
y: "1.3cm",
width: "21.2cm",
height: "7.9cm",
rows: [
{ cells: [{ text: "Name" }, { text: "Role" }, { text: "Department" }] },
{ cells: [{ text: "Alice" }, { text: "Engineer" }, { text: "Dev" }] },
{ cells: [{ text: "Bob" }, { text: "Designer" }, { text: "UX" }] },
],
},
},
],
},
],
});
Cell Formatting
Use children with paragraph objects for formatted cell content:
{
"slides": [
{
"children": [
{
"table": {
"x": "1.3cm",
"y": "1.3cm",
"width": "21.2cm",
"height": "7.9cm",
"rows": [
{
"cells": [
{
"fill": "2E74B5",
"verticalAlign": "center",
"children": [
{
"children": [
{ "text": "Header", "bold": true, "size": 14, "fill": "FFFFFF" }
]
}
]
}
]
},
{
"cells": [
{
"fill": "F2F2F2",
"children": [
{
"children": [{ "text": "Data cell", "size": 12 }]
}
]
}
]
}
]
}
}
]
}
]
}
import { generatePresentation } from "@office-open/pptx";
generatePresentation({
slides: [
{
children: [
{
table: {
x: "1.3cm",
y: "1.3cm",
width: "21.2cm",
height: "7.9cm",
rows: [
{
cells: [
{
fill: "2E74B5",
verticalAlign: "center",
children: [
{
children: [{ text: "Header", bold: true, size: 14, fill: "FFFFFF" }],
},
],
},
],
},
{
cells: [
{
fill: "F2F2F2",
children: [
{
children: [{ text: "Data cell", size: 12 }],
},
],
},
],
},
],
},
},
],
},
],
});
Rich Cell Content
Cells can contain multiple paragraphs:
{
cells: [
{
children: [
{ children: [{ text: "Bold title", bold: true, size: 14 }] },
{ children: [{ text: "Description", size: 11, fill: "666666" }] },
],
},
],
}
Merged Cells
Merge cells using rowSpan and columnSpan:
{
"slides": [
{
"children": [
{
"table": {
"x": "1.3cm",
"y": "1.3cm",
"width": "21.2cm",
"height": "9.3cm",
"rows": [
{
"cells": [{ "text": "Category", "rowSpan": 2 }, { "text": "Q1" }, { "text": "Q2" }]
},
{
"cells": [{ "text": "100" }, { "text": "120" }]
},
{
"cells": [
{ "text": "Products", "rowSpan": 2 },
{ "text": "200" },
{ "text": "250" }
]
},
{ "cells": [{ "text": "210" }, { "text": "270" }] }
]
}
}
]
}
]
}
import { generatePresentation } from "@office-open/pptx";
generatePresentation({
slides: [
{
children: [
{
table: {
x: "1.3cm",
y: "1.3cm",
width: "21.2cm",
height: "9.3cm",
rows: [
{
cells: [{ text: "Category", rowSpan: 2 }, { text: "Q1" }, { text: "Q2" }],
},
{
cells: [
// First cell merged from row above
{ text: "100" },
{ text: "120" },
],
},
{
cells: [{ text: "Products", rowSpan: 2 }, { text: "200" }, { text: "250" }],
},
{
cells: [{ text: "210" }, { text: "270" }],
},
],
},
},
],
},
],
});
Column Widths
Control column widths explicitly:
{
"slides": [
{
"children": [
{
"table": {
"x": "1.3cm",
"y": "1.3cm",
"width": "21.2cm",
"columnWidths": [200, 300, 300],
"rows": [
{ "cells": [{ "text": "ID" }, { "text": "Name" }, { "text": "Email" }] },
{ "cells": [{ "text": "1" }, { "text": "Alice" }, { "text": "alice@example.com" }] }
]
}
}
]
}
]
}
import { generatePresentation } from "@office-open/pptx";
generatePresentation({
slides: [
{
children: [
{
table: {
x: "1.3cm",
y: "1.3cm",
width: "21.2cm",
columnWidths: [200, 300, 300],
rows: [
{ cells: [{ text: "ID" }, { text: "Name" }, { text: "Email" }] },
{ cells: [{ text: "1" }, { text: "Alice" }, { text: "alice@example.com" }] },
],
},
},
],
},
],
});
Borders
Customize cell borders:
{
text: "Cell with border",
borders: {
top: { width: 2, color: "2E74B5" },
bottom: { width: 2, color: "2E74B5" },
left: { width: 2, color: "2E74B5" },
right: { width: 2, color: "2E74B5" },
},
}
Table-level borders distribute to edge cells:
{
"slides": [
{
"children": [
{
"table": {
"x": "1.3cm",
"y": "1.3cm",
"width": "21.2cm",
"rows": [
{ "cells": [{ "text": "A" }, { "text": "B" }] },
{ "cells": [{ "text": "C" }, { "text": "D" }] }
],
"borders": {
"top": { "width": 2, "color": "2E74B5" },
"bottom": { "width": 2, "color": "2E74B5" },
"left": { "width": 2, "color": "2E74B5" },
"right": { "width": 2, "color": "2E74B5" }
}
}
}
]
}
]
}
import { generatePresentation } from "@office-open/pptx";
generatePresentation({
slides: [
{
children: [
{
table: {
x: "1.3cm",
y: "1.3cm",
width: "21.2cm",
rows: [
{ cells: [{ text: "A" }, { text: "B" }] },
{ cells: [{ text: "C" }, { text: "D" }] },
],
borders: {
top: { width: 2, color: "2E74B5" },
bottom: { width: 2, color: "2E74B5" },
left: { width: 2, color: "2E74B5" },
right: { width: 2, color: "2E74B5" },
},
},
},
],
},
],
});
Table Options
| Property | Type | Description |
| -------------- | ------------------- | ------------------------ | ------------------- |
| x | number | UniversalMeasure | Horizontal position |
| y | number | UniversalMeasure | Vertical position |
| width | number | UniversalMeasure | Frame width |
| height | number | UniversalMeasure | Frame height |
| rows | TableRowOptions[] | Table rows |
| columnWidths | number[] | Width for each column |
| borders | object | Table-level edge borders |
| firstRow | boolean | Bold first row styling |
| bandRow | boolean | Alternating row banding |
Cell Options
| Property | Type | Description |
|---|---|---|
text | string | Plain text content |
children | ParagraphOptions[] | Paragraph objects |
fill | FillOptions | Cell background fill |
borders | object | Cell borders |
columnSpan | number | Horizontal merge count |
rowSpan | number | Vertical merge count |
verticalAlign | "top" | "center" | "bottom" | "justify" | "distribute" | Vertical text alignment |
margins | { top, bottom, left, right } | Cell padding |
Border Options
| Property | Type | Description |
| ----------- | --------------------------------------------------- | ----------------- | ------------ |
| width | number | UniversalMeasure | Border width |
| color | string | Hex color |
| dashStyle | "solid" \| "dash" \| "dashDot" \| "lgDash" \| ... | Dash style |