Table, TableRow, And TableCell¶
featherdoc::Table edits Word table structure and table-level metadata.
featherdoc::TableRow edits row metadata and visible cell text.
featherdoc::TableCell edits cell content, size, merge state, borders,
shading, margins, and paragraphs.
Indexing, Units, And Return Semantics¶
Table APIs use zero-based indexes. row_index addresses visible table rows,
cell_index addresses visible cells in that row, and grid_column addresses
the resolved Word grid column after spans are considered. Width, indent, margin,
and spacing values use twips. Methods returning std::optional<T> return an
empty value when the target cannot be resolved; methods returning bool report
whether the table XML was changed.
Common Tasks¶
Use these entry points for common table workflows:
Create a table: call
Document::append_table(...)orTemplatePart::append_table(...).Locate cells safely: use
find_row(...),find_cell(...), orfind_cell_by_grid_column(...)and check the returnedstd::optional.Fill a rectangular data region: use
set_row_texts(...),set_rows_texts(...), orset_cell_block_texts(...).Make layout deterministic: set
table_layout_mode::fixed,set_width_twips(...), andset_column_width_twips(...).Format row or cell details: use
TableRowfor repeat-header and height metadata, andTableCellfor merge, shading, margins, borders, and paragraph content.
Success And Failure Semantics¶
Return shape |
Success |
Failure or no-op |
|---|---|---|
|
Contains a row handle for an existing visible row. |
Empty when the row index is outside the current table. |
|
Contains a cell handle after visible-cell or grid-column resolution. |
Empty when the row, visible cell, or resolved grid column is unavailable. |
|
|
|
|
Returned handles point at inserted or appended table nodes. |
Treat the returned handle as the editing entry for the new row or cell. |
|
Contains existing table, row, or cell metadata. |
Empty means the requested metadata is not present or cannot be resolved. |
Short Example¶
auto table = doc.body_template().append_table(2, 2);
table.set_row_texts(0, {"Name", "Status"});
table.set_row_texts(1, {"Ada", "Approved"});
if (auto cell = table.find_cell(1, 1)) {
cell->set_fill_color("D9EAF7");
}
Typed Signature Guide¶
Signature |
Parameters |
Return semantics |
|---|---|---|
|
|
Empty when the row does not exist. |
|
|
Empty when the row or cell cannot be resolved. |
|
|
Empty when the grid column maps to no visible cell. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Table Structure And Lookup¶
Method |
Returns |
Purpose |
|---|---|---|
|
|
Advance the table iterator to the next table. |
|
|
Check whether the table iterator can advance. |
|
|
Access the row iterator for this table. |
|
|
Look up a row by zero-based row index. |
|
|
Look up a visible cell by row and visible cell index. |
|
|
Look up a cell by resolved grid column. |
|
|
Replace visible cell text. |
|
|
Replace cell text by resolved grid column. |
|
|
Replace visible cell text for one row. |
|
|
Replace a rectangular row block. |
|
|
Replace a rectangular cell block from a row/cell origin. |
|
|
Append a row with the requested number of cells. |
Table Layout, Style, And Borders¶
Method |
Returns |
Purpose |
|---|---|---|
|
|
Read table width. |
|
|
Set table width in twips. |
|
|
Read one grid column width. |
|
|
Set one grid column width. |
|
|
Read autofit or fixed layout mode. |
|
|
Set table layout mode. |
|
|
Read table alignment. |
|
|
Set table alignment. |
|
|
Read table indent. |
|
|
Set table indent. |
|
|
Read spacing between table cells. |
|
|
Set spacing between table cells. |
|
|
Read floating table position metadata. |
|
|
Set floating table position metadata. |
|
|
Read table style id. |
|
|
Set table style id. |
|
|
Read table style look flags. |
|
|
Set table style look flags. |
|
|
Read one table border edge. |
|
|
Set one table border edge. |
TableRow¶
Method |
Returns |
Purpose |
|---|---|---|
|
|
Access the cell iterator for this row. |
|
|
Look up a visible cell by index. |
|
|
Look up a cell by resolved grid column. |
|
|
Read row height. |
|
|
Read the row height rule. |
|
|
Set row height and rule. |
|
|
Check whether the row is prevented from splitting across pages. |
|
|
Toggle row split prevention. |
|
|
Check whether this row repeats as a header row. |
|
|
Toggle repeated header row metadata. |
|
|
Replace all visible cell text in this row. |
|
|
Insert a row next to the current row. |
|
|
Append a cell to this row. |
TableCell¶
Method |
Returns |
Purpose |
|---|---|---|
|
|
Access paragraphs inside the cell. |
|
|
Read flattened cell text. |
|
|
Replace cell text. |
|
|
Insert a cell next to the current cell. |
|
|
Read cell width. |
|
|
Set cell width in twips. |
|
|
Read horizontal span. |
|
|
Read resolved grid column index. |
|
|
Horizontally merge with cells to the right. |
|
|
Vertically merge with cells below. |
|
|
Remove horizontal or vertical merge state. |
|
|
Read vertical merge state. |
|
|
Read vertical span. |
|
|
Read cell vertical alignment. |
|
|
Set cell vertical alignment. |
|
|
Read text direction. |
|
|
Set text direction. |
|
|
Read cell shading color. |
|
|
Set cell shading color. |
|
|
Read one cell margin. |
|
|
Set one cell margin. |
|
|
Read one cell border edge. |
|
|
Set one cell border edge. |
Example¶
auto table = doc.body_template().append_table(2, 3);
table.set_layout_mode(featherdoc::table_layout_mode::fixed);
table.set_width_twips(9000);
table.set_row_texts(0, {"SKU", "Name", "Quantity"});
auto header = table.find_row(0);
if (header) {
header->set_repeats_header();
}
auto sku = table.find_cell(0, 0);
if (sku) {
sku->set_fill_color("D9EAF7");
sku->set_vertical_alignment(featherdoc::cell_vertical_alignment::center);
}