429 Commits
Author SHA1 Message Date
DolanandClaude Opus 5.5 2243d74c22 fix: write one w:pStyle for a paragraph with both heading and style (#3940)
A paragraph with both `heading` and `style` wrote a w:pStyle for each, and
CT_PPrBase has one, so the Open XML SDK validator rejected the document.
Word applies the last of the two, `style`, so `style` now takes the place
of `heading`, and Word shows the paragraph as it did. The layout module and
the table of contents' heading entries read the first w:pStyle, the
heading, and now read the style Word shows.

The ListParagraph that a bullet or numbered paragraph gets without a style
of its own goes in the same if/else.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 17:36:05 +08:00
yschoi9733andClaude Opus 5.5 893ca85c8b fix: write one w:pBdr for a paragraph with both border and thematicBreak (#3935)
A paragraph with both options got a w:pBdr from each, and CT_PPrBase has
one, so the Open XML SDK validator rejects the document. The same went for
paragraph styles, and for htmlToContent with an <hr> in a <div> with a
border.

The thematic break's line is now written in the w:pBdr of border, in place
of its bottom, as Word reads the two elements: ThematicBreak extends Border
and takes the paragraph's other borders. The layout module, which read only
the first w:pBdr, now gives the line its room, as Word does.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 16:58:40 +08:00
yschoi9733andClaude Opus 5.5 882c5aedef fix: stop writing a paragraph revision's run inside w:pPrChange (#3928)
A paragraph's revision takes the paragraph's options, run included, and run
was written as w:rPr in the w:pPr of w:pPrChange. That w:pPr is a CT_PPrBase,
which has no rPr, so the Open XML SDK validator rejects the document.

run is kept in IParagraphPropertiesChangeOptions, deprecated, and has no
effect. The earlier formatting of the paragraph mark goes in revision of the
paragraph's own run, which writes w:rPrChange. The change tracking docs now
show that, and the JSDoc of the paragraph's run says it formats the paragraph
mark rather than the paragraph's runs.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 16:58:26 +08:00
DolanandClaude Opus 5.5 5f626c02ba fix(layout): lay out rows that repeat their table's properties, split rows at multiple line spacing and overfull text boxes, as Word does (#3918)
* fix(layout): lay out rows that repeat their table's properties, split rows at multiple line spacing and overfull text boxes, as Word does

estimatePageNumbers stopped at three things report templates have (#3912):

- A row whose w:tblPrEx repeats the table's own w:tblW, w:tblLayout or
  w:tblInd. Properties that are the same as the table's change nothing,
  so only those that differ still stop the layout.
- A cell's line at multiple spacing at the foot of a row that breaks
  across pages, where it fits only without the space below its text.
  word-split-rows-and-boxes.docx shows Word moves it to the next page,
  unlike in the body: 69 probes, with and without borders and above a
  cell's bottom margin, all now on Word's pages.
- An inline VML text box of its own height whose text is taller than
  it. Word cuts the text off and keeps the box's height (OB1 in the same
  probe), so the box is laid out at its own height.

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

* fix(layout): compare a row's table properties with the table's whatever order their attributes are in

XML gives attributes no order, so a row's w:tblPrEx written with
w:type before w:w is the same as the table's w:tblW written the other
way round. The comparison now sorts each element's attributes first,
as a text frame's are compared, rather than stopping the layout there.

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

* fix(layout): put the probe's text box shape type before whichever box ONLY leaves first

The shape type was added to OB1a's box, so a run with ONLY=OB1b wrote a
box referring to a shape type the document didn't declare. It now goes
before the first box in the document, whichever that is. A full run
writes the same document as before.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 04:14:34 +00:00
yschoi9733andClaude Opus 5.5 bc5e98e1a3 feat: add autoSpaceLatinAndEastAsianText for the space beside Latin letters (#3916)
Word can put a small space between Chinese, Japanese or Korean text and
a Latin letter or a digit beside it. autoSpaceEastAsianText controls the
space beside digits (w:autoSpaceDN), and autoSpaceLatinAndEastAsianText
now does the same for Latin letters (w:autoSpaceDE).

Both can be set in paragraph styles, numbering levels and the document
defaults too, and are written after w:overflowPunct and before w:bidi,
the order CT_PPrBase gives them. To keep that order, w:suppressLineNumbers
moves to its place after w:numPr, and w:wordWrap and w:overflowPunct now
come after w:tabs. A test sets an option for each element
ParagraphProperties writes and checks their order against the schema.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 03:31:12 +00:00
Wu Shuwen 6957076145 docs: clarify packer prettify argument values (#3876) 2026-11-01 14:24:24 +00:00
DolanandClaude Opus 5.5 ea6bff070c docs: say a hanging paragraph's left is where the lines after the first start (#3874)
The `left` row in the indentation table ended with "With `hanging`, of
the lines after the first", which has no verb and doesn't say what
`left` does there. It now reads like the TSDoc on `left` in indent.ts.


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

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 14:48:36 +00:00
DolanandClaude Fable 5.1 19087e8b79 fix: name images in the package as Word does, image1.png and so on (#3872)
* fix: name images in the package as Word does, image1.png and so on

Images were written to word/media under a SHA-1 hash of their data,
such as 4bf7547c9322fd2143bd3e8dfa84109d9d3fed14.png. Word for the web
has shown an empty box in place of an image named like that, and shown
it once the file was renamed image1.png as Word names its own, as
https://github.com/dolanmiu/docx/issues/496 reports.

The hash is still the key an image is added to the media under, so an
image used twice is stored once and its placeholders are unchanged, but
the file is written as image1.png, image2.jpg and so on, numbered in the
order images are added. The numbers come from the document's
PackageParts, which an ImagePatch's parts already take theirs from, so
an image never takes a part's name, nor a part an image's, and in
patchDocument new images are numbered after the template's own.

Closes #496
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QzDw6ZwCkrdX4ZsWzeVQNC

* docs: say images are numbered by type, image1.png and image1.jpg

A document's images take their names from PackageParts.takePath,
which numbers by the whole file name, so a PNG and a JPEG are
image1.png and image1.jpg, not image2.jpg as the docs and the Media
comment said. Word for the web shows images named this way, as the
images demo showed, and an ImagePatch's images were already numbered
so. The docs now say that, and a Media without a path taker numbers
its images by type too, so it names them as a document does.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QzDw6ZwCkrdX4ZsWzeVQNC

* test: a document numbers its images by type, in the order they are added

Covers a PNG, a JPEG and a second PNG written through File, which
takePath names image1.png, image1.jpg and image2.png.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QzDw6ZwCkrdX4ZsWzeVQNC

* test: check the relationships to a document's images, numbered by type

The mixed-extension test checked the media files and their bytes, but
not the relationships that point the drawings at them, which is the
XML the names matter in.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QzDw6ZwCkrdX4ZsWzeVQNC

* test: check each of a document's images is written under its own number

Swapping the two PNGs' bytes passed the mixed-extension test, though
its name says images are numbered in the order they are added.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QzDw6ZwCkrdX4ZsWzeVQNC

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-31 14:10:01 +00:00
DolanandClaude Opus 5.5 f6b4a76208 docs: show a full-page background image the header doesn't push the text below (#3871)
* docs: show a full-page background image the header doesn't push the text below

A picture behind every page goes in the header, and the paragraph holding it has a
line's height, so with small margins Word and LibreOffice start the text below it.
A negative top or bottom margin is exact, so document it with an example and a demo.

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

* docs: say a background picture also goes in the first and even headers

With a different first page or different odd and even pages, those pages show
the first or even header, so a picture only in the default one is missing there.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 11:29:00 +00:00
DolanandClaude Opus 5.5 2c4e5b43cb fix: patch placeholders in links, content controls and tracked changes (#3864)
* fix: patch placeholders in links, content controls and tracked changes

patchDocument and patchDetector only read runs that are direct children of
a paragraph, so a placeholder in a link, a content control, text typed with
Track Changes on, a smart tag or a field's result was left as it was, with
no error. Runs in those elements are now read and patched where they are.

Where the content can't go in what holds the placeholder, it goes where
Word can open it: a link is taken out of a tracked insertion (whose piece
after it gets an id of its own) or a link, a plain text content control
given more than text becomes a rich text one, and a content control
showing its placeholder text stops showing it.

Addresses #2679

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

* test: cover every branch of patching runs in links and content controls

CI's coverage fell below 100%: an empty link, a content control without
properties, and runs that stay together when a tracked insertion is split
weren't tested. The name fallbacks in the replacer's lookups could never
be reached, so the lookups take an element's name as it is.

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

* feat: find placeholders with custom delimiters with patchDetector, and say why a placeholder isn't replaced

patchDetector takes placeholderDelimiters, as patchDocument does, so it
finds the same placeholders. Before, it only knew {{ and }}, and found
nothing in a template with <<name>>.

templates.md has a section on a placeholder that isn't replaced: how to
find the patches whose placeholder isn't in the template with
patchDetector, as patchDocument leaves them out without an error, and the
usual reasons, such as a key written with its braces.

Addresses #2679

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

* fix: unbind a content control a patch fills, so Word doesn't put the placeholder back

Word fills a control bound to custom XML or a document property
(w:dataBinding) in from its data when it opens a document. A patched
placeholder in one came back: Word for Mac showed {{name}} from the XML,
though the control held the patch's text. The binding is now removed from
a control a patch's content goes in.

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

* perf: split a tracked change around a link in linear time

The stretches were built by copying the stretch so far for each element,
so a tracked insertion of n runs took n² steps to split. Each stretch is
now sliced from where it starts.

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

* docs: list a placeholder only in alt text among the reasons a patch isn't applied

patchDetector finds placeholders in pictures' and charts' alt text, so
comparing its keys with the patches' doesn't show a text patch for one,
which leaves it as it is. It's now one of the listed reasons, saying so.

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

* fix: don't let a start delimiter before a placeholder hide it from patchDetector

A key ran from the first start delimiter to the next end delimiter, so in
"<<unfinished <<name>>" patchDetector found "unfinished <<name", not
"name", which patchDocument patches. With one-character delimiters such as
< and >, any "<" in the text did this. A key now has no start delimiter in
it. The search from a start delimiter with no end after it also stops at
the next one, rather than going on to the end of the paragraph each time:
120,000 characters of unmatched "<" took 1.4 s, and now take no time.

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

* test: check the link a patch puts in a content control without properties

The test only checked the control's text and its one child, so content
that lost the link would have passed it.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 20:39:09 +00:00
Dolan d08294a09a docs: say Word's dialog shows a hanging paragraph's Left where its first line starts (#3860) 2026-10-29 13:05:58 +00:00
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
DolanandClaude Opus 5.5 027c288640 fix: write a text box of auto height 1in tall, so WPS Office fits it to its text (#3858)
* fix: write a text box of auto height 1in tall, so WPS Office fits it to its text

Since 9.8.0 (#3541) WPS Office draws Textbox, which it showed blank
before (#3171), but it makes a box of auto height too short by its top
and bottom insets, cutting off the text's last line. Word, WPS,
LibreOffice and Pages all fit the box to its text from any definite
height of 8pt or more (mso-fit-shape-to-text is always written), so a
text box without a height, or with "auto", is now written 1in tall.
Word's and LibreOffice's layouts are unchanged; docx-preview, which
doesn't fit the box, draws it 1in tall rather than at its own default.

text-box.md's "Fixed Size" section said a height fixes the box's size,
which none of those applications do, so Sizing now says what height
does.

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

* docs: say a text box needs a style with a width, and that a style's missing height is written 1in

The docs said any text box without a height is written 1 inch tall, but
a text box with no style is written without one. Such a box has no width
either: Word draws it 50pt wide and LibreOffice gives it none, and
writing height:1in on it changes neither, so it stays without a style.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 14:16:24 +00:00
DolanandClaude Opus 5.5 2f82dcb464 docs: explain legal style numbering, for 1.1 under a level in Chinese counting (#3857)
A level's text shows each level's number in that level's format, so
"%1.%2" under a level in Chinese counting is 一.1 (#3425).
isLegalNumberingStyle writes w:isLgl, which makes every number in the
text a decimal number, as Word's Legal style numbering does, but the
docs never mentioned it and its TSDoc only said "legal numbering style
(e.g., 1.1.1)".


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

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 13:58:35 +00:00
DolanandClaude Opus 5.5 1146a21edd docs: show how to put space between images in a paragraph (#3856)
An inline image takes its place in the line like a letter, so images
mapped into one paragraph touch (#3021). Word for Mac ignores
characterSpacing on an image's run, and margins only apply to floating
images, but a space run between them with characterSpacing gives a gap
of a set width. Images one under another take a paragraph each, with
spacing after.


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

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 12:26:22 +00:00
DolanandClaude Opus 5.5 78b04e52c6 docs: give the checkbox options' real type, defaults and what alias does (#3855)
The options table named a SymbolState type that doesn't exist and marked
value as required, though both value and font are optional, defaulting
to Word's own ☒/☐ in MS Gothic. alias writes the content control's
w:alias, which Word for Mac shows as a title tab above the checkbox, so
it's described as that rather than as an accessibility label.


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

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 02:40:45 +00:00
Dolan 5b1ecfeceb docs: show how to style a list's numbers and bullets (#3853) 2026-10-27 17:01:00 +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
Dolan 922f7f5fd9 docs: say Packer.toBuffer rejects in a browser, which has no Buffer, rather than giving a Uint8Array (#3845) 2026-10-26 16:00:47 +00:00
Dolan ab3a09807c fix: emit toStream's failure to zip on its error event, as in a browser without Buffer, not as an unhandled rejection (#3844) 2026-10-26 15:30:15 +00:00
DolanandClaude Opus 5.5 66eaf1c12e feat: read the theme of a Word document or template with readTheme, and theme fonts for other scripts (#878) (#3839)
* feat: Word's themes, colors and fonts, and the theme of a Word document or template, from docx/theme (#878)

docx/theme is a new optional entry, so the main bundle stays as it is:

- Themes: the 29 themes of Word's Design > Themes gallery, each with its
  name, colors, and fonts for headings and body text, as IThemeOptions.
- ColorSchemes and FontSchemes: the 24 color sets and 26 font sets of the
  Design > Colors and Design > Fonts galleries, to mix with a theme as
  Word's Design tab does.
- readTheme: the theme of a .docx, .docm, .dotx, .dotm, .pptx, .xlsx or
  .thmx file, or of a theme1.xml, or colors or fonts Word saved on their
  own. Styles taken from a template with externalStyles then keep the
  template's theme fonts and colors (#878).

The presets are generated from Word for Mac's own theme files by
scripts/generate-word-themes.ts, which reads each one with readTheme.

In docx, a theme font can now have a font for each script (scripts, by
ISO 15924 code), in place of Office's for those scripts, so Word's themes
keep their own fonts for Japanese, Chinese and other scripts. docx also
exports parseXml and unzipFiles, which it already had, so docx/theme
reads files without bundling a second XML parser and unzipper.

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

* refactor: read a template's theme with readTheme from docx, sharing the patcher's theme reader, without docx/theme (#878)

- Word's themes, colour sets and font sets (Themes, ColorSchemes, FontSchemes), the
  script that generated them and the docx/theme entry are dropped. #878 asks only for
  the theme of the template a document's styles come from.
- readTheme moves into the core and is exported from docx. The patcher reads the
  colours of a template's theme with the same code, so parseXml and unzipFiles stay
  internal.
- The paths of a package's parts and its relationships' targets (relationshipsPathOf,
  resolveTarget and the others) move from the patcher to src/util/package-paths.ts,
  so the theme reader in src/file can use them.

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

* fix: read a theme in UTF-16, and inflate only a package's relationships and its theme in readTheme

- A theme, or the XML of one, that starts with UTF-16's byte order mark is read as
  UTF-16, little or big endian, as XML may be written.
- readTheme inflates a package's relationships, and then only the theme they refer to,
  so a large or damaged document, presentation or workbook part doesn't take memory or
  stop it.

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

* fix: find a theme whose relationship's target is in another case than its part, in readTheme and the patcher

The Open Packaging Conventions compare part names without regard to case, so a
relationship's target such as "Theme/THEME1.xml" names word/theme/theme1.xml.
readTheme threw that the file has no theme, and patchDocument used Office's colours.
isSamePart, in src/util/package-paths.ts, compares them as drawing-patch already finds
a relationship's target.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 23:02:10 +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 9239334f73 docs: pipe Packer.toStream's stream straight away in the quickstart (#3835)
The quickstart called `.then` on `Packer.toStream`'s result, but it returns the stream itself, not a promise, so the
example threw "then is not a function". The Packers page already uses the stream directly.


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

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 22:28:42 +01:00
Dolan ba1e9ddea9 fix: show Word's Update Table on a table of contents, by putting it in Word's Table of Contents gallery (#2598) (#3833) 2026-10-24 14:35:24 +01:00
DolanandClaude Opus 5.5 b26d269153 feat: make a new paragraph with other options from a paragraph, with Paragraph's with() (#3330) (#3831)
paragraph.with({ indent }) makes a new paragraph with the paragraph's options and those given, which replace its
own, such as to lay out the paragraphs a parser made, without casting to reach their children. The paragraph is
left as it is. paragraph.options gives the options it was made with, so an option can be extended rather than
replaced.


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

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 01:00:44 +01:00
DolanandClaude Opus 5.5 2f8c8c7711 feat: patch placeholders with spaces inside their delimiters, such as {{ name }}, with trimPlaceholders (#3112) (#3830)
patchDocument's trimPlaceholders takes the spaces inside the delimiters out of the placeholders of the patches given,
even when Word splits them across runs, before patching: in the text, the fields of TABLE_ROWS patches, and the alt
text of drawings. patchDetector's trimPlaceholders gives their keys without the spaces. Both default to false.


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

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 01:00:36 +01:00
DolanandClaude Opus 5.5 414b476dde fix: give a drawing whose alt text has no name an empty name, which the XML requires (#3829)
An ImageRun, ChartRun or shape whose altText was only a description, as JavaScript allows, wrote wp:docPr without
its required name attribute. The name now defaults to empty, as it does for a drawing without alt text, and is
optional in DocPropertiesOptions, so alt text can be just a description.


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

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 01:00:30 +01:00
Dolan 72951b75f7 feat: replace the image of a picture in a template, keeping its look, with ImagePatch (#3072) (#3828) 2026-10-23 22:02:17 +01:00
DolanandClaude Opus 5.5 eadca504e2 fix: define the TOC 1 to TOC 9 styles, so LibreOffice keeps the levels of a table of contents indented (#3819) (#3821)
* fix: define the TOC 1 to TOC 9 styles, so LibreOffice keeps the levels of a table of contents indented (#3819)

Since 9.9.0 a table of contents is written with its entries, in the styles
TOC1 to TOC9, which docx never defined. Opening it, LibreOffice gives its
Contents 2 to Contents 9 styles no indent, so once it updates the index every
level is flush left. 9.8.1 wrote no entries, and LibreOffice kept its own
indents.

docx now writes the styles as Word adds them: based on Normal, 5 points of
space after, and each level indented by Normal's font size more than the one
above (200 twips a level at docx's default 10 points, 220 at 11 points, as
Word for Mac writes them). They are hidden until used, as Word's are. A style
with their id replaces them, as for the other default styles, and so does a
style with their name, such as a template's "toc 1" with a localized id, so
no two styles share a name. The entries no longer need an indent of their
own, which assumed 220 twips.

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

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

* fix: keep the text-and-spacing layout demo's Tab stops heading clear of the bottom of a page

The TOC styles give the table of contents' entries 5 points of space after,
as Word's do, instead of the demo's 8, so the text after the table moved up
33 points. That left the Tab stops heading and its first line ending less
than a point below the bottom margin of page 9. Word and docx/layout fit
them there; LibreOffice, which compare-layout.sh checks against, moves them
to page 10. Word and LibreOffice put every other line of the page in the same
place.

The hanging-indent paragraph above the heading has 80 words instead of 90, a
line fewer, so the heading fits with room to spare. All 368 headings of the
layout demos are now on LibreOffice's page, and Word puts this demo's on the
same pages.

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

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

* fix: keep docx's TOC styles beside a character style with their name

Only a paragraph style named "toc 1" to "toc 9" takes the place of docx's
TOC1 to TOC9. A table of contents' entries are paragraphs, which can't take
a character style, so a character style named "toc 2" left the entries
naming a TOC2 that docx no longer wrote.

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

* fix: indent the TOC styles patchDocument adds by the template's Normal font size

Word indents each level of a table of contents by the size of the Normal
style's font, and a Document does too, but the TOC1 to TOC9 styles that
patchDocument adds to a template without them always stepped by docx's 10
points. They now follow the template's Normal: its own size, or else the
document's default size, such as the 12 points Word for Mac saves.

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

* fix: take the TOC indent from the template's style that patchDocument bases the TOC styles on

The TOC styles patchDocument adds are based on the template's style with
Normal's id, or else on its style named Normal. Their indent now follows
the font size of that same style, so a template whose Normal has another
name still gets its size.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 04:09:31 +01:00
Dolan 799bc7f47e feat: choose what fills the space before a table of contents' page numbers, such as nothing or hyphens (#1696) (#3818) 2026-10-22 10:41:12 +01: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
DolanandClaude Opus 5.5 8a84c5906d fix: write a half-inch default tab stop, so tabs and list text line up in Pages (#2590) (#3816)
docx only wrote w:defaultTabStop when the defaultTabStop option was set. The
spec puts a tab stop every half inch without it, and Word and LibreOffice do,
but Pages 15.1.1 puts none: a tab takes no room, and the tab after a list
number with no hanging indent sends the text to the right margin, one word to
a line. Write 720 unless the option says otherwise, as Word always does.


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

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 02:37:02 +01:00
DolanandClaude Opus 5.5 b87383272d feat: cite sources and list them in a bibliography, in each of Word's styles, from docx/bibliography (#557) (#3814)
* feat(bibliography): the sources part, the styles' framework, and Word's output to test against

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

* feat(bibliography): citations and bibliographies, written as Word's content controls and fields

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

* test(bibliography): keep the empty paragraphs in corpus s's bibliographies of GB7714 and ISO 690

The fixtures' generator left out the paragraphs of corpus s's bibliographies that have
no text, though Word's styles write them: GB7714 and ISO 690 write an entry for a source
with no author, title or other field as an empty paragraph, which Word keeps. Corpora a
to d, Word's own output, keep empty paragraphs between entries too. Each of these
fixtures gets back its 15 empty paragraphs, from the oracle, with the others as they were.

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

* feat(bibliography): write citations and bibliographies in GB7714, as Word does

GB.XSL and ISO690.XSL share nearly every template, so the shared ones go
in one family module, iso-690-family.ts, with the few that differ chosen by
the variant: GB7714 cites a source with no author or year by its tag, and
the two styles put the space after a website's or a report's production
company by different fields.

The module also reads the styles' HTML as Word's import does: spaces
collapse, a space falls between two elements and at the end of a copied
variable before the end of a paragraph, and a copied element with nothing
in it leaves its formatting on for the rest of the bibliography.

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

* feat(bibliography): write citations and bibliographies in ISO 690 by first element and date, as Word does

ISO690.XSL is GB.XSL's twin, so the style is the ISO 690 variant of the
family module: a source with a title but no author or year is cited by
nothing, "()", where GB7714 cites it by its tag.

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

* feat(bibliography): write citations and bibliographies in ISO 690 by numerical reference, as Word does

ISO690Nmerical.XSL cites a source by its number, with the pages or volume
cited after it, such as "(1 p. 5)", and lists the sources in the order the
document cites them. Its entries are the ISO 690 family's, with the main
contributors after the start of a journal article or conference paper.

The style copies each entry from a variable, so Word reads an entry whose
bold has nothing in it, such as one with no author, as bold that stays on
for the rest of the bibliography. An empty xsl:value-of in an element ends
it as usual, so a miscellaneous source with no publication doesn't leave
italics on, as Word's own bibliography of such a source shows; libxslt's
output differs from Word's there.

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

* chore(bibliography): spell the styles' names and Word's abbreviations

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

* test(bibliography): keep the empty entries of corpus s in the GOST and SIST02 fixtures

Word writes an empty paragraph for a source whose entry is empty in a style,
such as a miscellaneous source with no fields in GOST, as Word's style writes an
empty <p> for it. gen-fixtures.mjs dropped every empty paragraph of corpus s, so
the fixtures had fewer entries than the bibliography. They're rewritten from the
oracle with them, and gen-fixtures.mjs needs the same change.

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

* feat(bibliography): write citations and bibliographies in GOST, as Word does

Ports Word's GOST - Name Sort (GostName.XSL) and GOST - Title Sort
(GostTitle.XSL). They share everything but how an entry starts, how the
bibliography is sorted, and a few templates, so both are written from one module,
gost-family.ts: Name Sort starts an entry with its authors in bold and leaves the
people who are those authors out of the rest; Title Sort starts it with its title
in bold, sorts by title, then the main author's names, counts an organization as a
book section's author, and writes an interview's responsibilities only when one
of the first three isn't empty.

The ports follow the templates where they do what they don't look like they do:
_MaxAuthor is read without a $, so every author is listed up to three; a role is
written only when one of its people has a last name; a location with neither a
city nor a publisher is the source's distributor; and an entry of nothing but
spaces is left empty, with no dot.

Their output matches Word's for corpora a to d and the oracle's for corpus s, and
the oracle's for 8 seeds of 300 random sources each.

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

* test(bibliography): end SIST02's corpus s entries without a space, as Word does

Word's SIST02 style, run with libxslt, ends an entry that ends with a bold or
italic element with a line break, which the oracle reads as a space. Word for
Mac shows none: corpus b has "<b>MoraLuz</b> <i>Bread.</i>" and
"<i>Untitled Notes.</i>", with nothing after them. Corpus s's expected
bibliography is regenerated with the oracle reading no space at the end of a
SIST02 paragraph, which changes 14 entries such as "<b>—.</b> ".

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

* feat(bibliography): write citations and bibliographies in SIST02, as Word does

Word's SIST02 style (SIST02.XSL), with its own full-width punctuation and
empty spaces, its name patterns, and Word's reading of its HTML: a space
between two bold or italic elements that follow each other, even an empty
one, and none at the end of an entry. Its quirks are kept, such as "ed."
after any number of editors, "Vol. 5..", "[Cited: ]" for a date accessed
with only a day, and "—." for an article whose title is the one before's.

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

* test(bibliography): keep the empty paragraphs of corpus s's APA bibliography

Word's APA style writes a paragraph for each source, empty for a source it
has nothing to write for, such as a case with no title, number, court or date.
The fixtures' generator left out empty paragraphs, so corpus s's expected
bibliography was two entries short of what the style writes.

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

* feat(bibliography): write citations and bibliographies in APA, as Word does

Word's APASixthEditionOfficeOnline.xsl, written in TypeScript: citations such
as "(Baker, 2010)", with the title when another source has the same first
author and initials when another first author has the same last name, and
the bibliography sorted by author, with a hanging indent.

It follows the XSL, including its quirks: the editors of a conference's
proceedings are always "Ed.", a work of art's date has no space after it
without an artist, and Word reads a space after an entry that ends in
italics, where MSXML writes a line break at the end of the copy of the
entry. Its citations and bibliographies are Word's for every source of the
four corpora Word wrote, and Word's XSL's for corpus s and for random sources.

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

* feat(bibliography): write citations and bibliographies in Harvard - Anglia, as Word does

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

* feat(bibliography): write citations and bibliographies in Chicago, as Word does

Ported from Word's CHICAGO.XSL, template by template, including its quirks:
a space after an entry that ends with a title in italics, as Word's XSLT
writes a line break there, "eds." left out after a list of editors, as
Word's English has none, and no space before "Edited by" after the title
of an interview. Tested against Word's own output for the probes' corpora,
and against Word's XSL for the synthetic corpus and the branches neither
reaches.

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

* test(bibliography): keep the empty paragraph Turabian writes for an artwork with nothing to write

Corpus s's fixture left out the paragraph Word writes for an artwork with no artist, title, institution, city or
publication title, which Turabian writes as an empty paragraph.

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

* feat(bibliography): write citations and bibliographies in Turabian, as Word does

Turabian's citations are Chicago's, and it finds a source's authors and sorts its bibliography as Chicago does, so
it shares those with Chicago, from chicago-family.ts. Its entries end with where and when the source was published.

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

* feat(bibliography): write citations and bibliographies in IEEE, as Word does

Written from Word's IEEE2006OfficeOnline.xsl: citations such as "[1, p. 50]", and a
bibliography that is a table of each source's number and entry, in the order the sources are
cited. Its people are written with the style's own templates for initials, and some of its
words are English written into the style, such as "Available:".

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

* test(bibliography): keep the empty paragraph MLA writes for an artwork with nothing to write

Corpus s's MLA fixture left out the empty paragraph Word writes for the work of art with none of its fields, as its generator dropped empty paragraphs.

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

* feat(bibliography): write citations and bibliographies in MLA, as Word does

MLA, seventh edition, written from Word's MLASeventhEditionOfficeOnline.xsl: citations such as "(Baker 50)", with the title when the authors don't tell a source apart, and a bibliography sorted by the people each source is named by, with "—" for the same people as the entry before.

It writes what Word's style writes, including where that isn't what MLA asks for: editors named first with no "eds." after several of them, an organization as a performer with no "Perf." before it, an interview's title without its italics when its interviewer follows, no space between a sound recording's album and its producer when it has neither composers nor a title, and a space after an entry that ends with italics, as Word reads it.

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

* fix(bibliography): name the style as Word for Mac finds it, and write bibliographies' paragraphs as Word does

Word for Mac only finds a style named with a slash before its file, and opens a document with
a backslash in APA. A bibliography of no sources is Word's bold "Invalid source specified.",
and IEEE's table has an empty paragraph after it, as Word writes them when it updates the
fields.

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

* feat(bibliography): docx/bibliography, with sources, citations and bibliographies in each of Word's styles (#557)

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

* fix(bibliography): reject a style named after a property every object has

createBibliography looked the style up in an ordinary object, so a name such as "toString" or "__proto__" found an inherited value, got past the check and failed later, when the document was packed. It now checks the style is one of the definitions' own keys, and throws the documented error.

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

* fix(bibliography): throw for a source whose type isn't one of SourceType's

A source with an unknown type, such as Word's own name "InternetSite" for SourceType.WEBSITE, was kept with no type and failed later in a style, with a TypeError. wordSourceOf now throws when the source is given, saying which source and type.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 21:49:43 +01:00
DolanandClaude Opus 5.5 9397bbd549 feat: write Word's Caption style, and document captions and cross-references (#557) (#3813)
Word gives the captions it inserts the paragraph style "caption", and docx
didn't write it, so a paragraph with `style: "Caption"` came out in Normal:
Word drops a style the document doesn't define. docx now writes the style
as Word writes it when it inserts a caption (small italic text in the
theme's second dark color, with space after), and `styles.default.caption`
changes it. A Caption style in paragraphStyles or externalStyles still takes
its place.

A new docs page shows captions with SequentialIdentifier, their numbers
written by docx/layout, cross-references to them with a bookmark and
NumberedItemReference, and a table of figures, none of which the docs
covered.


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

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 16:22:38 +01:00
Dolan ba2b4e26a0 feat: protect a document from changes in Word, with a password and editable ranges (#2271) (#3810) 2026-10-21 14:09:06 +01:00
Dolan 0132938894 feat: style a section's line numbers with styles.default.lineNumber (#551) (#3808) 2026-10-20 16:29:43 +01:00
Dolan 1bfacd5c83 fix: declare that docx needs Node.js 16 or later (#3807) 2026-10-20 14:33:39 +01:00
Dolan 9382d55176 feat: set a document's properties when patching it (#2701) (#3806) 2026-10-20 14:10:34 +01:00
Dolan 437d455034 feat: embed files in a document as OLE objects, from docx/embedded-files (#719) (#3802) 2026-10-20 12:49:44 +01:00
Dolan d71fb31dc5 feat: fit a run's text to a width with fitText (#2597) (#3801) 2026-10-20 02:55:23 +01:00
DolanandClaude Opus 5.5 3aaeff48b8 fix: start a numbered heading's table of contents entry with its number, with page numbers from docx/layout (#1130) (#3800)
* fix: start a numbered heading's table of contents entry with its number, with page numbers from docx/layout (#1130)

When Word fills in a table of contents, the entry of a numbered heading
starts with the heading's number, then a tab, with a tab stop past the
number. docx wrote the entries without the numbers. With page numbers
from docx/layout, the table is written clean, so Word shows it as it is
written and doesn't update it: the numbers were never shown. Word for
Mac opened such a document with "Main 2" where its own entry is
"1 Main 2".

A page number estimator can now work out the list numbers of the
paragraphs bookmarks start (listNumbers), which docx asks for once it
has bookmarked the headings, before it writes the entries.
estimatePageNumbers, and estimatePageNumbersWith's estimators, read
them as docx/layout numbers its lists, without laying out the pages. A
numbered heading's entry then starts with its number and a tab, or its
number and a space when its list follows the number with a space or
nothing, as Word writes it, and the pages are laid out with them. A
number docx/layout doesn't write as Word does is left out.

Word places the tab stop by its Normal template, not the document:
past the number, measured in Aptos 12 pt, by 240 twips, and 240 more a
level below the first, at the next multiple of 240 up to 1920, and
where it falls past that. docx places it the same way. The probes are
scripts/layout-probes/word-toc-numbers.ts and the documents Word saved
once it had updated their tables. After entries at levels 7 to 9, Word
places the stops after them on multiples of 200 instead, which docx
doesn't follow.

Checked in Word for Mac 16.114: Word opens the docs' example without
asking to update it, with "1 Introduction 2" to "2.1 Results 3", and
writes the same entries, tab stops and page numbers when it updates
the table itself.

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

* fix: don't name the TOC number probes .word.docx, which the layout comparison lays out

scripts/compare-layout.sh lays out every scripts/layout-probes/*.word.docx
and compares the page of each heading with the pages Word marked in it,
failing for a committed one whose marks don't have all its pages. The
TOC number probes' documents are what Word saved once it had updated
their tables, saved before Word had laid out all their pages, and
aren't for laying out: the shape demos workflow failed on
word-toc-numbers.word.docx, "its marks have 2 of its 3 pages".

They are now word-toc-numbers.docx and word-toc-numbers-font.docx, as
the other probes' documents are named.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 23:49:36 +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 69fc2da10d fix: stop an index entry field scrambling the document in Word (#1546) (#3792) 2026-10-19 12:23:45 +01:00
DolanandClaude Opus 5.5 ea08b9677c feat: write macro-enabled documents with VBA macros, from docx/macros (#471) (#3791)
* feat: write macro-enabled documents with VBA macros, from docx/macros (#471)

A document's macros, the macros option, make it a macro-enabled
document (.docm): its main part has the macro-enabled content type, it
has the VBA project, word/vbaProject.bin, and Packer gives it a .docm's
MIME type. The events of the document the macros handle, such as
Document_Open, are listed in word/vbaData.xml, as Word only runs the
handlers of the events listed there.

createMacros, in a new entry, docx/macros, writes the macros from VBA
code: ThisDocument's, modules and class modules. It writes the VBA
project as [MS-OVBA] describes, in a compound file ([MS-CFB]), without
a compiled cache, so Word compiles the code when it first runs it, and
lists the events ThisDocument has handlers for. A vbaProject.bin from a
.docm Word saved goes in macros too, with the events it handles.

Checked in Word for Mac 16.114: Document_Open runs when the document
opens, and so do macros in modules that use class modules and Office's
library. LibreOffice imports the modules, and the Open XML SDK validator
passes the demos for each version of Office since 2010. The demos
workflow now validates a .docm as it does a .docx.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

* fix: give a character beyond U+FFFF as two ChrW in createMacros' error

createMacros' error for a character Windows-1252 doesn't have said to
write it with ChrW and its code point, such as ChrW(&H1F600) for an
emoji. ChrW only takes a UTF-16 code unit, up to &HFFFF, so that fails
in Word. The error now gives one ChrW for each code unit: the surrogate
pair, ChrW(&HD83D) & ChrW(&HDE00), which Word for Mac turns into the
emoji. The docs say so too.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

* docs: say how to run the macros of a .docm downloaded in Word for Windows

The macros docs said Word asks whether to enable a .docm's macros when
it opens. Word for Windows doesn't for a file from the internet, such
as a .docm a web page made with docx and the browser downloaded: it
blocks its macros without an Enable Content button. The docs now say to
unblock the file in its Properties, that an organization's policy can
still block macros, and that Word for Mac isn't affected.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 00:13:28 +01:00
DolanandClaude Opus 5.5 7b08eacce9 fix: read an image's type from its data when it isn't given (#2952) (#3789)
TypeScript requires an ImageRun's type, but JavaScript can leave it out,
as the code in #2952 and #3305 did. The image was then written to
word/media/<hash>.undefined, which has no content type, so Word said the
document had unreadable content and Word Online wouldn't open it.

An image without a type now has it read from the bytes its data starts
with, for PNG, JPEG, GIF and BMP files, and so does an SVG image's
fallback. Data that isn't one of those is an error that says to give the
type, rather than a document Word can't read.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 21:38:46 +01:00
DolanandClaude Opus 5.5 0ffd27a95d docs: explain why TOC entries keep a heading's bold, and how to avoid it (#1369) (#3787)
When Word updates a table of contents, it copies the formatting set on a
heading's text, such as bold: true on a TextRun, onto the entry. That
takes priority over the TOC1 style, so bold: false there can't remove
it. Formatting from the heading's style isn't copied, so the fix is to
make the heading style bold instead.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 17:32:20 +01:00
Dolan 3b4f7777cd fix: patch a template read from a stream (#2321) (#3786) 2026-10-17 19:30:50 +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
Dolan c08ec0ae8a feat: two lines in one and horizontal in vertical with eastAsianLayout (#1943) (#3783) 2026-10-17 15:41:30 +01:00
Dolan 65d97ee0dd docs: show how to add SVG images with a fallback (#3315) (#3782) 2026-10-17 14:15:38 +01:00