Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Thanks so much. Using our $var did the trick and my script is functioning properly now. Here is the final version:
#!/usr/bin/perl use strict; use warnings; use DBI; use DBD::mysql; use Spreadsheet::ParseExcel; # DBI configuration variables my $platform = "mysql"; my $database = "smdb"; my $host = "Sinn"; my $port = "3306"; my $tablename = "site"; my $user = "user"; my $pw = "password"; #Data source name my $dsn = "dbi:mysql:smdb:localhost:3306"; # PERL DBI connection handle my $dbh = DBI->connect($dsn, $user, $pw)or die "Unable to connect: $DB +I::errstr\n"; #xls file to be parsed my $file = "SAMReport.xls"; #global variables our $siteid; our $name; our $address; our $city; our $state; our $zip; my $workbook = Spreadsheet::ParseExcel::Workbook->Parse($file)or die " +Unable to open $file\n"; #locate columns in the spreadsheet from which we want to extract data foreach my $sheet (@{$workbook->{Worksheet}}) { print "Sheet number $sheet\n"; foreach my $col ($sheet->{MinCol} .. $sheet->{MaxCol}) { if ($sheet->{Cells}[0][$col]->{Val} eq "Site Number") { $siteid = $col; print "$siteid\n"; } if ($sheet->{Cells}[0][$col]->{Val} eq "Site Name") { $name = $col; print "$name\n"; } if ($sheet->{Cells}[0][$col]->{Val} eq "Address") { $address = $col; print "$address\n"; } if ($sheet->{Cells}[0][$col]->{Val} eq "City") { $city = $col; print "$city\n"; } if ($sheet->{Cells}[0][$col]->{Val} eq "State") { $state = $col; print "$state\n"; } if ($sheet->{Cells}[0][$col]->{Val} eq "Zip Code") { $zip = $col; print "$zip\n"; } } #iterate through spreadsheet rows and extract site.siteid, site.name, +site.address, site.city, site.state, site.zip foreach my $row ($sheet->{MinRow}+1 .. $sheet->{MaxRow}) { my $site_number = $sheet->{Cells}[$row][$siteid]->{Val}; my $site_name = $sheet->{Cells}[$row][$name]->{Val}; my $site_address = $sheet->{Cells}[$row][$address]->{Val}; my $site_city = $sheet->{Cells}[$row][$city]->{Val}; my $site_state = $sheet->{Cells}[$row][$state]->{Val}; my $site_zip = $sheet->{Cells}[$row][$zip]->{Val}; $dbh->do("insert into site (indate,sitei +d,name,address,city,state,zip) values (CURDATE(),\'$site_number\',\'$site_name\',\'$site_address +\',\'$site_city',\'$site_state\',\'$site_zip\')"); } } exit;

In reply to Re^6: Spreadsheet::ParseExcel Script Fails to Parse (access) Excel Spreadsheet by finhagen
in thread Spreadsheet::ParseExcel Script Fails to Parse (access) Excel Spreadsheet by finhagen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-18 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found