 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Henk Baas Guest
|
Posted: Wed Oct 29, 2003 3:56 pm Post subject: TStringGrid and Clipboard |
|
|
Is it possible to copy a grid contents (in my case from a TStringGrid) to
the Clipboard and have it pasted in for example Excel?
Henk Baas
|
|
| Back to top |
|
 |
Peter Below (TeamB) Guest
|
Posted: Wed Oct 29, 2003 7:14 pm Post subject: Re: TStringGrid and Clipboard |
|
|
In article <3f9fe33e (AT) newsgroups (DOT) borland.com>, Henk Baas wrote:
| Quote: | Is it possible to copy a grid contents (in my case from a TStringGrid) to
the Clipboard and have it pasted in for example Excel?
|
Of course.
Var
S: String;
i, k: Integer;
begin
S:= '';
with stringgrid1 do begin
for i:= FixedRows to RowCount-1 do begin
For k:= FixedCols to ColCOunt-1 do begin
If k > FixedCols Then
S:= S + #9;
S:= S + Cells[k,i];
end; { for }
S:= S + #13#10;
end; { for }
end; { with }
Clipboard.AsText := S;
This generates a string in which columns are separated by Tab characters
and rows by CR/LF linebreaks. Most spreadsheets are able to paste this into
cells correctly. The code is not exactly efficient, so if you want to use
this for really large grids you may want to change the logic to write the
data to a TMemoryStream first, it has a smarter "grow" method. You can copy
the content of the memory stream to a string via
SetString( aString, PChar( aMemorystream.Memory ), aMemoryStream.Size );
and then copy that to the clipboard. Or use my CopyStreamToClipboard
routine (search the newsgroup archives for that).
--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|