in reply to Perl OLE Excel Sort By Color

If you already have working Visual Basic code, why don't you convert that code to Perl? It's pretty straightforward.

  1. Add use Win32::OLE::Constant 'Microsoft Excel';
  2. Convert all . to ->
  3. Add $ before all variable names
  4. Convert all named arguments / keywords to hashes:
    MyFunction( Foo= bar )

    becomes

    MyFunction( { Foo => $bar } );
  5. Replace False by undef and True by 1
  6. For bonus points, eliminate all ActiveWorksheet calls and replace them by assignments to variables

Replies are listed 'Best First'.
Re^2: Perl OLE Excel Sort By Color
by martinslmn (Novice) on Jun 02, 2015 at 12:43 UTC
    Hi, The current converted code I have is
    my $sheet1 = $workbook->Worksheets(1)->{Name}; $sheet1=$workbook->Worksheets($sheet1); $sheet1->Activate; my $rows=$sheet1->UsedRange->Rows->{'Count'}; $sheet1->Sort->SortFields->Add($sheet1->Range("A2:A" . $rows),xlSortOn +CellColor, xlAscending, xlSortNormal)->SortOnValue->{Color} = RGB(255 +, 0, 0);
    I am getting the error on RGB, and I don't know what is the replacement for it in Perl. Kindly help.

      Looking at Corion's google search I found this link where someone claims that

      RGB(a,b,c)=a*1+b*256+c*256^2

      Easy enough to translate into Perl:

      sub RGB { my ( $red, $green, $blue ) = @_; return $red + ($green<<8) + ($blue<<16); }