2005. december 19., hétfő

Copy an Excel range into a two-dimensional array

Problem/Question/Abstract:

How to copy an Excel range into a two-dimensional array

Answer:

Copy it to a variant, then read the resulting variant array. This will be much faster than reading from each Excel cell individually, and it will avoid an Excel resource leak that can be critical on Win9x systems.

{ ... }
var
ArrV: OleVariant;
{ ... }

ArrV := WS.UsedRange[LCID].Value2;
for Row := 1 to VarArrayHighBound(ArrV, 1) - 1 do
for Col := 1 to VarArrayHighBound(ArrV, 2) - 1 do
Memo1.Lines.Add(Format('Row: %d Col: %d %s', [Row, Col, VarToStr(ArrV[Row,
Col])]));
end;
{ ... }


Nincsenek megjegyzések:

Megjegyzés küldése