in reply to Error getting number of rows in excel.

I'm a business analyst who does this kind of thing for a living... I pull reports from legacy systems and format them into Excel reports. I know, my life sucks.

Fortunately for me, I discovered perl and now do all my data munging outside of Excel. However, I used to write VBA macros to do the job.

If you want to find the last row in a range of data, the VBA construct is the following (assuming your block of data starts in column A):

lastRow = activeSheeet.range("A65536").end(xlUp)

This translates into perl as...

$last_row = $active_sheet->Range('A65536')->End(-4121)

(This assumes that the value of the 'xlUp' constant in VBA is constant across different copies and versions of Excel. To check, open the macro editor in Excel (F11), open the "Immediate" window under the View menu and type xlUp to obtain its value.

Alternatively, you could figure out what I could not and determine how to bring those constants into perl. I've yet to figure out how to pull that off - I know they're in the OLE Excel object, I just don't know how to reference them.

Anyone?

Hope that helped.

Cluka

Replies are listed 'Best First'.
Re: Re: Error getting number of rows in excel.
by jmcnamara (Monsignor) on Oct 11, 2002 at 22:15 UTC

    You can import the OLE constants using Win32::OLE::Const:
    use Win32::OLE::Const 'Microsoft Excel'; print xlUp; # gives -4162

    --
    John.