in reply to Re: Question about Win32::OLE and Excel
in thread Question about Win32::OLE and Excel

Okay now you have convinced me, to convert it into perl, but I hae meet some problems:

How can i "translate" the following VB code into perl? I tried several times but i didn't get it.

Columns(SelectedHeaderColumn).Select For Each Entry In Selection $currentsheet->Columns($SelectedHeaderColumn)->{Select}; #this is okay + and does what it is suposed to, select the right column #here comes the problem: this is one example how I tried it my $selection = $currentsheet->Selection; foreach my $Line (in $selection){

Replies are listed 'Best First'.
Re: Re: Re: Question about Win32::OLE and Excel
by Grygonos (Chaplain) on Apr 20, 2004 at 17:49 UTC

    i'm not sure what your code is trying to accomplish.. but when I want to loop through columns I use the following struct

    for (qw(A B C D E)) { $sheet->Range($_."1:".$_."5")->Font->{Bold} = 1; }
    That code takes 5 letters, and loops over them, populating $_ with the current letter each time. The statement inside the loop, Sets the Bold property for rows 1 through 5 of the current column. Is this helping you at all? Try and repost what you want this code to do.

    Hope I'm helping

    Grygonos
      The code should select a column, like: my $SelectedHeaderColumn = "A:A"; #then select the column: $currentsheet->Columns($SelectedHeaderColumn)->{Select}; #then go through all entries in this column ??? in VB this was: 'define Column: Dim SelectedHeaderColumn As String SelectedHeaderColumn = "A:A" 'Select the Column: Columns(SelectedHeaderColumn).Select 'then go through all Entires in the Column: For Each Entry In Selection Debug.Print Entry.Value Next And now I tried to translate the For loop into perl, but I didn't get it... Thanks for help
        my $excel = Win32::OLE->new('Excel.Application'); my $book = $excel->Workbooks->Open("C:/test.xls"); my $sheet = $book->Worksheets('Sheet1'); $col = $your_column_to_loop_over for(0..$your_row_limit) { print $sheet->Range($col.$_)->{Value}; }
        That should do what you want. See if you can understand how the translation works.

        Grygonos