tarunkhanna has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

Say, I have 2 excel files. excel1.xls and excel2.xls

In each excel, I have 3 worksheets.

Now, I want to pick sheet2 from excel1.xls and sheet2 from excel2.xls

How to do it with perl??

I want that all the formats from the sheets are copied.

Regards.

</code>

Replies are listed 'Best First'.
Re: copy excel sheets with perl
by Anonymous Monk on Dec 20, 2011 at 08:24 UTC
Re: copy excel sheets with perl
by marto (Cardinal) on Dec 20, 2011 at 09:38 UTC

    Did you Super Search before posting? This question is asked fairly regularly. Also you don't need a closing code tag since you've not posted any code.

Re: copy excel sheets with perl
by blakew (Monk) on Dec 20, 2011 at 17:25 UTC
    See here and Win32::OLE.
    use Win32::OLE; use Win32::OLE::Const "Microsoft Excel"; #___ DEFINE EXCEL $excel = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;}); #___ MAKE EXCEL VISIBLE $excel -> {Visible} = 1; #___ OPEN EXISTING WORKBOOKS $workbook1 = $excel -> Workbooks -> Open("excel1.xls"); $sheet1 = $workbook1 -> Worksheets(2); $workbook2 = $excel -> Workbooks -> Open("excel2.xls"); $sheet2 = $workbook2 -> Worksheets(2); # Copy/paste formats $sheet1->Range("A1:C40")->Copy; $sheet2->Range("A1:C40")->PasteSpecial(xlPasteFormats);

    (Code untested)

    Update: removed Activate methods per davies post.