Using Perl to Parse Excel File

M

mull0024

I'm using Perl to parse through an Excel file and I'm having trouble
with a date field. The date displays as 1-Jan-63 (for example) but
when the script runs it is printing as
"Win32::OLE::Variant=SCALAR(0x2626704)" If I print it using two $
signs then Perl prints it as "39047808"

So I guess I have two questions:

1) How does the extra $ sign change anything?

2) How do I get the data from Excel to print in Perl as dd/mm/yy ?

Thanks in advance for your thelp,
Chris
 
M

m

I'm using Perl to parse through an Excel file and I'm having trouble
with a date field. The date displays as 1-Jan-63 (for example) but
when the script runs it is printing as
"Win32::OLE::Variant=SCALAR(0x2626704)" If I print it using two $
signs then Perl prints it as "39047808"

So I guess I have two questions:

1) How does the extra $ sign change anything?

the extra $ is used to dereference an address. i have jst begun to learn
perl and this is what i have understood. its like go to address and pick
up the value there. so i think $($) would go to the address 0x2626704
and pick up whatever is there.
could it b like this?
 
C

Chris Mattern

I'm using Perl to parse through an Excel file and I'm having trouble
with a date field. The date displays as 1-Jan-63 (for example) but
when the script runs it is printing as
"Win32::OLE::Variant=SCALAR(0x2626704)" If I print it using two $
signs then Perl prints it as "39047808"

So I guess I have two questions:

1) How does the extra $ sign change anything?

It dereferences. If $date is a reference to the scalar (which is
what you have; the SCALAR(address) is what you get when you ask
Perl to print a reference), then $$date is the scalar it references.
2) How do I get the data from Excel to print in Perl as dd/mm/yy ?

perldoc Date::Format
Thanks in advance for your thelp,
Chris

--
Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
 
M

mull0024

"No documentation found for "Date::Format"."

"PPM> install Date-Format
Install package 'Date-Format?' (y/N): y
Installing package 'Date-Format'...
Error installing package 'Date-Format': Could not locate a PPD file for
package
Date-Format
PPM>"

Any advice on how to proceed?

Thanks again. Seems like the learning never ends with Perl ;-)

Chris
 
X

xhoster

I'm using Perl to parse through an Excel file and I'm having trouble
with a date field. The date displays as 1-Jan-63 (for example) but
when the script runs it is printing as
"Win32::OLE::Variant=SCALAR(0x2626704)"

That means that what you have is an object of the class
Win32::OLE::Variant. (and that class appears to use a scalar
as its storage mechanism.)
If I print it using two $
signs then Perl prints it as "39047808"

So I guess I have two questions:

1) How does the extra $ sign change anything?

It dereferences the object directly, bypassing any accessor methods
defined by the class (unless the class overrides scalar dereferncing).
2) How do I get the data from Excel to print in Perl as dd/mm/yy ?

I don't know. Did you try the docs for Win32::OLE::Variant?


Xho
 
C

Chris Mattern

"No documentation found for "Date::Format"."

"PPM> install Date-Format
Install package 'Date-Format?' (y/N): y
Installing package 'Date-Format'...
Error installing package 'Date-Format': Could not locate a PPD file for
package
Date-Format
PPM>"

Any advice on how to proceed?

Sorry, I don't use ActivePerl. Date::Format was part of standard install
with my perl, and I don't know anything about PPM.
Thanks again. Seems like the learning never ends with Perl ;-)

Chris

--
Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
 
K

Kiloran

I'm using Perl to parse through an Excel file and I'm having trouble
with a date field. The date displays as 1-Jan-63 (for example) but
when the script runs it is printing as
"Win32::OLE::Variant=SCALAR(0x2626704)" If I print it using two $
signs then Perl prints it as "39047808"

So I guess I have two questions:

1) How does the extra $ sign change anything?

2) How do I get the data from Excel to print in Perl as dd/mm/yy ?

Thanks in advance for your thelp,
Chris

Be aware that Excel's display format for dates is different to the
internally stored format. Dates are based on 01Jan1900 = 1, 02Jan1900 = 2,
17Feb2005 = 38400. I am sure Perl is reading the internal numeric, not the
displayed date format.

--Kiloran
 
B

Bart Lateur

I'm using Perl to parse through an Excel file and I'm having trouble
with a date field. The date displays as 1-Jan-63 (for example) but
when the script runs it is printing as
"Win32::OLE::Variant=SCALAR(0x2626704)" If I print it using two $
signs then Perl prints it as "39047808"
2) How do I get the data from Excel to print in Perl as dd/mm/yy ?

See if you can invoke a function with a name like "formatted", to make
Excel convert the internal format to displayed text format. Start
looking in the docs for Win32::OLE::Variant, as that is the kind of
object you're seeing here. Docs on CPAN:


<http://search.cpan.org/~jdb/libwin32-0.24/OLE/lib/Win32/OLE/Variant.pm>

Oh, look at that, there's a Date() method:

Date([FORMAT[, LCID]])
Converts the VARIANT into a formatted date string.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top