HotXLS Docs

TXLSXAlignment class

Cell-alignment descriptor used by the XLSX facade. Live instances are held on the workbook-level Workbook.Alignments collection; cells refer to them through TXLSXCell.AlignmentIndex (1-based, 0 = workbook default).

Declaration

type
  TXLSXHorizontalAlignment = (
    xlsxXAlignDefault, xlsxXAlignLeft, xlsxXAlignCenter, xlsxXAlignRight,
    xlsxXAlignFill, xlsxXAlignJustify, xlsxXAlignCenterContinuous,
    xlsxXAlignDistributed);

  TXLSXVerticalAlignment = (
    xlsxYAlignDefault, xlsxYAlignTop, xlsxYAlignCenter, xlsxYAlignBottom,
    xlsxYAlignJustify, xlsxYAlignDistributed);

  TXLSXAlignment = class
    constructor Create;
    procedure Assign(Source: TXLSXAlignment);
    function IsDefault: Boolean;
    property Horizontal: TXLSXHorizontalAlignment;
    property Vertical: TXLSXVerticalAlignment;
    property WrapText: Boolean;
    property ShrinkToFit: Boolean;
    property Indent: Integer;
    property TextRotation: Integer;   // -90..90; Excel auto-converts
  end;

Notes

Example

var
  wrap, center: TXLSXAlignment;
  wrapIdx, centerIdx: Integer;
begin
  wrap := wb.Alignments.Add;
  wrap.WrapText := True;
  wrap.Vertical := xlsxYAlignTop;
  wrapIdx := wb.Alignments.Count;        // 1-based

  center := wb.Alignments.Add;
  center.Horizontal := xlsxXAlignCenter;
  center.Vertical := xlsxYAlignCenter;
  centerIdx := wb.Alignments.Count;

  ws.Cells.Item[1, 1].Value := 'A multi-line note that should wrap';
  ws.Cells.Item[1, 1].AlignmentIndex := wrapIdx;
  ws.Cells.Item[2, 1].Value := 'Centered';
  ws.Cells.Item[2, 1].AlignmentIndex := centerIdx;
end;