Delphi excel 复制粘贴到dbgrid

uses   Clipbrd

function SplitString(const Source,ch:String):TStringList;

var
temp: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;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值