Hello poopay, and welcome to the Monastery!
As explained in Excel::Writer::XLSX#DATES_AND_TIME_IN_EXCEL, Excel dates are stored internally as real numbers, but Spreadsheet::BasicRead and its relatives read dates in as strings. This means you have to manually extract the date from your input data, then convert it to a more convenient form. Here is one way to do this (adapted from the example given in the module documentation just referenced):
#! perl use strict; use warnings; use Excel::Writer::XLSX; use Spreadsheet::BasicRead; my $workbook = Excel::Writer::XLSX->new('perl.xlsx') or die "$!"; my $worksheet = $workbook->add_worksheet(); my @files = ('data.xlsx'); foreach my $file (@files) { my $excel = new Spreadsheet::BasicRead($file) or die "$!"; my $row = 0; while (my $dataref = $excel->getNextRow()) { foreach my $date (@$dataref[7 .. 8]) # Columns H and I { $date =~ s[ ^ (\d{1,2}) / (\d{1,2}) / (\d{4}) $ ] [ sprintf("%4d-%02d-%02d", $3, $2, $1) ]ex; } $worksheet->write_row($row++, 0, $dataref); } }
Note: this approach will work only if you know the format(s) of the dates in your input files — or if you are prepared to expand the regex to allow for all the date formats you may encounter.
Update 1: I tested the above on an input file data.xlxs with Row 1 populated as follows:
1.1 2.1 3.3 4.4 5.5 6.6 7.7 9/15/2012 7/18/196 +0 8.8 9.9
The output file, perl.xlxs, had as Row 1:
1.1 2.1 3.3 4.4 5.5 6.6 7.7 2012-15-09 1960-18 +-07 8.8 9.9
as required.
Hope that helps,
Update 2: Why did you have a do {} block in your code snippet? As far as I can see, it serves no purpose there.
Athanasius <°(((>< contra mundum
In reply to Re: Not sure why perl-generated spreadsheet has formatting issues
by Athanasius
in thread Not sure why perl-generated spreadsheet has formatting issues
by poopay
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |