HotXLS Docs

WriteCells method

Fills a classic XLS worksheet range by calling application code for each cell value.

Syntax

type
  TXLSCellWriteEvent = procedure(
    Sender: TObject;
    SheetIndex, Row, Col: Integer;
    var Value: Variant;
    var Skip: Boolean;
    var Cancel: Boolean) of object;

function WriteCells(ARange: WideString; Callback: TXLSCellWriteEvent): Integer; overload;
function WriteCells(ARow1, ACol1, ARow2, ACol2: Integer; Callback: TXLSCellWriteEvent): Integer; overload;

Remarks

The string overload accepts an A1-style range such as A1:C100. The numeric overload uses 1-based row and column indexes. Ranges are normalised when the start row or column is greater than the end row or column.
Cells are requested in row-major order. Set Value in the callback to write the current cell. Set Skip to True to leave the current cell unchanged. Set Cancel to True to stop after the current callback. The return value is the number of cells written.
This method writes into the loaded worksheet model. It is a compact callback-based writing helper, not a file-streaming save mode.

Example

procedure TForm1.WriteCell(Sender: TObject; SheetIndex, Row, Col: Integer;
  var Value: Variant; var Skip: Boolean; var Cancel: Boolean);
begin
  if Col = 3 then
  begin
    Skip := True;
    Exit;
  end;

  Value := Format('R%dC%d', [Row, Col]);
  if Row >= 1000 then
    Cancel := True;
end;

Written := Workbook.Sheets[1].WriteCells('A1:D2000', WriteCell);

See Also