http://qs321.pair.com?node_id=188949


in reply to Re: Re: Re: Reading from Excel
in thread Reading from 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.

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Reading from Excel
by dimmesdale (Friar) on Aug 09, 2002 at 18:50 UTC

    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.

Re:(5) Reading from Excel
by cacharbe (Curate) on Aug 09, 2002 at 19:23 UTC
    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