HotXLS Docs

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

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;