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

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
  • Comment on Re: Re: Re: Re: Question about Win32::OLE and Excel

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Question about Win32::OLE and Excel
by Grygonos (Chaplain) on Apr 21, 2004 at 11:38 UTC
    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
      Yes that was it, Thanks a lot...

      Here comes my next Problem: the VB Code is sthe following:

      Set RangeofChard = Union(Range(Cells(ChardRowStart, 1), Cells(ChardRow +End, 1)), _ Range(Cells(ChardRowStart, UsedCol), Cells(Ch +ardRowEnd, UsedCol)), _ Range(Cells(ChardRowStart, MaintCol), Cells(C +hardRowEnd, MaintCol)), _ Range(Cells(ChardRowStart, OtherUsedCol), Cel +ls(ChardRowEnd, OtherUsedCol)))

      This had created a Range for a chart, the range looked like this: "A2:A4,B2:B4, E2:E4 ..."

      Now Ive tried to convert it to perl code: but there are always Errorcodes, the problem is, that i cannot simply put it into an string because the Column indixes are numeric like 1,2,3... but for the range they must be converted to "A,B,C..." but I dont know how to make this?

      If i simply try this for example:

      my $Range = $currentsheet->Union($currentsheet->Range($currentsheet->C +ells($HeaderRow, 1), $currentsheet->Cells($ToIndex, 1)), $currentsheet->Range($currentsheet->Cells($He +aderRow, $UsedCol), $currentsheet->Cells($ToIndex, $UsedCol)), $currentsheet->Range($currentsheet->Cells($He +aderRow, $MaintCol), $currentsheet->Cells($ToIndex, $MaintCol)), $currentsheet->Range($currentsheet->Cells($He +aderRow, $OtherUsedCol), $currentsheet->Cells($ToIndex, $OtherUsedCol +))); print "$Range\n";
      Then Range is empty...

      I think this will be the last problem, because ist is at the end of my macro...

      Thanks for help

      UPDATE: I dont know why but all my line breaks are gone

      Edited by Chady -- fixed formatting, added code tags.

      UPDATE: Why are my linebreaks missing? I don't understand whythe following code does not what it is suposed to to: #My Range: my $RangeSting = "A$HeaderRow:A$ToIndex,D$HeaderRow:D$ToIndex,F$HeaderRow:F$ToIndex,H$HeaderRow:H$ToIndex"; #Printed example is: A2:A8,D2:D8,F2:F8,H2:H8 #then a chart is created: my $Chart = $Excel->Charts->Add; $Chart->{ChartType} = xlColumnClustered; $Chart->SetSourceData({Source => $currentsheet->Range($RangeSting) , PlotBy => xlColumns}); But then The chart is empty and I don't understand why... when I record a makro exactly the same is standing there: eg.: ActiveChart.SetSourceData Source:=Sheets("INF1").Range( _ "A2:A8,D2:D8,F2:F8,H2:H8"), PlotBy:=xlColumns I don't see my mistake here... please help me..