uses Clipbrd
function SplitString(const Source,ch:String):TStringList;
vartemp:String;
i:Integer;
begin
Result:=TStringList.Create;
//如果是空自符串则返回空列表
if Source=''
then exit;
temp:=Source;
i:=pos(ch,Source);
while i<>0 do
begin
Result.add(copy(temp,0,i-1));
Delete(temp,1,i);
i:=pos(ch,temp);
end;
Result.add(temp);
end;
procedure Tfrm_bjd.N2Click(Sender: TObject);
var
row,col:TStringList;
r,c:Integer;
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]);
ShowMessage(daorustring2);
row:=TStringList.Create;
col:=TStringList.Create;
row:=SplitString(daorustring2,'@');
r:=row.count;
ShowMessage(IntToStr(row.Count));
for i := 0 to row.count - 2 do
begin
cds1.Append;
col:=splitstring(row[i],'|');
//ShowMessage(IntToStr(col.Count));
//for j := 0 to col.Count - 1 do
// begin
ShowMessage(row[i]);
cds1.FieldByName('clmc').AsString:=col[0];
cds1.FieldByName('ggxh').AsString:=col[1];
cds1.FieldByName('dw').Value:=col[2];
cds1.FieldByName('sjs').AsString:=col[3];
cds1.FieldByName('sss').Value:=col[4];
cds1.FieldByName('zlqk').AsString:=col[5];
//end;
cds1.post;
end;
//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;