in reply to Re: Re: Reading from Excel
in thread Reading from Excel

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.

/update

Replies are listed 'Best First'.
Re: Re: Re: Re: Reading from Excel
by Hrvoje (Initiate) on Aug 09, 2002 at 15:53 UTC
    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.

      Update Well, cacharbe is probably right, so what I say may not be applicable. I'm glad that's never happened to me :) /update

      You don't modify anything in the program do you -- I mean modify anything in Excel with the program? The negative integer (overflow?) sounded familiar, but I didn't find it in the docs...

      (There was this, but I don't think it applies here)

      Randomly failing method calls It seems like modifying objects that are not selected/activated is som +etimes fragile. Most of these problems go away if the chart/sheet/doc +ument is selected or activated before being manipulated (just like an + interactive user would automatically do it).

      If you're modifying any of the values within the program it by be noteworthy to see that code -- maybe something went wrong there? But (as I suspect since you say you saw it in Excel correctly so I guess you're not modifying anything), you may want to go to the Parse Excel module listed by someone else below.

      The only thing that comes to mind is that you might be referring to a cell that is out of bounds -- but then Excel would proably raise an exception, so its probably not that.

      I tried to break linking for about 1/2 hour and failed to repeat your error, without recalculating the sheet and without $Book->UpdateLink({Name=> $Book->{LinkSources}}); So, allow me to suggest a course of action, if you please.

      Debug a little using Win32::OLE->LastError(). After you try to open your files, print Win32::OLE->LastError()."\n";, after you try to get the values, print Win32::OLE->LastError()."\n"; You get the idea.

      Something is happening that you are making assumptions about, and I think somewhere your assumptions are wrong, or as Inigo would say "I do not think it means what you think it means."

      Perhaps if you built an example that breaks but doesn't use proprietary files such that you could post the code. As I say, I tried to replicate your error using the code given without any luck, and I can post my code if you like to double check my understanding vs. your meaning.

      C-.

      ---
      Flex the Geek