HotXLS Docs

TXLSXFont / TXLSXFonts classes

Workbook-level font palette for the XLSX facade. The collection lives on TXLSXWorkbook.Fonts; individual cells pick a font through TXLSXCell.FontIndex (1-based). SaveAs emits a real fonts list inside xl/styles.xml and pairs each font with a dedicated cellXf; Open reads it back so a saved-then-reopened workbook keeps the customized Name, Size, Bold, Italic, Strikethrough, Underline, and Color attributes. Declared in lxHandleX.

TXLSXFontVertAlign declaration

type
  TXLSXFontVertAlign = (
    xlsxVertAlignBaseline,
    xlsxVertAlignSuperscript,
    xlsxVertAlignSubscript);
      
Vertical text position. xlsxVertAlignBaseline (default) places text on the normal baseline; the other two values emit a <vertAlign val="superscript"/> or <vertAlign val="subscript"/> child element.

TXLSXUnderline declaration

type
  TXLSXUnderline = (
    xlsxUnderlineNone,
    xlsxUnderlineSingle,
    xlsxUnderlineDouble,
    xlsxUnderlineSingleAccounting,
    xlsxUnderlineDoubleAccounting);
      
Mirrors the OOXML u/val token set. xlsxUnderlineNone suppresses the element entirely.

TXLSXFont declaration

type
  TXLSXFont = class
    constructor Create;
    procedure Assign(Source: TXLSXFont);
    property Name: WideString;
    property Size: Double;
    property Bold: Boolean;
    property Italic: Boolean;
    property Strikethrough: Boolean;
    property Underline: TXLSXUnderline;
    property Color: LongWord;
    property ColorIsAuto: Boolean;
    property ColorTheme: Integer;
    property ColorIndex: Integer;
    property TintAndShade: Double;
    property VertAlign: TXLSXFontVertAlign;
    property OutlineFont: Boolean;
    property Shadow: Boolean;
    property Family: Integer;
    property CharSet: Integer;
  end;
      

TXLSXFont members

Name Font family name (default 'Calibri').
Size Font size in points (default 11).
Bold / Italic / Strikethrough Boolean toggles. SaveAs emits the matching OOXML child element (<b/>, <i/>, <strike/>) when the property is True.
Underline One of the TXLSXUnderline tokens. xlsxUnderlineSingle emits a bare <u/> (OOXML default); the other tokens emit <u val="..."/>.
Color 8-digit ARGB color (e.g. $FFFF0000 for opaque red). Only honored when ColorIsAuto = False.
ColorIsAuto When True (default), the <color/> child is omitted so Excel uses the automatic color. Set to False when you populate Color.
VertAlign Superscript or subscript positioning. Default is xlsxVertAlignBaseline (normal). Emits <vertAlign val="superscript"/> or <vertAlign val="subscript"/>.
OutlineFont When True, emits <outline/> (macOS outline rendering). Rarely used on Windows.
Shadow When True, emits <shadow/> (macOS shadow rendering).
Family OOXML font-family numeric token (0 = not applicable, 1 = Roman, 2 = Swiss, 3 = Modern, 4 = Script, 5 = Decorative). Default 0 suppresses the <family/> element.
CharSet Windows character-set code (e.g. 0 = ANSI, 128 = Shift-JIS, 134 = GB2312). Default 0 suppresses the <charset/> element.
ColorTheme Office theme color slot index (0..9 per OOXML theme spec). Set to -1 (default) to use the Color / ColorIndex path instead. When ≥ 0, SaveAs emits <color theme="N" tint="..."/> and ignores Color / ColorIndex.
ColorIndex OOXML indexed-color palette slot (0..63). Only applied when ColorTheme < 0 and ColorIsAuto = False. Emits <color indexed="N"/>. Set to -1 (default) to use the Color (RGB) path.
TintAndShade Luminance adjustment applied on top of ColorTheme or ColorIndex (-1.0 = black, 0.0 = no change, +1.0 = white). Emits a tint="N" attribute when non-zero.
Assign(Source) Copies every property from Source. Used by TXLSXFonts.Add(Source).

TXLSXFonts declaration

type
  TXLSXFonts = class
    function Add: TXLSXFont; overload;
    function Add(Source: TXLSXFont): Integer; overload;
    function Add(const AName: WideString; ASize: Double; ABold, AItalic: Boolean): Integer; overload;
    procedure Clear;
    property Count: Integer;
    property Items[Index: Integer]: TXLSXFont; default;
  end;
      

TXLSXFonts members

Add Creates a new font seeded with the Calibri 11 defaults and appends it. Returns the new TXLSXFont instance for further tweaking.
Add(Source) Copies every property from Source into a new font and appends it. Returns the new entry index.
Add(Name, Size, Bold, Italic) Convenience overload that creates a font from the four most common attributes and returns the new entry index.
Count Number of user-defined fonts (the implicit Calibri 11 default that Excel always provides is not counted here).
Items[Index] Font at the 0-based index. Declared as the default property so Workbook.Fonts[i] works directly.
Clear Removes and frees every font.

Example

var
  wb: TXLSXWorkbook;
  ws: TXLSXWorksheet;
  boldRed: Integer;
begin
  wb := TXLSXWorkbook.Create;
  try
    // Define a bold red font and remember its 0-based index.
    boldRed := wb.Fonts.Add('Calibri', 14, True, False);
    wb.Fonts[boldRed].Color := $FFFF0000;
    wb.Fonts[boldRed].ColorIsAuto := False;
    wb.Fonts[boldRed].Underline := xlsxUnderlineSingle;

    ws := wb.Sheets.Add('Demo');
    ws.Cells.Item[1, 1].Value := 'Alert';
    ws.Cells.Item[1, 1].FontIndex := boldRed + 1; // 1-based on the cell

    wb.SaveAs('alert.xlsx');
  finally
    wb.Free;
  end;
end;
    

See also