49 Commits
Author SHA1 Message Date
Dolan a75d7a3e94 docs: say a table goes next to paragraphs, never in a paragraph's children (#3859) 2026-10-28 20:10:10 +00:00
Dolan 19da2bf8b7 docs: explain that a table row of exact height never splits across pages (#3852) 2026-10-27 16:16:02 +00:00
DolanandClaude Opus 5.5 82b1dc132e fix: write a table lined up inline down the page in line with the text, as Word floats one with w:tblpYSpec="inline" (#331) (#3838)
A table with `float: { relativeVerticalPosition: RelativeVerticalPosition.INLINE }` was written with
`w:tblpYSpec="inline"` in its `w:tblpPr`. Word has no floating table in line with the text: it places such a table
at the top of the paragraph after it, with text beside it, and saves it back with the `inline` dropped
(`<w:tblpPr w:vertAnchor="text" w:tblpXSpec="center"/>`). So the table never stayed in line with the text, as the
option promises.

Such a table is now written in line with the text, as Word writes a table with no text wrapping: without
`w:tblpPr` or `w:tblOverlap`. Its `relativeHorizontalPosition` of left, center or right becomes its `w:jc`, as Word's
row alignment reports those of a floating table, unless the table has an `alignment` of its own. Word reads the
issue's table as not wrapping text and centered, and lays it out centered between the paragraphs before and after it.

The tables docs now show `alignment`, and say what `INLINE` writes.


Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 13:10:40 +00:00
DolanandClaude Opus 5.5 5050cc0bba feat: draw diagonal lines across table cells, to split a header cell (#3121) (#3817)
A cell's borders take `diagonalDown` and `diagonalUp`, Word's "Diagonal
Down Border" and "Diagonal Up Border", written as `w:tl2br` and `w:tr2bl`
after the sides, in CT_TcBorders' order. A diagonal down border splits a
header cell into a label for the columns, above the line, and one for the
rows, below it.

Checked in Word for Mac: a cell merged with columnSpan or rowSpan gets one
diagonal across the whole merged cell. docx already copies a merged cell's
borders into the cells it adds below, and Word draws the same either way,
as it keeps the diagonal on the cells below when it saves.


Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 03:18:59 +01:00
Dolan f0a176ec0b fix: don't write a table row with no cells, which Word can't open (#2724) (#3799) 2026-10-19 13:02:13 +01:00
Dolan 8f0a8532e4 fix: cells added below a rowSpan cell take its formatting and paragraph alignment (#1219) (#3784) 2026-10-17 16:39:04 +01:00
DolanandClaude Opus 5.5 1fb5e15729 fix: Size rows below a merged cell with its margins, and show how to merge cells by hand (#3766)
Word makes a row below a cell merged down rows as tall as the merged
cell's margins in it, as word-merged-cell-margins.docx shows: with
rowSpan, the cells docx adds take the table's margins, so the rows below
are as tall as the table's margins above and below and a line.
docx/layout left those cells out of the row's height, and now counts
their margins.

The table docs now show merging cells by hand with verticalMerge, which
gives the merged cell's part in each row settings of its own, such as no
margins, which keeps the rows below to a line. That is what #668 asked
for besides keeping rows together.


Claude-Session: https://claude.ai/code/session_0121RHRfmgN8jDksNAdAWKnK

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 23:27:08 +01:00
Dolan 8b8f5b1083 fix: Keep merged rows together with TableRow keepNext, and indent the numbering demo's numbers (#3765) 2026-10-15 15:26:10 +01:00
DolanandClaude Opus 5.5 7f6de64474 fix: Let a table's style give its borders (#3760)
A table always wrote `w:tblBorders` with a thin single line on every side
it wasn't given, which covered the borders of its table style. A table
with a `style` now writes only the sides `borders` gives, and none
without `borders`, so the style's borders show. Tables without a style
keep their thin single borders.

Fixes #1497

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 02:43:59 +01:00
Dolan 7826217f8d docs: fix mistakes found while answering discussions (#3748) 2026-10-12 13:42:45 +01:00
DolanandClaude Opus 5.5 b53aca8a3d docs: explain that only header rows at the top of a table repeat (#3745)
Word repeats a table's first row and the rows straight after it that set
tableHeader, and ignores tableHeader on rows further down. Document this,
and show how to give each part of a long table its own repeating header
by making each part a table of its own.

Closes #2425

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 13:36:50 +01:00
DolanandClaude Opus 5.5 8a79f10344 feat(table): write cells' widths from columnWidths and Word's default cell margins, so tables look and lay out the same in Word (#3594)
* feat(table): write each cell's width from columnWidths, so Word keeps them

Word lays a table out from its cells' widths (w:tcW), and sizes the
columns of cells without one to their text, whatever the grid
(w:tblGrid) says. docx wrote columnWidths only to the grid, so in Word
they did nothing unless every cell was given the same width again, as
#517, #352, #1099 and #561 found. A table saved as a PDF from Word 16 for
Mac showed it: "Entry" shrank to its text and gave its room to the other
columns.

Each cell without a width of its own now gets the width of the columns it
spans, the cells added for rowSpan included. When the table's width is
wider than its columns add up to, the cells' widths are scaled up to fill
it, as Word and LibreOffice lay the columns out, so columnWidths given as
proportions of a 100% table, as some issues suggest, keep them. The grid
is written as given.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NijyutGmb3bNR3dNRWJken

* feat(styles): write Normal Table, the default table style, with Word's cell margins

docx wrote no table style, and without one Word gives cells no margins,
so their text touched the borders: in a PDF saved from Word, the text of
each cell started half a point inside its border. LibreOffice gives them
the 0.075 inches (108 twips) on the left and right that Word gives the
tables it makes, so the same table had narrower lines of text there.

docx now writes Normal Table as Word writes it in its own documents, the
default table style with those margins, so tables look the same in Word
as tables made in it, and as in LibreOffice. A Normal Table in
externalStyles takes its place, and margins given to a table or cell
still win.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NijyutGmb3bNR3dNRWJken

* fix(layout): lay cells out at their own widths, with the margins of their table's style

The layout took each cell's width from the grid and gave every cell
margins of 5.4 points, as LibreOffice does. Word goes by a cell's own
width in twips when it has one, and takes cell margins from the table's
style, or the default table style, and gives none without either.

Cells are now laid out at their own width in twips when they have one,
and their margins come from the table's style and the styles it is based
on, or the default table style when it has none, then the table's own.
With docx's Normal Table, that is the 5.4 points it was, and the table
demos' headings stay on LibreOffice's pages. The docs say to give tables
columnWidths for their page numbers to be right, as Word sizes the columns
of a table without widths to their text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NijyutGmb3bNR3dNRWJken

* docs(table): don't suggest columnWidths as proportions for readers that go by the grid

The warning about readers that lay tables out from the grid alone ended by
suggesting columnWidths as proportions of a table with a width. Only the
cells' widths are scaled to the table's width, and the grid is written as
given, so those readers still take [20, 80] as 20 and 80 twips. The
warning asks for real twips again, and the paragraph on scaling says it
applies to the readers that go by the cells' widths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NijyutGmb3bNR3dNRWJken

* fix(layout): stop at a table whose rows give a column different widths

With cells laid out at their own widths, two rows could give the same
column different widths, such as a one-column table whose first cell is
1000 twips wide and whose second is 3000. Word settles the column's width
in a way the layout doesn't follow yet, so at least one row's lines were
broken at the wrong width. The layout now stops at such a table and
leaves the page numbers after it blank, as it does for other things it
can't lay out. Widths a point apart, from rounding, still count as equal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NijyutGmb3bNR3dNRWJken

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 17:57:02 +01:00
DolanandClaude Opus 5.5 c169dd1a83 feat: live examples in the docs, which run, draw the document next to the code, and can be edited and downloaded (#3556)
* feat: live examples in the docs, which run, draw the document next to the code, and can be edited and downloaded

The docs' code examples were plain snippets, often fragments that couldn't run. A code block marked ```ts live is now
an example readers can see and change: the page runs it with docx, draws the document it makes next to the code with
docx-preview, and offers the .docx to download. Clicking the code opens an editor (Monaco) that knows docx's types,
the pages are drawn again as the code changes, and View closes the editor. Split, Code and Preview show the code and
the pages side by side, or one of them. The demos a page includes are live too.

Every example in the docs that builds or patches a document is now live: 443 of them, each a whole file with its
imports, so it runs as written. Code about other things, such as installing, bundlers or servers, stays plain.

Running them showed docs that were wrong, fixed here:
- Landscape: docx swaps a landscape page's width and height itself, so the docs' swapped sizes made a tall page
  marked as landscape
- Comments: `comments.children` takes plain objects, not `new Comment(...)`
- Custom properties are text only
- APIs that no longer exist: MathText, Row, `.then` on Packer.toStream, patchDocument(buffer, ...),
  createParagraph().heading1(), a border's `value`, TextRun's `.break()`
- The templates and patcher examples read files that aren't in the repository. They now patch the templates in
  demo/assets, or make their own

`npm run build.docs` copies docx's browser builds into docs/live-examples/lib, so the docs use the docx they
describe, and the Pages workflow runs it. The folder is gitignored, and cspell and ESLint skip it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ

* docs: the bullet examples draw a bullet, and the patcher's usage writes the patched document

"ὠ" is U+1F60, a Greek omega, since \u takes four hex digits, so the two live bullet examples on
the numbering page drew it as each item's bullet. They use "•" now. The patcher's usage example
now awaits patchDocument and writes the document it makes, as the example after it does.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 13:00:29 +01:00
DolanandClaude Opus 5.5 e0ff13ee3d chore: organise the demos into a folder for each topic (#3552)
* chore: organise the demos into a folder for each topic

The demos were one flat list of 124 numbered files, which made it hard to
find the one you wanted. Each is now in a folder for its topic, such as
demo/tables/basic-table.ts, with a name that says what it shows instead of
a number.

npm run demo lists every demo and narrows the list as you type. It also
takes a demo's path or name, a topic, or search words.

The demos' images moved to demo/assets/images, as images is now a topic.
The docs' links, the Demos workflow, the shape render script and its
reference images use the new paths and names.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ

* fix: list only a topic's own demos, and drop stale output file names

npm run demo text also offered the text-boxes demos and others with
"text" in their name, so a topic now searches for "text/". Three demos
logged their old numbered file name after writing My Document.docx.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 01:40:45 +01:00
Dolan 764d5423f3 feat: theme colours for text, underlines, borders and shading (#3537) 2026-09-24 23:34:57 +01:00
99517e0c1c fix(table): emit numeric pct widths in fiftieths of a percent (#3476)
* fix(table): emit numeric pct widths in fiftieths of a percent

createTableWidthElement wrote a numeric PERCENTAGE size as a "50%" string.
Both that string and the fiftieths-of-a-percent integer (50% = 2500) are
valid under ST_MeasurementOrPercent, but Word writes the integer, and
stricter consumers — Google Docs and Apple Pages/QuickLook/Mail — misread
the string form and collapse table columns to one character.

Emit the integer (Math.round(size * 50)) for numeric pct sizes to match
Word's output. Callers who want the literal percent string can still pass a
Percentage (e.g. "50%"), which is left untouched. Adds table-width.spec.ts
and updates the two specs that asserted the old string output.

* fix(table): derive tblGrid from table and cell widths so tables render in Google Docs and Pages

Writing pct widths as fiftieths of a percent (previous commit) is correct but
does not fix #1457 on its own. Google Docs, Apple Pages, QuickLook and other
consumers lay a table out from w:tblGrid alone and ignore w:tblW / w:tcW
percentages, while docx wrote a placeholder grid of 100 twips per column
whenever columnWidths was omitted. Every percentage-width table therefore
collapsed to one character per column in those readers (#1457, #349, #216,
#3015). Word recomputes the layout from the preferred widths, which is why it
was never affected.

When columnWidths is omitted the grid is now derived, in twips, the way Word
writes it after laying the table out:

- percentages resolve against the text width of the section the table is in
  (page width minus margins and gutter, per column in multi-column sections),
  or against the parent cell for nested tables, at serialization time
- dxa and universal-measure widths are used as they are
- columns without a width share what is left of the table width equally
- column spans and the continuation cells inserted for rowSpan are honoured

Explicit columnWidths are written unchanged. Tables formatted without a
document (bare Formatter, patcher) resolve against the default A4 page, and
formatting a table more than once is idempotent.

New: SectionProperties.AvailableTextWidth, Body.getSectionPropertiesFor,
universalMeasureToTwips, Table.ColumnWidths and Table.getCellWidth. Adds a
demo, documents columnWidths, and applies the review nits on table-width.spec.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* test: use a cspell-friendly malformed measure in the universalMeasureToTwips spec

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

---------

Co-authored-by: Dolan Miu <dolan_miu@hotmail.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-23 17:29:48 +01:00
DolanandDolan Miu 74bf48f8c1 feat: Migrate to new component authoring (#3332)
* feat: Migrate to new component authoring

# Conflicts:
#	src/file/table-of-contents/table-of-contents.ts

# Conflicts:
#	src/file/content-types/content-types.ts
#	src/file/paragraph/properties.ts
#	src/file/table/table-properties/table-properties.ts

# Conflicts:
#	src/file/document/body/section-properties/section-properties.ts
#	src/file/paragraph/run/run.ts
#	src/file/table-of-contents/table-of-contents.ts
#	src/file/table/grid.ts
#	src/file/table/table-cell/table-cell-properties.ts
#	src/file/table/table.ts

* Clarify public api

* Add docs

* Fix tests and linting

* Fix readonly array

* Fix spelling

* Update ToC docs

* Update WPS to use BuilderElement

* Migrate components to use Builder element

Add ESLint rules

* Comment out the template demos

* Ignore demo 90 until we fix schema validation

* Disable demo validation

* Disable doc

* Disable validation for now

---------

Co-authored-by: Dolan Miu <>
2026-02-22 21:23:05 +00:00
NicoandDolan da20f94a28 feat: Add table look support for conditional table formatting (#3317)
* Added the table look parameter to new Table class to enable controlling various conditional formatting table properties (first row, first column etc)

* Improve documentation

---------

Co-authored-by: Dolan <dolan_miu@hotmail.com>
2026-02-16 01:45:14 +00:00
Dolan 3539c06e92 docs: Improve inline docs and docs website (#3353)
* docs: Improve inline docs and docs website

* Fix lint

* Fix spelling
2026-02-14 03:54:25 +00:00
Firat Ciftci 7d1129900f Fix: separate vertical alignment enums for ITableCellOptions and ISectionPropertiesOptions (#3079)
* fix: separate vertical alignment enums for table and section properties

- Introduced `VerticalAlignTable` for table-cell vertical alignment with valid values: `top`, `center`, and `bottom`.
- Added `VerticalAlignSection` for section properties, extending `VerticalAlignTable` with an additional value `both`.
- Marked the original `VerticalAlign` as deprecated for backward compatibility, directing users to the new enums.
- Updated type definitions for better clarity on valid vertical alignments.

* refactor: update vertical alignment imports and types for section and table properties

- Renamed `VerticalAlign` to `VerticalAlignSection` in section properties and `VerticalAlignTable` in table-cell properties for clarity.
- Updated type definitions to reflect the new enum names, ensuring better organization and understanding of vertical alignment options.
- Adjusted related test cases to utilize the new imports and types.

* refactor: update demos to use new enums for table and section properties for vertical alignment
2025-05-02 19:58:10 +01:00
Lê Anh Vũ 28029f4c1c chore[tables.md]: replace semicolon to commas (#2708) 2024-10-10 00:14:09 +01:00
James Montalvo 111c80d049 docs: fix height.value not height.height 2022-01-24 10:28:57 -06:00
Dolan 9efee181ba Update tables.md 2021-08-27 10:12:08 +01:00
Tom Hunkapiller 097c6a5962 use hexColorValue in borders and underlines 2021-05-24 08:42:34 +03:00
Tom Hunkapiller dd6d1bc039 Consolidate TableWidth and TableCellMargins types; add Table indent (#954) 2021-05-24 05:39:26 +03:00
Tom Hunkapiller 496fcb55fa unify Shading; breaking change: Paragraph/Run shading option key type changed to val, and shadow alias removed 2021-05-24 05:39:26 +03:00
Tom Hunkapiller d527013451 Update outdated docs to show current usage 2021-05-18 17:16:10 +03:00
Ismail Magomedov abc7c8dc72 Fixed typos in usage documentation 2021-03-25 19:21:27 +03:00
Dolan 3299c557a0 Make .addSection fully declarative 2021-03-19 20:53:56 +00:00
Dolan a3febae8a3 Inline single use interfaces 2021-03-15 00:11:39 +00:00
Dolan Miu 95556e57df Write documentation on vidi visual 2021-03-04 02:08:09 +00:00
Dolan ea5f9a48ab Fix cantSplit documentation 2020-10-24 20:24:10 +01:00
Matt Walsh af0bf5ced5 Fix row height option 2020-09-11 21:10:10 -05:00
Dolan d2dded860d Fix example links 2019-09-30 20:58:18 +01:00
Dolan bd888219fc Amend table documentation 2019-09-26 02:03:17 +01:00
Dolan Miu 2842619196 Update table documentation 2019-09-25 01:59:30 +01:00
Dolan Miu d2f82052b4 Improve documentation 2019-09-19 22:49:09 +01:00
Dolan 4ac55a787e Fix includes 2019-08-21 00:53:49 +01:00
Dolan 535f2d75b0 Fix embed links in documentation 2019-08-20 22:23:14 +01:00
Dolan e2574ec23b Turn methods into "add()" 2019-06-25 23:17:56 +01:00
Dolan c97d15cb9f Remove create table helper function 2019-06-25 01:21:28 +01:00
fmuscolino 9c89c1ab59 Update docs 2019-04-12 13:46:05 +02:00
Dolan 5aa878b901 Fix invalid link 2019-03-06 02:12:41 +00:00
Dolan b99d1fc129 correctly use include 2019-03-06 00:18:00 +00:00
Dolan 6c772b956c Add examples to table documentation 2019-03-05 23:15:50 +00:00
Dolan 9d09ff3518 Update documentation 2019-03-05 21:57:31 +00:00
Dolan 04ea2b2dc9 Add footer tests and improve table documentation 2019-01-03 02:11:04 +00:00
Dolan Miu b9465b2a20 Add more changes to table API and documentation 2018-12-31 01:55:15 +00:00
Dolan Miu ab07f2ecbe Change table methods and document it 2018-12-29 01:57:20 +00:00