--- Timothy Johnson <[EMAIL PROTECTED]> wrote:

> Ah.  Ok, this will work as long as you are using
> text files.  The
> answers I gave you were for automating Excel using
> OLE.  Unless you are
> having to do this over and over, saving the file as
> text and then using
> this will probably work, except for one thing:  Do
> you want to split the
> line into an array of single characters, or do you
> want to print out the
> reverse order of the cells? 

I need to reverse the order of the cells.

Li

 Excel usually saves to
> a tab-delimited text
> file, so this may be closer to what you want:
> 
>      my @row = reverse split(/\t/,$_);
> 
> or if you want to get fancy:
>       
>       chomp $_;
>       print join("\t",(reverse split(/\t/,$_)))."\n";
> 
> which is a shorter version of this:
> 
>       #Cut off the newline
>       chomp $_;
>  
>       #split the line into an array using tab delimiters      
>       my @row = split(/\t/,$_);
> 
>       #reverse the order of the elements of @row 
>       @row = reverse @row;
> 
>       #Use join to make a string out of @row, using tab
> as delimiter
>       print join("\t",@row);
> 
>       #add the newline back to the end of the line
>       print "\n";
>      
> 
> 
> P.S.  Please copy these to the list for two reasons:
>  1) I might end up
> being to busy to help you, and 2) you're probably
> not the first person
> to have this problem, so it is good to get the
> information out there for
> other beginners.
> 
> 
> 
> 
> -----Original Message-----
> From: chen li [mailto:[EMAIL PROTECTED] 
> Sent: Friday, April 14, 2006 2:44 PM
> To: Timothy Johnson
> Subject: RE: reverse the order of a row in Excel
> 
> Hi Timothy,
> 
> This is my code to get the job done and it is what I
> want. (Sorry I do not have much knowledge about perl
> and OO programming.)
> 
> #reverse a list
> my $file='test2.txt';
> open (FILEHANDLE,$file) or die" File $file can't be
> open!!!"; 
> 
> # read the file 
> while(<FILEHANDLE>){
>       chomp;
>       my @row=reverse(@row=split(//));
>       print @row, "\n";       
> }
> close FILEHANDLE;
> 
> exit;
> 
> 
> Li
> 
> --- Timothy Johnson <[EMAIL PROTECTED]> wrote:
> 
> > 
> > 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>
> > 
> > 
> > 
> 
>  
> 
> 
> --
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> 
=== message truncated ===


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-- 
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