finhagen has asked for the wisdom of the Perl Monks concerning the following question:
So my $worksheet variable prints as a HASH - which could be right but seems wrong to me. I have added a bunch of print statements in an effort to debug the problem, but most of those don't print. The DBI connection and insert statements work so I am not concerned about my mysql connection. My sense is the $workbook = Spreadsheet::ParseExcel::Workbook->Parse("\\lebensraum\\perl\\SAMReport.xls")or die "Unable to open $file\n"; statement is failing somehow but not in a way that reports an error. However, I am new to this module so I could easily be doing something else wrong. Any help would be greatly appreciated.Sinn:/lebensraum/perl # ./excel.syr.extract.pl \lebensraum\perl\SAMRep +ort.xls Made it so far HASH(0xc682e0)
#!/usr/bin/perl use DBI; use DBD::mysql; use CGI; use Spreadsheet::ParseExcel; # CONFIG VARIABLES $platform = "mysql"; $database = "smdb"; $host = "Sinn"; $port = "3306"; $tablename = "site"; $user = "user"; $pw = "password"; #DATA SOURCE NAME $dsn = "dbi:mysql:smdb:localhost:3306"; # PERL DBI CONNECT (RENAMED HANDLE) $dbh = DBI->connect($dsn, $user, $pw)or die "Unable to connect: $DBI:: +errstr\n"; #$dbh->do("insert into site (siteid,name,city) values # (12345, \'BXB-200\',\'Boxborough\')"); #$cgi = new CGI; $file = "\\lebensraum\\perl\\SAMReport.xls"; print "$file\n"; $workbook = Spreadsheet::ParseExcel::Workbook->Parse("\\lebensraum\\pe +rl\\SAMReport.xls")or die "Unable to open $file\n"; print "Made it so far\n"; print "$workbook\n"; #locate columns in the spreadsheet from which we want to extract data foreach $sheet (@{$workbook->{worksheet}}) { print "Sheet number $sheet\n"; foreach $col ($sheet->{MinCol} .. $sheet->{MaxCol}) { if ($sheet->{Cells}[0][$col]->{Val} eq "Site Number") { $siteid = $col; print "$siteid\n";} #else print "Could not find column Site Number\n";} if ($sheet->{Cells}[0][$col]->{Val} eq "Site Name") { $name = $col; print "$name\n";} #else print "Could not find column Site Name\n";} if ($sheet->{Cells}[0][$col]->{Val} eq "City") { $city = $col; print "$city\n";} #else print "Could not find column City\n";} } print"Column find completed successfully - moving on to row find\n"; #iterate through spreadsheet rows and extract site.siteid,site.name & +site.city foreach $row ($sheet->{MinRow}+1 .. $sheet->{MaxRow}) { $site_number = $sheet->{Cells}[$row][$siteid]->{Val}; $site_name = $sheet->{Cells}[$row][$name]->{Val}; $site_city = $sheet->{Cells}[$row][$city]->{Val}; print "$site_number\n"; print "$site_name\n"; print "$site_city\n"; $dbh->do("insert into site (siteid,name,city) values (\$site_number, \'$site_name\',\'$site_city')"); } #print $cgi->header(); #print <<EOF #<html> #<head> #<title>Data has been uploaded #<head> #<body> #Thank you. #</body> #</html> #EOF #; } exit;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Spreadsheet::ParseExcel Script Fails to Parse (access) Excel Spreadsheet
by runrig (Abbot) on Sep 19, 2008 at 21:51 UTC | |
Re: Spreadsheet::ParseExcel Script Fails to Parse (access) Excel Spreadsheet
by graff (Chancellor) on Sep 20, 2008 at 04:11 UTC | |
Re: Spreadsheet::ParseExcel Script Fails to Parse (access) Excel Spreadsheet
by Narveson (Chaplain) on Sep 19, 2008 at 21:41 UTC | |
by finhagen (Sexton) on Sep 19, 2008 at 22:22 UTC | |
by bmann (Priest) on Sep 19, 2008 at 22:58 UTC | |
by finhagen (Sexton) on Sep 20, 2008 at 05:06 UTC | |
by Anonymous Monk on Sep 20, 2008 at 06:58 UTC | |
|