Skip to content

Fix rich text rendering in PDF export and stop mutating source workbook#2371

Closed
swmal wants to merge 3 commits into
develop9from
textshaping-perf
Closed

Fix rich text rendering in PDF export and stop mutating source workbook#2371
swmal wants to merge 3 commits into
develop9from
textshaping-perf

Conversation

@swmal

@swmal swmal commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes a rich text rendering bug in PDF export and removes a serious side effect where the export mutated the source workbook.

Changes

  • Rich text fix: PdfTextMap now reads cell.RichText via the public property (which lazy-loads from XML) instead of the internal _rtc field. Cells whose _rtc happened to be null previously had their rich text formatting flattened to a single run of plain text.
  • No workbook mutation: GetTextFragments no longer creates an ExcelRichTextCollection for plain-text cells. That constructor had a hidden side effect — it set CellFlags.RichText and overwrote cell.Value, silently corrupting user data on export.
  • Stream API: Added PdfCatalog(settings, worksheet, stream) and ExcelPdf.CreatePdf(stream) overloads for in-memory export.
  • Temp worksheet cleanup: The temporary worksheet used for comments/notes pages is now removed after export. Previously it remained in the workbook, causing subsequent exports of the same workbook to fail.
  • ExcelColor.ToColor(): New public helper that resolves theme, tint, indexed, and RGB to a System.Drawing.Color.

How to verify

Export a workbook containing both rich-text and plain-text cells, then export it again from the same ExcelPackage instance. Both exports should succeed and render rich text correctly without altering the source workbook.

@swmal swmal self-assigned this Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants