Jump to content


Photo

Copy/Paste to/from Excel

excel copy paste

  • Please log in to reply
7 replies to this topic

#1 m610

m610
  • Members
  • 33 posts

Posted 12 August 2015 - 12:47 AM

Is it possible to copy and paste cells to and from Excel and TNxGrid? I just need to copy/paste the values, not formulas.

 

Thanks,

Mike



#2 m610

m610
  • Members
  • 33 posts

Posted 12 August 2015 - 05:19 AM

I figure I should be a bit more specific.

 

1. Select a block of cells in Excel

2. CTRL-C to copy to the clipboard

3. Select the top-left cell in my TNxGrid

4. CTRL-V to copy the block of cells in teh clipboard to teh grid.

 

Thanks, Mike



#3 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,196 posts
  • Gender:Male

Posted 12 August 2015 - 05:00 PM

Hi,

I think that you will need to do this manually, via Clipboard set of functions of Delphi. Most probably it will be easy to copy value of cell, but not sure about styles. I suggest that you look for Clipboard for Delphi on web.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#4 m610

m610
  • Members
  • 33 posts

Posted 12 August 2015 - 05:09 PM

Thanks.

 

I'm familiar with the clipboard, but not with the structure/format of the Excel data. I guess it's time I learned.

 

By the way, all I need to copy/paste are the values, not the styles.



#5 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,196 posts
  • Gender:Male

Posted 12 August 2015 - 05:39 PM

Hi,

 

I think that Excel will simply copy value to Clipboard as any other application. I suggest that you copy/paste into empty text file and see what is output.


boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#6 m610

m610
  • Members
  • 33 posts

Posted 12 August 2015 - 06:36 PM

Thanks.

 

It looks like it is tab delminted values (not formulas). I should be able to work with that by loading it into a TStringList or something and parsing it there.

 

Any tips on how to handle the CTRL-V part? I suppose I could always use a pop-up menu.



#7 jaimak

jaimak
  • Members
  • 7 posts
  • Gender:Male

Posted 12 August 2015 - 06:51 PM

Hello m610,

here is a small procedure from NextGrid to Clipboard. I found this everywhere in net. I hope it help you.

LD

 

 

uses clipbrd;

 

procedure NextGrid_ToClipboard(AGrid: TNextGrid; withHeader:Boolean);
var s   : String;
    c,r : Integer;
begin
  s := '';
  if withHeader
    then
      begin
        for r := 0 to AGrid.Columns.Count-1 do
        s := s + Trim(AGrid.Columns[r].Header.Caption) + #9;
        s := s + #13;
      end;
   for r := 0 to AGrid.RowCount - 1 do
     begin
       for c  := 0 to AGrid.Columns.Count - 1 do
         begin
           s := s + Trim(AGrid.Cell[c,r].AsString) + #9;
           s := s + #13;
         end;
    end;
  Clipboard.AsText := s;
end;



#8 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,196 posts
  • Gender:Male

Posted 12 August 2015 - 07:42 PM

Hi,

ctrl + V I will inspect in KeyDown. There is a Shift parameter to get Ctrl.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.





Also tagged with one or more of these keywords: excel, copy, paste

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users