复制粘贴Excel数据列表到StringGrid(XE3下编写)
注意引用:Vcl.Clipbrd
procedure TDataEditDrFrm.Excel1Click(Sender: TObject);
var
Copystrings:Tstringlist;
daorustring,daorustring1,daorustring2:string;
i,j,row1,row2:Integer;
begin
daorustring:=(Clipboard.AsText);
daorustring1:=StringReplace(daorustring,#$D#$A,',',[rfReplaceAll]); // #$D#$A
daorustring2:=StringReplace(daorustring1,#9,',',[rfReplaceAll]);
Copystrings:=TStringList.Create;
for i := 1 to daorustring2.Length do
begin
if daorustring2[i]<>',' then
Copystrings.Add(daorustring2[i]);
end;
row1:=1;
row2:=0;
while(row1<=Round(Copystrings.Count/2)) do
begin
for j := 1 to 2 do
begin
strngrd1.Cells[j,row1]:=Copystrings[row2];
row2:=row2+1;
end;
row1:=row1+1;
if strngrd1.RowCount<Round(row1/2) then
strngrd1.RowCount:=strngrd1.RowCount+1
end;
end;