Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Copy paste rows in excel

by imrags (Monk)
on Jul 21, 2009 at 07:17 UTC ( [id://781875]=note: print w/replies, xml ) Need Help??


in reply to Copy paste rows in excel

Well, i wrote the following and it worked on my system.
use Win32::OLE; my $excelfile = 'E:\\perl scripts\\abc.xls'; my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); $Excel->{'Visible'} = 1; my $Book = $Excel->Workbooks->Open($excelfile); my $Sheet = $Book->Worksheets("Sheet1"); $Sheet->Activate(); #------Here's what u were looking for $Sheet->range('A4')->copy(); $Sheet->range('B1')->Select(); $Sheet->paste();
With what I've learnt using excel<->perl, i've found that one should write the code
as one would work manually with excel (step by step), that helps with perl/excel.
That's my feeling anyway!
Raghu

Replies are listed 'Best First'.
Re^2: Copy paste rows in excel
by Ankit.11nov (Acolyte) on Jul 21, 2009 at 08:19 UTC
    Thanks Raghu for the help. With this piece of code copy operation is working for me as well.
    One more clarification:
    Is there any way in which we can copy one complete row and paste it, as here it just picks the cell A4 and copies to cell B1.
      As I said, think how you'll do it manually and make perl do it.
      $Sheet->rows('4:4')->copy(); $Sheet->rows('15:15')->Select(); $Sheet->paste();
      The above code copies 4th row cells to 15th row cells.
      Raghu
        Hi I am trying the same code to copy values of one row of excel into another, but getting error "Can't locate object method "GetActiveObject" via package "Win32::OLE" (perhaps you forgot to load "Win32::OLE"?) at C:\Users\ssoni\Desktop\copyexcel.pl line 2." could you please help what should be done in the case?
        Thanks again Raghu. Its working :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://781875]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-19 01:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found