Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/export-docx/src/converters/table-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ export function convertTableCell(
},
});
}
if (!cell.options.width) {
Object.assign(cell.options, {
width: {
size: 2000, // Default width of about 1.4 inches (2000/1440)
type: "dxa" as const,
},
});
}

return cell;
}
22 changes: 20 additions & 2 deletions packages/export-docx/src/converters/table-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,29 @@ export function convertTableHeader(
Object.assign(headerCell.options, { rowSpan: node.attrs.rowspan });
}

// Add column width if present
// Add column width if present, otherwise use default width
if (node.attrs?.colwidth !== null && node.attrs?.colwidth !== undefined) {
// colwidth is an array in TipTap, take the first value
const width =
Array.isArray(node.attrs.colwidth) && node.attrs.colwidth.length > 0
? node.attrs.colwidth[0]
: null;

if (width) {
Object.assign(headerCell.options, {
width: {
size: width,
type: "dxa" as const,
},
});
}
}

// If no width is set, apply a default minimum width to prevent cells from being too small
if (!headerCell.options.width) {
Object.assign(headerCell.options, {
width: {
size: node.attrs.colwidth,
size: 2000, // Default width of about 1.4 inches (2000/1440)
type: "dxa" as const,
},
});
Expand Down
8 changes: 8 additions & 0 deletions packages/export-docx/src/converters/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ export function convertTable(
// Build table options with options
const tableOptions: ITableOptions = {
rows,
// Set default table width if not specified
width: {
size: options?.run?.width?.size || 100,
type: options?.run?.width?.type || "pct",
},
// Use fixed layout to ensure cell widths are respected
// This is important when we set specific widths on cells
layout: options?.run?.layout || "fixed",
...options?.run, // Apply table options
};

Expand Down