TXLSXRichText / TXLSXRichTextRun classes
Multi-run rich-text payload for an XLSX cell. Live instances are
attached to a cell via
TXLSXCell.RichText (the
cell owns the instance and frees it on destruction). SaveAs routes the
cell through the shared-string table with one <r> per
run; Open rebuilds the TXLSXRichText from the parsed SST entry and the
cell's Value exposes the concatenated plain text so callers
that ignore formatting still see something useful.
Declaration
type
TXLSXRichTextRun = class
constructor Create;
procedure Assign(Source: TXLSXRichTextRun);
property Text: WideString;
property Name: WideString;
property Size: Double;
property Bold: Boolean;
property Italic: Boolean;
property Strikethrough: Boolean;
property Underline: TXLSXUnderline;
property Color: LongWord;
property ColorIsAuto: Boolean;
end;
TXLSXRichText = class
constructor Create;
destructor Destroy; override;
function AddRun: TXLSXRichTextRun;
function AddRunText(const AText: WideString): TXLSXRichTextRun;
procedure Clear;
function PlainText: WideString;
property RunCount: Integer;
property Runs[Index: Integer]: TXLSXRichTextRun;
end;
Notes
- Setting
cell.RichTexttakes ownership; the cell frees the instance when it is destroyed or when the property is reassigned. - If a cell has both
ValueandRichText, SaveAs uses the rich-text path;Valuestill surfaces the concatenated plain text fromRichText.PlainTexton Open. - Underline / Color follow the same enums used by
TXLSXFont —
TXLSXUnderlineand an ARGB 32-bit color.
Example
var
rt: TXLSXRichText;
run: TXLSXRichTextRun;
begin
rt := TXLSXRichText.Create;
run := rt.AddRunText('Warning: ');
run.Bold := True;
run.Color := $FFCC0000; // ARGB red
run.ColorIsAuto := False;
rt.AddRunText('do not edit this cell.');
ws.Cells.Item[1, 1].RichText := rt; // cell now owns rt
end;