Skip to main content
page.table builds a table element. You define the columns up front, add rows of cells, then add the table to the page. Each cell is plain string content or an object with content and a style.

Table options

interface CreateTableOptions {
  columns: number | number[];
  style?: StyleProperties;
  position?: { x: number; y: number };
  width?: number;
  border_color?: ColorLike;
  border_width?: number;
  cell_padding?: number;
  header_style?: StyleProperties;
  cell_style?: StyleProperties;
  z_index?: number;
}
columns
number | number[]
required
An equal count, or an array of absolute widths in points where 0 means auto width. For example columns: [180, 0, 100] sets two fixed columns with one auto column between them.
border_color
ColorLike
The color of the cell borders.
border_width
number
The thickness of the cell borders.
cell_padding
number
The padding inside every cell.
header_style
StyleProperties
The style applied to the first row, which is treated as the header.
cell_style
StyleProperties
The default style applied to body cells.

Adding rows

Build rows with table.add_row. The first row added receives header_style.
table.add_row(cells: Array<string | TableCellInput>): this

interface TableCellInput {
  content: string;
  style?: StyleProperties;
}

A complete table

const table = page.table({
  columns: [180, 0, 100],
  border_width: 0.5,
  cell_padding: 8,
  header_style: { background_color: "#ebf4ff" },
  width: page.get_content_width(),
});
table.add_row(["Name", "Role", "Status"]);
table.add_row(["Alice Nguyen", "Lead Engineer", "Active"]);
table.add_row([
  { content: "Bob Chen", style: { color: "#718096" } },
  "Designer",
  "Active",
]);
page.add(table);
This low level table takes plain string cell content. For rich inline cells with bold text, links, and inline formulas, use the Doc API table.

Layout

Arrange tables and other elements with containers.

Themes

Centralize colors used in cell and header styles.