HotXLS Docs

TXLSXMergedCells / TXLSXMergedRange classes

Merged-range support on a TXLSXWorksheet. Each entry covers a rectangle of cells that Excel displays as one. The collection is round-tripped through the worksheet's <mergeCells> block. Declared in lxHandleX.

TXLSXMergedRange declaration

type
  TXLSXMergedRange = class
    constructor Create(ARow1, ACol1, ARow2, ACol2: Integer);
    property Row1: Integer;
    property Col1: Integer;
    property Row2: Integer;
    property Col2: Integer;
    property Ref: WideString;
  end;
      

TXLSXMergedRange members

Row1, Col1 1-based top-left corner.
Row2, Col2 1-based bottom-right corner (inclusive).
Ref OOXML A1-style range string such as 'A1:C3'. Computed on demand from the four indices.

TXLSXMergedCells declaration

type
  TXLSXMergedCells = class
    function Add(ARow1, ACol1, ARow2, ACol2: Integer): Integer; overload;
    function Add(const ARef: WideString): Integer; overload;
    procedure Clear;
    property Count: Integer;
    property Items[Index: Integer]: TXLSXMergedRange; default;
  end;
      

TXLSXMergedCells members

Add(R1, C1, R2, C2) Adds a merge rectangle and returns the new entry index. Coordinates are 1-based and inclusive on both ends.
Add(Ref) Adds a merge rectangle from an A1-style range string such as 'A1:C3'. Returns -1 if the string cannot be parsed.
Count Number of merge entries currently registered on the worksheet.
Items[Index] Merge entry at the given 0-based index. Declared as the default property.
Clear Removes and frees every merge entry.

Example

var
  ws: TXLSXWorksheet;
begin
  ws := Workbook.Sheets.Add('Demo');
  ws.Cells.Item[1, 1].Value := 'Title spans three columns';

  // Either the worksheet shorthand:
  ws.MergeCells(1, 1, 1, 3);

  // ...or the collection directly:
  ws.MergedCells.Add('A2:C2');
end;
    

See also