Hi Monks!
I am trying to parse an Excel Spreadsheet to insert its values into a database, but I can’t get this code to work. It doesn’t print anything. I am getting "Use of uninitialized value in array element on line 44 and 46". Is there anything I am doing complete wrong, or a better way of doing this?
Here is the code:
#!/usr/bin/perl -w use strict; use CGI qw( -oldstyle_urls :standard ); use CGI::Carp qw ( fatalsToBrowser ); use Spreadsheet::ParseExcel; print header(); my $header_account; my $header_name; my $got_number; my $got_name; my $f_to_parse="accounts.xls"; my $workbook = Spreadsheet::ParseExcel::Workbook->Parse($f_to_parse)or + die "Unable to open $f_to_parse\n"; foreach my $page (@{$workbook->{Worksheet}}) { if ((defined $page->{MinCol}) && (defined $page->{MaxCol})) { foreach my $col ($page->{MinCol} .. $page->{MaxCol}) { if ($page->{Cells}[0][$col]->{Val} eq 'Account Numbers +') { $header_account = $col; } if ($page->{Cells}[0][$col]->{Val} eq 'Account Names') { $header_name = $col; } } } if ((defined $page->{MinRow}) && (defined $page->{MaxRow})) { foreach my $row ($page->{MinRow}+1 .. $page->{MaxRow}) { $got_number = $page->{Cells}[$row][$header_account]->{Val} +; $got_name = $page->{Cells}[$row][$header_name]->{Val}; } } } # here I will insert the values from the xls file into the database if + they are true. print "got_number=$got_number\n"; print "got_name=$got_name\n";

In reply to Help with Spreadsheet::ParseExcel by Anonymous Monk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.