-
-
Notifications
You must be signed in to change notification settings - Fork 34
Description
Bug Description
Table cell borders have w:val (border style) and w:color (hex color) swapped in the generated DOCX XML. This causes borders to be invisible in Microsoft Word.
Environment
@turbodocx/html-to-docxv1.20.1- Bun 1.3.8 / Node.js compatible
- Microsoft Word (Windows)
Steps to Reproduce
import HTMLtoDOCX from "@turbodocx/html-to-docx";
const html = `
<table>
<tr>
<td style="width: 50%;">Cell 1</td>
<td style="width: 50%;">Cell 2</td>
</tr>
</table>`;
const docx = await HTMLtoDOCX(html, null, {
table: {
borderOptions: {
size: 2,
stroke: "single",
color: "000000",
},
},
});Expected Behavior
Generated XML should have:
<w:top w:val="single" w:sz="2" w:space="0" w:color="000000"/>Actual Behavior
Generated XML has val and color swapped:
<w:top w:val="000000" w:sz="2" w:space="0" w:color="single"/>Word interprets w:val="000000" as an unknown border style, so borders are invisible.
When It Occurs
The swap happens for cells in "edge" positions (first row, last row, single-row tables) that have inline styles (like width) but no inline border CSS property. The library falls back to documentOptions.table.borderOptions but puts the values in the wrong XML attributes.
Cells in "middle" rows without inline styles generate correct borders.
Workaround
Adding explicit border in the inline style on every <td> forces the CSS border parser path, which generates correct XML:
<td style="border: 1px solid #000000; width: 50%;">Cell 1</td>Root Cause
Likely in the fixupTableCellBorder or buildTableCellBorders functions in src/helpers/xml-builder.js. When applying defaults from documentOptions.table.borderOptions to edge cells, the stroke value ends up in w:color and the color value ends up in w:val.
🤖 This bug was discovered and reported by Claude Opus 4.6 (Anthropic)