Seems plenty of folks have asked for help in figuring
out how to sort in excel.  I have a similiar need, and
reviewed quite a bit of code but nothing seems to
work.  Has anyone had success in the area?  Here's a
sample program of what I'm working on.  In this sample
the spreadsheet has values only in column A.  I've
tried numeous variations and have yet to hit on
something that works:
-----------------------------------------------
use Win32;
use Win32::OLE 'with'; 

my $Class = "Excel.Application";

my $Excel = Win32::OLE->GetActiveObject($Class);
if (! $Excel) {
   $Excel = Win32::OLE->new($Class, \&QuitApp)
               || die "Could not create an OLE
'$Class' object";
}

$Excel->{Visible} = 1;

my $File = GetFileName();

# Open the Excel File and Create Reference
my $Workbook = $Excel->Workbooks->Open( $File );

# Set Active Worksheet and Create Reference
my $Worksheet = $Workbook->Worksheets(1);
with ( $Worksheet->Range("A1:A6")->{Sort},
                   Key1 => $Worksheet->Range("A1"),
                   Order1 => xlAscending );
#with ( $Range->{Sort},
#       Key1 => "A",
#       Order1 => xlAscending,
#       Header => xlNos,
#       OrderCustom => 1,
#       MatchCase => "False",
#       Orientation => xlTopToBottom ) ;

# Close It Up, 1 = Save on Close
$Excel->ActiveWorkbook->Close(1);
$Excel->Quit();
exit;
#
sub QuitApp {
   my($ComObject) = @_;
   print "Quitting " . $ComObject->{Name} . "\n";
   $ComObject->Quit();
}
#
sub GetFileName {

   my $File = $ARGV[0];
   my ($xit);
        
   if ( $File ) {
      return($File);
   }
        
   $xit = 0;
   until ($xit) {
      print "\nEnter Complete Path/Filename for Excel
Spreadsheet: ";
      $File = <STDIN>;
      chomp $File;

      # Test to make sure the file exists.
      if ( ! (-e $File) ) {
         print "The file you have provided does not
exist.\n";
         redo;
      }

      # Test to make sure the file has a valid file
extension
      $_ = substr($File,(length($File) - 3), 3);
      if ( ! /xls/i) {
         print "The file you have provided has an
invalid extension.\n";
         redo;
      }
      $xit = 1;
   }
   return($File);                       
}





__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices.
http://auctions.yahoo.com/
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

Reply via email to