Table of Contents

TExcelFile.VirtualMode Property

Set this value to true to turn Virtual Mode on. Look at 'Virtual mode' in the Performance Guide for more information.

Syntax

Unit: FlexCel.Core

property TExcelFile.VirtualMode: Boolean

Examples

You can find a full example of Virtual mode in the sample: 10.API\22.Virtual Mode But here we will show a simpler example which reads only the first row of cells from the first sheet and then exits.

type
TVirtualCellReader = class
  public
    procedure OnCellRead(const sender: TObject; const e: TVirtualCellReadEventArgs);
end;

{ TVirtualCellReader }
procedure TVirtualCellReader.OnCellRead(const sender: TObject;
  const e: TVirtualCellReadEventArgs);
begin
  if (e.Cell.Row > 1) then
  begin
    if e.Cell.Sheet < Length(e.SheetNames) then e.NextSheet := e.SheetNames[e.Cell.Sheet]
    else e.NextSheet := ''; // Stop reading the file.
  end
  else
  begin
    WriteLn('Cell: ', TCellAddress.Create(e.SheetNames[e.Cell.Sheet - 1], e.Cell.Row, e.Cell.Col, false, false).CellRef);
    WriteLn('Value: ', e.Cell.Value.ToString.ToString);
  end;
end;
...
procedure ReadFirstRowOfAllSheets(const fileName: String);
var
  xls: TXlsFile;
  CellReader: TVirtualCellReader;
begin
  xls := TXlsFile.Create;  //Create the object but don't open the file yet.
  try
    CellReader := TVirtualCellReader.Create;  // Create a CellReader to handle reading the cells.
    try
      xls.VirtualMode := true;  //Set the mode to Virtual.
      xls.VirtualCellRead:= CellReader.OnCellRead; //Assign the CellReader to the TXlsFile.
      xls.Open(fileName);
    finally
      CellReader.Free;
    end;
  finally
    xls.Free;
  end;
end;

See also