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

I am using Spreadsheet::XLSX to read a standard excel spreadsheet. The last column is a date field.

However, it doesnt appear to be converting correctly as a dumper of the cell shows

$VAR1 = bless( { 'Type' => 'Date', 'Val' => 'MM/03/2017 HH:29:59', '_Value' => 'MM/03/2017 HH:29:59', 'Format' => 'MM/dd/yyyy HH:mm:ss' }, 'Spreadsheet::ParseExcel::Cell' );

Relevent code is pretty much standard from what I found on the web

foreach my $row ($sheet -> {MinRow} .. $sheet -> {MaxR +ow}) { my($first) = 1; $sheet -> {MaxCol} ||= $sheet -> {MinCol}; foreach my $col ($sheet -> {MinCol} .. $sheet + -> {MaxCol}) { my $cell = $sheet -> {Cells} [$row] [$ +col]; if ($cell) { unless (defined($firstrow)) { print CSV ',' unless ( +$first); print CSV $cell -> va +lue(); } $first = undef; $last = $cell -> value(); print Dumper($cell); } }

Anybody have any ideas?

2017-08-04 Athanasius added code tags

Replies are listed 'Best First'.
Re: Problem with Spreadsheet::XLSX (Date formatting)
by 1nickt (Canon) on Aug 03, 2017 at 16:55 UTC

    Use Spreadsheet::Read and specify the date format used in your spreadsheet in the call to ReadData():

    use Spreadsheet::Read qw/ ReadData rows /; my $format = 'yyyy-mm-dd'; # or whatever your date/time format is my $workbook = ReadData('my_file.xlsx', dtfmt => $format); my @rows = rows( $workbook->[1] );

    Spreadsheet::Read also provides the commandline tool xlscat which extracts all or part of a spreadsheet into a CSV structure, as you appear to want to do. xlscat in turn supports the dtfmt command option. See the docs.

    Hope this helps!


    The way forward always starts with a minimal test.
Re: Problem with Spreadsheet::XLSX (Date formatting)
by Tux (Canon) on Aug 03, 2017 at 20:17 UTC

    Any specific reason you are using Spreadsheet::XLSX instead over Spreadsheet::ParseXLSX?

    The former is undermaintained and buggy, whereas the latter is trying to be Spreadsheet::ParseExcel compatible.

    Personally I would love to see all programs that use "M/D/Y" date formatting die and auto-remove itself, but somehow, the US citizens won't learn about logic


    Enjoy, Have FUN! H.Merijn
Re: Problem with Spreadsheet::XLSX (Date formatting)
by thanos1983 (Parson) on Aug 03, 2017 at 15:31 UTC

    Hello kelliott,

    Welcome to the Monastery. Please use <code><code> tags so we can view your stdout.

    Also provide us with a sample of code that replicates your problem so we can experiment locally individually.

    Update: Similar question and proposed solution(s) Spreadsheet::ParseExcel and Dates.

    Looking forward to your update, BR.

    Seeking for Perl wisdom...on the process of learning...not there...yet!