Mirror

How to put the content of a TStringGrid into an Excel range (Views: 710)


Problem/Question/Abstract:

How to put the content of a TStringGrid into an Excel range

Answer:

{ ... }
var
  ArrV: Variant;
  Cell: Range;
  { ... }

ArrV := VarArrayCreate([0, NumRows, 0, NumCols], varOleStr);
for Row := 0 to NumRows do
  for Col := 0 to NumCols do
    ArrV[Row, Col] := StringGrid1.Cells[Col, Row];
Cell := Excel.ActiveCell;
WS.Range[Cell, Cell.Offset[NumRows, NumCols]].Value := ArrV;
{ ... }

<< Back to main page