-
Notifications
You must be signed in to change notification settings - Fork 812
Open
Description
Description
When cellOpts.margin evaluates to a truthy non-number, non-array value (e.g., an object or a string), the cell margin XML attributes are generated as marL="NaN" marR="NaN" marT="NaN" marB="NaN", which triggers the PowerPoint repair dialog.
Root Cause
In gen-objects.ts (compiled: pptxgen.cjs.js around L5322), the margin handling converts numbers to arrays but does not guard against non-array, non-number values:
let cellMargin = cellOpts.margin === 0 || cellOpts.margin ? cellOpts.margin : DEF_CELL_MARGIN_IN;
if (!Array.isArray(cellMargin) && typeof cellMargin === 'number')
cellMargin = [cellMargin, cellMargin, cellMargin, cellMargin];
// If cellMargin is truthy but not a number or array, it falls through
// Then cellMargin[0] is undefined → inch2Emu(undefined) → Math.round(914400 * undefined) → NaNvalToPts() has a Number(pt) || 0 guard that catches NaN, but inch2Emu() does not — it directly computes Math.round(EMU * inches) which produces NaN.
Steps to Reproduce
- Create a table where cell margin resolves to a non-number, non-array truthy value
- Generate the .pptx
- Open in Microsoft PowerPoint → repair dialog appears
Expected Behavior
Invalid margin values should fall back to DEF_CELL_MARGIN_IN instead of producing NaN.
Suggested Fix
let cellMargin = cellOpts.margin === 0 || cellOpts.margin ? cellOpts.margin : DEF_CELL_MARGIN_IN;
if (!Array.isArray(cellMargin) && typeof cellMargin === 'number')
cellMargin = [cellMargin, cellMargin, cellMargin, cellMargin];
if (!Array.isArray(cellMargin))
cellMargin = DEF_CELL_MARGIN_IN;
cellMargin = cellMargin.map(v => (typeof v === 'number' && !isNaN(v)) ? v : 0);Environment
- PptxGenJS: 4.0.1
- PowerPoint for Mac (Microsoft 365)
- Node.js 22.x
Related
Possibly related to #1137 (margin unit inconsistency).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels