Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Reading from Excel

by dimmesdale (Friar)
on Aug 09, 2002 at 14:28 UTC ( [id://188918] : note . print w/replies, xml ) Need Help??

in reply to Reading from Excel

my $value = $MYWORKSHEET->Range("B35")->Value();

Hmm... I'm pretty sure that value isn't a method, but a hash. Try saying:

my $value = $MYWORKSHEET->Range("B35")->{Value};

If this doesn't work, maybe some more information about the problem is needed.

Replies are listed 'Best First'.
Re: Re: Reading from Excel
by Hrvoje (Initiate) on Aug 09, 2002 at 15:05 UTC
    Thanks, but I've tried that, it's the same as Value()...
      Perhaps include some more code then. For example, how do you define $MYWORKSHEET; what's the call to Win32::OLE look like (are you opening an existing application), etc. And of course, maybe some of the spreadsheet (a reasonable amount) might be helpful. I've done some things with this before, and know the $sheet->Range("range")->{Value} is the correct "template" for getting at a value. Maybe you have the wrong sheet that you are accessing.

      Have you debugged any to narrow the problem down?

      update Maybe you should check out Win32::OLE Tips and Tricks with Excel.


        OK, here's the thing:
        my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32: +:OLE->new('Excel.Application', sub {$_[0]->Quit;}); my $Book = $Excel->Workbooks->Open(MYFILE, 1, 1); my $Sheet = $Book->Worksheets("WORKSHEETNAME"); $Sheet->Activate(); my $value = $Sheet->Range("SOMECELL")->{Value};

        I can't give you the spreadsheet, it's not mine, sorry (company policy)...
        When I print out the $value, I get the same result over and over (that is "-2146826259", and the expected result should be a positive number not bigger than 100,000). If I use:
        my $value = $Sheet->Range("SOMECELL")->Text();

        to retrieve cell data then I get #NAME!.
        I even tried debugging like this:
        if (ref($value)) { print $value->Type(); }

        and it returns "10", which is VT_ERROR. I repeat, when you look at it in Excel application, it displays the correct results.