Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Win32::OLE Excel: identify cell-format

by davies (Prior)
on Nov 16, 2011 at 10:05 UTC ( [id://938343]=note: print w/replies, xml ) Need Help??


in reply to Win32::OLE Excel: identify cell-format

The technique I usually use is to compare value to value2. I'm a little surprised at you using @val instead of $val, but strange things of which I was not aware appear to be happening with Excel dates.

use strict; use warnings; use diagnostics; use Win32::OLE; my $xl = Win32::OLE->new('Excel.Application'); $xl->{Visible} = 1; my $wb = $xl->Workbooks->Add(); for (2..$wb->Sheets->{Count}) { $wb->Sheets(2)->Delete; } my $cell = $wb->Sheets(1)->Cells(1,1); $cell->{Value} = '1/1/1'; my $v = $cell->Value; my $v2 = $cell->{Value2}; print "$$v $v2\n"; $cell->{Value} = '\'1/1/1'; $v = $cell->Value; $v2 = $cell->{Value2}; print "$v $v2\n";

As you will see, when you have a text string, Value and Value2 are the same, but when there is a date, Win32::Ole returns a reference for Value (VBA just returns the value - 01/01/2001 in this case). I don't know if the number held in the reference makes sense to you, but it doesn't to me. However, the important point is that if a cell contains a date, the two will differ. This applies whether the date is entered directly or is calculated via a formula (again, I'm unclear why you use the Formula property).

Rumour has been heard in the land of other cases where Value and Value2 differ. If they exist, they are very rare. I've certainly never needed to know about them.

Unless you know for sure that there will be no transatlantic confusion, you may have to watch out for date formats.

Regards,

John Davies

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2024-04-26 01:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found