feat: write rich inline strings (per-run formatting) via Worksheet.inlineString#606
Merged
Merged
Conversation
…, RichText)
Add a RichText value type and a Worksheet.inlineString(int, int, RichText)
overload so callers can write a single cell with mixed per-run formatting
(bold, italic, underline, font size/name/color).
Output follows OOXML (ECMA-376 §18.4):
<c t="inlineStr"><is><r><rPr>...</rPr><t xml:space="preserve">...</t></r>...</is></c>
API:
RichText rt = RichText.builder()
.run("Pickable (A)").end()
.run("\n*Direct contract only").bold().fontColor("FF70AD47").end()
.build();
worksheet.inlineString(row, col, rt);
Notes:
- RichText (and its Builder/RunBuilder) are public; Run constructor is
package-private so runs are produced through the builder.
- Unset font fields on a run are omitted from <rPr>, letting Excel inherit
from the cell style — matches the existing inheritance contract for the
default cell font.
- xml:space="preserve" is always emitted so leading/trailing whitespace
and newlines round-trip correctly.
- Three POI round-trip tests added to PoiCompatibilityTest covering
per-run formatting, leading/trailing whitespace, and bare-run output.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Add support for writing rich inline strings — a single cell with multiple
font styles (bold/italic/underline, font size/name/color per run).
Use case
Template headers and cells where one fragment must be highlighted relative
to the rest currently can't be expressed:
Worksheet.value(r, c, String)/Worksheet.inlineString(r, c, String)apply one font to the whole cell.This adds a
RichTextvalue type and aWorksheet.inlineString(int, int, RichText)overload.API
RichText,RichText.Builder, andRichText.RunBuilderare public.RichText.Runconstructor is package-private — runs are produced throughthe builder. Unset font properties on a run are omitted from
<rPr>,letting Excel inherit from the cell style.
Wire format
Per OOXML (ECMA-376 §18.4):
xml:space="preserve"is always emitted so leading/trailing whitespace andnewlines round-trip correctly.
Tests
Three POI round-trip cases added to
PoiCompatibilityTest:<r><t>...</t></r>All 108 existing tests in
fastexcel-writercontinue to pass.Scope
This PR touches
fastexcel-writeronly. Issue #382 requests thereader module expose rich text formatting when parsing an existing
xlsx — that path is unchanged here. Reader-side work would be a natural
follow-up but is out of scope (theme/indexed color resolution requires
loading
theme1.xml, which the reader currently doesn't do — bestdesigned in a dedicated PR).