Skip to content

convertDocxToHtml throws Format_InvalidStringWithValue on tables with percentage widths (w:type="pct") #210

@mazurwieslaw2022-cmd

Description

@mazurwieslaw2022-cmd

Summary

convertDocxToHtml throws Conversion failed: Format_InvalidStringWithValue, 100% for any document containing a table whose width (table-level or cell-level) is expressed as a percentage (w:tblW/w:tcW with w:type="pct"). Tables using DXA (twips) widths convert fine.

The failure happens on plain conversion (no comparison involved), so it is not specific to compareDocuments/redline output.

Environment

  • docxodus@6.2.0 (npm, WASM)
  • Node.js v24.15.0, Windows 11
  • platform: browser-wasm, dotnetVersion: 8.0.27

Minimal reproduction

Uses docx to author the input.

import { Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell, WidthType } from "docx";
import * as dx from "docxodus";

await dx.initialize();

async function tableDoc(widthType, cellW) {
  const cell = (t) => new TableCell({ children: [new Paragraph({ children: [new TextRun(t)] })], width: { size: cellW, type: widthType } });
  const row = (a, b) => new TableRow({ children: [cell(a), cell(b)] });
  const tbl = new Table({
    width: { size: widthType === WidthType.PERCENTAGE ? 100 : 9000, type: widthType },
    rows: [row("Item", "Amount"), row("Fee", "1000")],
  });
  return new Uint8Array(await Packer.toBuffer(new Document({ sections: [{ children: [new Paragraph("Header"), tbl] }] })));
}

// PERCENTAGE -> throws
await dx.convertDocxToHtml(await tableDoc(WidthType.PERCENTAGE, 50));
// -> Error: Conversion failed: Format_InvalidStringWithValue, 100%

// DXA -> OK
await dx.convertDocxToHtml(await tableDoc(WidthType.DXA, 4500)); // fine

Expected

Percentage-width tables convert to HTML (e.g. width: 50% on the cells / width: 100% on the table), like DXA-width tables do.

Actual

Throws Format_InvalidStringWithValue, 100%. The message suggests the percentage string ("100%"/"50%") is being passed to a numeric parse that doesn't strip the % suffix or doesn't handle the pct width type.

Workaround

Use DXA (twips) widths instead of percentages when authoring tables intended for HTML conversion.

Isolation

Width type convertDocxToHtml(original) convertDocxToHtml(redline)
PERCENTAGE throws throws
DXA OK OK

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions