• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 759
  • Last Modified:

How to: From StringGrid to Clipboard (newbie Question)

Basically, If I have a single StringGrid, which the best way to export its contents to clipboard. ie: I need import the contents from Excel.

Is the StringGrid a good alternative ?
If I have a listview (report mode), can I manage it as StringGrid through cols/rows

Thanks in advance
0
rdfloc
Asked:
rdfloc
1 Solution
 
TIgorCommented:
listenning....
0
 
Lukasz LachCommented:
//Copy
procedure TForm1.Button1Click(Sender: TObject);
var
   S:String;
   GRect:TGridRect;
   C,R:Integer;
begin
   GRect:=StringGrid1.Selection;
   S:='';
   for R:=GRect.Top to GRect.Bottom do
   begin
       for C:=GRect.Left to GRect.Right  do
       begin
       if C= GRect.Right then  S:=S+(StringGrid1.Cells[C,R])
         else  S:=S+StringGrid1.Cells[C,R]+#9;
       end;
       S:=S+#13#10;
   end;
   ClipBoard.AsText:= S;
end;

// Paste
procedure TForm1.Button2Click(Sender: TObject);
var
   Grect:TGridRect;
   S,CS,F:String;
   L,R,C:Byte;
begin
   GRect:=StringGrid1.Selection;
   L:=GRect.Left; R:=GRect.Top;
   S:=ClipBoard.AsText;
   R:=R-1 ;
   while Pos(#13,S)>0 do
   begin
       R:=R+1;
       C:=L-1;
       CS:= Copy(S,1,Pos(#13,S));
       while Pos(#9,CS)>0 do
       begin
           C:=C+1;
           if (C<=StringGrid1.ColCount-1)and (R<=StringGrid1.RowCount-1) then
               StringGrid1.Cells[C,R]:=Copy(CS,1,Pos(#9,CS)-1);
               F:= Copy(CS,1,Pos(#9,CS)-1);
           Delete(CS,1,Pos(#9,CS));
       end;
       if (C<=StringGrid1.ColCount-1)and (R<=StringGrid1.RowCount-1) then
               StringGrid1.Cells[C+1,R]:=Copy(CS,1,Pos(#13,CS)-1);
       Delete(S,1,Pos(#13,S));
       if Copy(S,1,1)=#10 then
       Delete(S,1,1);
   end;
end;
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now