Do you have any experience using Win32::OLE with Excel?  That would be
the way to go.

I got this going, and there is only one weird idiosyncrasy that I found.
When you input data into a range using the Values property you do it by
putting your data into an anonymous array, but when you retrieve it, it
doesn't return an anonymous array, but instead it returns a reference to
an anonymous array that is the first element of another anonymous array,
which makes things look even stickier than usual.  

Consider the code below:

###################################

use strict;
use warnings;
use Win32::OLE;

#Check to see if Excel is already running
my $xl;
eval{$xl = Win32::OLE->GetActiveObject("Excel.Application");};

#Otherwise create a new instance of Excel
unless(defined $xl){
        $xl = Win32::OLE->new("Excel.Application");
}
$xl->{Visible} = "True";

#Create a new workbook for this session
my $book = $xl->Workbooks->Add;

#Delete the extra sheets
foreach my $delete(1..2){
        $book->WorkSheets($delete)->Delete();
}

#This next line keeps popups from showing when you perform
#certain actions, like saving a spreadsheet.
$xl->{DisplayAlerts} = "False";

#Create a worksheet object
my $sheet = $book->WorkSheets(1);

#Populate our cells
$sheet->Range("A1:F1")->{Value} = [1,2,3,4,5,6];
sleep 2;

#Reverse the cells
#I split this into three steps for legibility.
my $arrayRef = $sheet->Range("F1:A1")->{Value}->[0];
my @values = reverse @{$arrayRef};
$sheet->Range("A1:F1")->{Value} = [EMAIL PROTECTED];

####################################




-----Original Message-----
From: chen li [mailto:[EMAIL PROTECTED] 
Sent: Monday, April 10, 2006 1:53 PM
To: beginners@perl.org
Subject: reverse the order of a row in Excel

Dear all,

I know this question has nothing to do perl. But I
just wonder if anyone out there knows how to reverse
the order of a row in Excel. Here is the example:

I have  a row of data: 1, 0, 4, 5 in Excel but I would
like to reverse its order so that I get data row like
these: 5,4,0,1. If I just have a few data I can just
use cut and paste method. But what if I have hundreds
and hundreds?


Thanks,

Li



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to