Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi. I am really new using perl (by new I mean I have 3 days using it :s ) and I was requested to create an application that reads an Excel file and load info into the database. I was able to find how to do this, It worked perfectly on my computer, but when I try to load it in the web server for it to be accessed remotely, I get weird information as a result. I read about this and I found out that it has something to do with the way perl represents the different data_types. Here is the info I get: Win32::OLE::Variant=SCALAR(0x2004638). This is what I get on fields that are date formatted in the excel spreadsheet. Can anyone help me find out why I get different results in both computers? and if there is any way I can convert this Win32::OLE::Variant=SCALAR(0x2004638) into the date I need to store? here is the code I use: (I have commented the place where I put the information into a bidimensional array to send it to a function that stores it to the DB, and replaced it for code that just prints it to the screen)
use Win32::OLE; my $acum = 0; my $file2Parse = "c:/failureFile.xls"; my @DBrow; my @DBResult; my $ref; $row = 1; $ex = Win32::OLE->GetActiveObject('Excel.Application'); $ex = Win32::OLE->new('Excel.Application') or die "Oops, canno +t start Excel"; # get a new workbook $book = $ex->Workbooks->Open($file2Parse) or die "no file open +ed"; # write to a particular cell $sheet = $book->Worksheets(1); while ($acum!=17) { $acum = 0; for ($column=1;$column<=17;$column++) { print $sheet->Cells($row,$column)->{Value}."||"; # $DBrow[$column-1] = $sheet->Cells($row,$column)->{Value +}; if ($sheet->Cells($row,$column)->{Value} eq "") { $acum++; } } if ($acum != 17) { # $DBResult[$row-1] = [@DBrow]; } $row++; } $book->Close; undef $book; undef $ex;
thanks in advance for any help you can give me.

Replies are listed 'Best First'.
Re: Data Types and Win32::OLE
by pc88mxer (Vicar) on Feb 26, 2008 at 15:48 UTC
    If I understand things correctly you might try this:

    $DBrow[$column-1] = $sheet->Cells($row,$column)->{Value}.'';
    This forces the expression to be converted to a string which is also what is being done in the print statement on the preceding line. So if the print statement is working, then doing this should give the same results in your database.

    The string Win32::OLE::Variant=SCALAR(0x2004638) is a textual representation of a perl reference which is like a pointer in C. In this case it is a pointer to an object of type/class Win32::OLE::Variant and the memory address of the object is 0x2004638.