CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
Converting excel to .csv file - datetime format problem



Apr 24, 2014, 8:43 AM

Post #1 of 2 (11676 views)
Converting excel to .csv file - datetime format problem Can't Post

Hi I am new to perl programming: I am using the below code to convert excel file to CSV file and the format of date changes

source: file.xls has dates as below:

TDate 20/03/2014 08:07

VDate 26/03/2014

IDate 20/03/2014 08:07

Output of the .csv files looks as (changes the format when time exists in it).

TDate; 3-20-14 0:08

VDate 26/03/2014

IDate 3-20-14 8:07

Attached perl script program code file as well. Please help me getting the same date values as source in target .csv as well

#!/usr/bin/perl -w 
# For each tab (worksheet) in a file (workbook),
# spit out columns separated by ",",
# and rows separated by c/r.

use Spreadsheet::ParseExcel;
use strict;
my $file='output2.csv';

open STDOUT, ">", $file or die "$0: open: $!";
open STDERR, ">&STDOUT" or die "$0: dup: $!";

my $filename = shift || "/home/src/file.xls";
my $e = new Spreadsheet::ParseExcel;
my $eBook = $e->Parse($filename);
my $sheets = $eBook->{SheetCount};
my ($eSheet, $sheetName);

foreach my $sheet (0 .. $sheets - 1) {
$eSheet = $eBook->{Worksheet}[$sheet];
$sheetName = $eSheet->{Name};
#print "#Worksheet $sheet: $sheetName\n";
next unless (exists ($eSheet->{MaxRow}) and (exists ($eSheet->{MaxCol})));
foreach my $row ($eSheet->{MinRow} .. $eSheet->{MaxRow}) {
foreach my $column ($eSheet->{MinCol} .. $eSheet->{MaxCol}) {
if (defined $eSheet->{Cells}[$row][$column])
print $eSheet->{Cells}[$row][$column]->Value . ",";
} else {
print ",";
print "\n";

(This post was edited by FishMonger on Apr 24, 2014, 9:26 AM)


Apr 26, 2014, 3:24 PM

Post #2 of 2 (11584 views)
Re: [vsmeruga] Converting excel to .csv file - datetime format problem [In reply to] Can't Post

It may be easier to reformat the date with perl than to figure out how to make excel or the moddule do it for you.
Good Luck,


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives