feat: embed cell <img> as floating images in exported excel - #2
Open
sibinc wants to merge 1 commit into
Open
Conversation
Images inside table cells (logos, college headers/banners, signs, seals, student photos, QR codes) were stripped by htmldecode and never reached the exported sheet. Add image support in the parser so every <img> in a cell is read from the loaded DOM image via a canvas and embedded with exceljs addImage, anchored to that cell. convert() stays synchronous and templates need no changes. - parser.js: thread workbook through, add addCellImages/getImageDataUrl, defensively skip unloaded/cross-origin-tainted images - tableToExcel.js: pass workbook into parseDomToTable - tests: update call sites to new signature, add image cell test + sample - README: document image behaviour and CORS caveat - dist: rebuild bundle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Images placed inside table cells (
<td>/<th>) — college logos, header/banner images, signatures, seals, student photos, QR codes — were silently dropped from the exported Excel.htmldecode()strips every tag (including<img>), so the cell became empty text and no image was ever embedded. This affects 100+ report templates that render an<img>into a header cell and export viaTableToExcel.convert(...).Fix
Add image support in the library itself (one place), so no template or caller changes are needed:
src/parser.js—parseDomToTablenow receives the workbook. For each cell,addCellImages()finds every<img>, reads the already-loaded DOM image through a<canvas>→ PNG base64, and embeds it withwb.addImage()+ws.addImage()anchored (oneCell) to the cell's top-left, sized from the img'swidth/height. Cell text alongside the image is still exported. Wrapped in try/catch — unloaded or cross-origin-tainted images are skipped so a single bad image never breaks the export.src/tableToExcel.js— threads the workbook intoparseDomToTable.convert()stays synchronous (canvas reads are sync for loaded, same-origin images), so existing callers are untouched.Tests
Notes for reviewers
dist/bundle is rebuilt in this PR. Deploying to consumers (e.g. examcontroller-ui) requires publishing a new package version and bumping it there.