Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

XLSX Get Sheet Names

Open an Excel spreadsheet (.xlsx) and get the names of the sheets.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.StringTable,
  Chilkat.Zip,
  Chilkat.Csv;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  zip: TZip;
  csv: TCsv;
  sheetNames: TStringTable;
  i: Integer;

begin
  success := False;

  //  This example assumes the Chilkat API to have been previously unlocked.
  //  See Global Unlock Sample for sample code.

  //  .xlsx files are Zip archives
  zip := TZip.Create;
  success := zip.OpenZip('qa_data/excel/fakeCompanies.xlsx');
  if (success = False) then
    begin
      WriteLn(zip.LastErrorText);
      Exit;
    end;

  csv := TCsv.Create;
  sheetNames := TStringTable.Create;
  success := csv.XlsxGetSheets(zip,sheetNames);
  if (success = False) then
    begin
      WriteLn(csv.LastErrorText);
      Exit;
    end;

  i := 0;
  while i < sheetNames.Count do
    begin
      WriteLn(sheetNames.StringAt(i));
      i := i + 1;
    end;



  zip.Free;
  csv.Free;
  sheetNames.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.