Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Thanks so much for everyone's help. I am making progress. Changing the worksheet to Worksheet and then using just the file name for my xls file allowed me to parse the spreadsheet. However, the output of my parsing isn't correct and it looks like the breakdown is the capturing of the column data (e.g. $city =$col;) isn't carrying over to the row iteration. In my efforts to correct that I am encountering a compile error:
Global symbol "$siteid" requires explicit package name at ./excel.syr. +extract3.pl line 48. Global symbol "$name" requires explicit package name at ./excel.syr.ex +tract3.pl line 49. Global symbol "$address" requires explicit package name at ./excel.syr +.extract3.pl line 50. Global symbol "$city" requires explicit package name at ./excel.syr.ex +tract3.pl line 51. Global symbol "$state" requires explicit package name at ./excel.syr.e +xtract3.pl line 52. Global symbol "$zip" requires explicit package name at ./excel.syr.ext +ract3.pl line 53. Execution of ./excel.syr.extract3.pl aborted due to compilation errors +.
I imagine that the "explicit package name" issue is something the PerlMonks understand well, but I have to confess I don't know what it means or what to do about it. Here is my latest script:
#!/usr/bin/perl use strict; use warnings; use Spreadsheet::ParseExcel; my $file = "SAMReport.xls"; 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") { my $siteid = $col; } if ($sheet->{Cells}[0][$col]->{Val} eq "Site Name") { my $name = $col; } if ($sheet->{Cells}[0][$col]->{Val} eq "Address") { my $address = $col; } if ($sheet->{Cells}[0][$col]->{Val} eq "City") { my $city = $col; } if ($sheet->{Cells}[0][$col]->{Val} eq "State") { my $state = $col; } if ($sheet->{Cells}[0][$col]->{Val} eq "Zip Code") { my $zip = $col; } } #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]; my $site_name = $sheet->{Cells}[$row][$name]; my $site_address = $sheet->{Cells}[$row][$address]; my $site_city = $sheet->{Cells}[$row][$city]; my $site_state = $sheet->{Cells}[$row][$state]; my $site_zip = $sheet->{Cells}[$row][$zip]; #print captured output print "$site_number\n"; print "$site_name\n"; print "$site_address\n"; print "$site_city\n"; print "$site_state\n"; print "$site_zip\n"; } } exit;
Thanks again for everyone's kind assistance! Hagen

In reply to Re^4: 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 pondering the Monastery: (2)
As of 2024-04-26 03:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found