Skip to content

Add configurable WrapText measurement to AutoFitColumns (#2427)#2428

Open
swmal wants to merge 2 commits into
develop8from
fix/WrappedTextAutofitMode
Open

Add configurable WrapText measurement to AutoFitColumns (#2427)#2428
swmal wants to merge 2 commits into
develop8from
fix/WrappedTextAutofitMode

Conversation

@swmal

@swmal swmal commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Implements #2427.
Adds a WrappedTextAutofitMode property to ExcelTextSettings, backed by a new eWrappedTextAutofitMode enum, giving control over how cells with WrapText enabled contribute to column width in AutoFitColumns().

Modes:

Skip — wrapped cells are ignored during autofit (default; preserves current behaviour).
FullText — the entire cell text is measured as a single line.
SplitNewLine — split on explicit line breaks (CR, LF, CRLF); widest line drives the width.
SplitWord — split on whitespace (space, tab, line breaks) and hyphens (U+002D, U+2010); widest segment drives the width. Visible hyphens are included in the segment width, whitespace is not.

Changes:

New eWrappedTextAutofitMode enum and WrappedTextAutofitMode property on ExcelTextSettings, propagated to the measurer.
Reworked MeasureTextInternal to measure per segment; the widest segment determines the result.
Fixed a pre-existing bug where East Asian character width accumulated across all lines instead of resetting per line.
Deprecated the internal MeasureWrappedTextCells flag via [Obsolete], mapping to the new enum.

Tests: Added coverage for all four modes plus CRLF handling, widest-segment-first, hyphen-as-visible-boundary, and the East Asian per-line reset.

Notes:

Applies to the generic font-metrics measurer; the System.Drawing measurer currently ignores the setting (to be addressed before the next release).
MeasureWrappedTextCells removal and the ITextMeasurer interface cleanup are deferred to EPPlus 9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant