ravi179 has asked for the wisdom of the Perl Monks concerning the following question:
how to Read the data in excel and store it as Hash?
My Excel is in given format.
ID NAME Degree Collage
1 Teja B.Tech NIT
M.Tech IIT(the problem is in converting this line)
2 Ravi B.tech MIT
I am in a position to convert a Excel table into a key value pairs.Please help me.Thanks in advance.
use Spreadsheet::ParseExcel; $filename = shift || "Book2.xls"; $e = new Spreadsheet::ParseExcel; $eBook = $e->Parse($filename); $sheets = $eBook->{SheetCount}; $eSheet = $eBook->{Worksheet}[$sheet]; for my $row(1 .. $eSheet->{MaxRow}) { next unless (defined $eSheet->{Cells}[$row][$col]); my $master_key=$eSheet->{Cells}[$row][0]->Value; for my $col(1 .. $eSheet->{MaxCol}) { next unless (defined $eSheet->{Cells}[$row][$col]); my $key= $eSheet->{Cells}[0][$col]->Value; my $value = $eSheet->{Cells}[$row][$col]->Value; $data{$master_key}->{($key)}=$value; } } for $id(sort keys %data) { print "$id:\n "; for $role(sort keys%{$data{$id}}) { print " $role=$data{$id}{$role}\n"; } print "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Converting Excel to Hash
by Corion (Patriarch) on Jan 03, 2017 at 08:04 UTC | |
by ravi179 (Novice) on Jan 03, 2017 at 08:40 UTC | |
by Corion (Patriarch) on Jan 03, 2017 at 08:46 UTC | |
by ravi179 (Novice) on Jan 03, 2017 at 15:20 UTC | |
by Corion (Patriarch) on Jan 03, 2017 at 15:31 UTC | |
| |
by poj (Abbot) on Jan 03, 2017 at 16:19 UTC | |
|