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


In reply to Re: Win32::OLE Excel: identify cell-format by davies
in thread Win32::OLE Excel: identify cell-format by Ratazong

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.