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
Horizontal = xlsxXAlignDefaultandVertical = xlsxYAlignDefaultsuppress the corresponding attribute on SaveAs.TextRotationtakes a signed integer in the API for convenience. SaveAs converts it to Excel's stored form (0..90 for counter-clockwise, 91..180 for clockwise) and Open converts it back.- Use
Workbook.Alignments.Addto create a new descriptor, then assign the returned 1-based index (viaWorkbook.Alignments.Count) to a cell'sAlignmentIndex.
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;