HotXLS Delphi Excel Read Write Library / Component Developers Guide loslab Inc.

Open method

Opens an existing Workbook

Syntax

function Open(FileName: WideString):Integer;
function Open(Stream: TStream):Integer;
function Open(FileName: WideString; Password: WideString):Integer;
function Open(Stream: TStream; Password: WideString):Integer;
FileName WideString. A string that indicates the name of the file to be opened. You can include a full path; if you don't, Workbook opens the file in the current folder.
Stream TStream. A stream object that can be used to read the Workbook.
Password WideString. A string that contains the password required to open a protected Workbook.

Example

This example opens excel file book1.xls from the current folder.

Workbook.Open('book.xls');
This example opens password protected excel Workbook book2.xls with the password 'password'.

Workbook.Open('book2.xls', 'password');
This example changes the name of the first Worksheet in book1.xls.

Var book: IXLSWorkbook;
begin
  book := TXLSWorkbook.Create();
  book.Open('book1.xls');
  book.Sheets[1].Name := 'New name';
  book.SaveAs('book1.xls');
end;
This example loads Workbook from a BLOB field.

var
  MS: TMemoryStream;
begin
  MS := TMemoryStream.Create;
  try
    SQLDataSet1Documents.SaveToStream(MS);
    FWorkbook.Open(MS);
  finally
    MS.Free;
  end;
end;
Copyright©2007-2019 loslab.com