#!/usr/bin/perl use strict; use warnings; use Spreadsheet::ParseExcel; my $file = "\\lebensraum\\perl\\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; print "$siteid\n";} else {print "Could not find column Site Number\n";} if ($sheet->{Cells}[0][$col]->{Val} eq "Site Name") { my $name = $col; print "$name\n";} else {print "Could not find column Site Name\n";} if ($sheet->{Cells}[0][$col]->{Val} eq "City") { my $city = $col; print "$city\n";} else {print "Could not find column City\n";} } #iterate through spreadsheet rows and extract site.siteid,site.name & site.city foreach my $row ($sheet->{MinRow}+1 .. $sheet->{MaxRow}) { my $site_number = $sheet->{Cells}[$row][my $siteid]->{Val}; my $site_name = $sheet->{Cells}[$row][my $name]->{Val}; my $site_city = $sheet->{Cells}[$row][my $city]->{Val}; print "$site_number\n"; print "$site_name\n"; print "$site_city\n"; } } exit;