Try
update : clear @datarow for header line.#!perl use strict; use Spreadsheet::ParseExcel; use Data::Dump 'dd'; my $filename = "Book2.xls"; my $e = new Spreadsheet::ParseExcel; my $eBook = $e->Parse($filename); my $eSheet = $eBook->{Worksheet}[0]; my $maxrow = $eSheet->{MaxRow}; my $maxcol = $eSheet->{MaxCol}; print "maxrow=$maxrow maxcol=$maxcol\n"; my %data = (); my @header = (); my @datarow = (); for my $row (0 .. $maxrow) { my %this_set=(); my $master_key; for my $col (0 .. $maxcol){ my $cell = $eSheet->{Cells}[$row][$col]; if (defined $cell){ $datarow[$col] = $cell->Value unless ($cell->Value eq ''); } else { next; } # header row if ($row == 0){ $header[$col] = $datarow[$col]; $datarow[$col] = ''; } else { if ($col == 0){ $master_key = $datarow[$col]; } else { my $key = $header[$col]; my $value = $datarow[$col]; $this_set{$key} = $value; } } } #print join ",",@datarow,"\n"; # Store our found set for that ID: if ($row > 0){ push @{ $data{ $master_key }}, \%this_set; } } dd \%data;
In reply to Re^7: Converting Excel to Hash
by poj
in thread Converting Excel to Hash
by ravi179
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |