You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 46f95cd
Browse filesBrowse the repository at this point in the historyBrowse files
authored
Render byte[] template placeholders as images (#1018)
* Render byte[] values as images in templates
Template placeholders that resolve to image byte[] values (root, nested or
inside collections) are now emitted as embedded images, consistently with
the SaveAs pipeline and reusing ImageHelper, FileDto and ExcelXml.
- Resolve nested scalar paths such as {{Company.Logo}}.
- Stop treating byte[] as an IEnumerable during template resolution.
- Emit media, drawing and relationship parts, and declare the drawing
content type so Excel does not repair the workbook.
- Merge into a pre-existing drawing and worksheet rels instead of
dropping them.
Refs #604, #972.
* docs: document template image support
Explain how byte[] template placeholders are rendered as embedded images
(root, nested and collections), consistently with SaveAs, and how to opt
out via EnableConvertByteArray.
Refs #604, #972.
* Size template images to the row height
Scale template images to the height of the row they are anchored to,
preserving their aspect ratio, by reading the natural dimensions from the
image header (PNG, JPEG, GIF, BMP and TIFF). Rows without an explicit
height keep the previous default anchor size.
Refs #604, #972.
* Avoid duplicate picture ids when merging template drawings
Base the picture id assigned to generated anchors on the highest id already
present in the reused drawing instead of on the number of existing anchors,
so merged images no longer clash with the template's own pictures.
* Keep image parts and relationships unique per anchor
Two images captured on the same template cell, for example {{Image1}} {{Image2}},
derived the same media part, relationship id and r:embed from their sheet, row and
column coordinates. The second image overwrote the first and the drawing ended up
with duplicate relationship ids, which Excel repairs by dropping the picture.
Give every template image a unique suffix for its derived identifiers. The SaveAs
id scheme is left untouched.
Refs #604, #972.
* Release template image bytes once they are captured
Pending images kept every resolved byte[] alive until the next template run,
including values that were never rendered and every image produced by a collection.
Transfer ownership of the bytes to the emitted file on first capture, reuse them
for repeated captures through a lightweight reference, and drop the per-sheet and
per-run bookkeeping as soon as it is no longer needed.
Refs #604, #972.
* Fix template image docs wording and IdSuffix comment
Drop the claim that template image support has existed since v2.0.0, and describe
the IdSuffix property by its actual purpose: disambiguating generated media and
relationship ids when multiple image values share one anchor cell.
Refs #604, #972.
* Fix template drawing allocation, worksheet order, namespace and TIFF bounds
- Allocate generated drawing part names independently from the worksheet
relationship id, so a drawing part owned by another template sheet is never
reused.
- Insert the generated <drawing> before the CT_Worksheet suffix elements,
including the legacyDrawing used by comments.
- Write the <drawing r:id> through XmlWriter so the r namespace is declared
whenever the worksheet does not already declare it.
- Make the TIFF bounds checks overflow-safe so malformed offsets return null
instead of aborting the export.
Refs #604, #972.
* test: verify template image bytes are collectable after the call
* Removed legacy facade test
Adding a reference to the full MiniExcel project just for testing a single facade method is a bit out of place. If in the future we create a separate test project exclusively for facade methods this will be included there.
* Simplified image size construction
Refactored byte manipulation operations into `BinaryPrimitives` method calls for clarity
* Removed regex expressions for processing of images markers
The expressions were used to filter the rows containing cells with image markers, extrapolate their height, map the cell references to the relative images and finally remove the markers using named capture groups.
This approach was not very readable so I changed in favor of a clearer one: parsing the xml string into a `XElement` and manipulating it to obtain the same result.
* Inlined a few single-use methods
* Minor cleanup
- Slightly simplified image marker processing
- Removed unused OpenXmlValueExtractorHook.cs file
- Changed magic string data types to corresponding strong type constants where appropriate
* Fixed edge case problem in image marker processing
Reintroduced a more contained regex expression to make sure only the image markers and the relative image ids are replaced with empty strings
---------
Co-authored-by: Wei Lin <shps951002@gmail.com>
Co-authored-by: Michele Bastione <michele.bastione@gmail.com>
0 commit comments