Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Re: Re: Re: Reading from Excel

by Hrvoje (Initiate)
on Aug 09, 2002 at 15:53 UTC ( #188949=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://188949]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2021-12-01 14:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (10 votes). Check out past polls.

    Notices?