HotXLS Docs

TXLSXSheets class

Worksheet collection on TXLSXWorkbook. Mirrors the IXLSWorkSheets collection on the BIFF facade so that the call style stays consistent across the two formats. Declared in lxHandleX.

Declaration

type
  TXLSXSheets = class
    function Add: TXLSXWorksheet; overload;
    function Add(const AName: WideString): TXLSXWorksheet; overload;
    procedure Clear;
    function IndexByName(const AName: WideString): Integer;
    function SheetByName(const AName: WideString): TXLSXWorksheet;
    function TryGetSheetByName(const AName: WideString; out Sheet: TXLSXWorksheet): Boolean;
    property Count: Integer;
    property Items[Index: Integer]: TXLSXWorksheet; default;
  end;
      

Members

Add Adds a new worksheet with an auto-generated name (Sheet1, Sheet2, ...). Returns the new TXLSXWorksheet.
Add(AName) Adds a new worksheet with the given name. Returns the new worksheet.
Clear Removes and frees every worksheet in the collection.
IndexByName(AName) Case-insensitive name lookup. Returns the index or -1 if no worksheet has that name.
SheetByName(AName) Case-insensitive name lookup. Returns the matching TXLSXWorksheet object or nil if no worksheet has that name.
TryGetSheetByName(AName, Sheet) Case-insensitive name lookup with a Boolean status result. Returns True and assigns Sheet when a worksheet is found; returns False and assigns nil otherwise.
Count Number of worksheets currently in the workbook.
Items[Index] Worksheet at the given 0-based index. Declared as the default property so Sheets[i] works directly.

Example

var
  i: Integer;
begin
  Workbook.Sheets.Add('Summary');
  Workbook.Sheets.Add('Detail');

  for i := 0 to Workbook.Sheets.Count - 1 do
    WriteLn(Workbook.Sheets[i].Name);

  if Workbook.Sheets.IndexByName('Detail') >= 0 then
    ShowMessage('Detail sheet exists.');

  if Workbook.Sheets.SheetByName('Detail') <> nil then
    Workbook.Sheets.SheetByName('Detail').Cells[1, 1].Value := 'Ready';
end;
    

See also