How to read an excel file when it saved with ".xls" but the error message
shows "File is in different format than specified by the file...
I am trying to read an excel sheet in perl using "Spreadsheet::ParseExcel"
module. If the file is saved in excel 97-2003 workbook, the module works
as expected. but for few files which throws an error as : "File is in a
different format than specified by the file extension" ,it doesn't get
read by this module. Could anyone please suggest something?
This code is to read a perticular column of an excel sheet.
use Spreadsheet::ParseExcel;
my $excel = Spreadsheet::ParseExcel::Workbook->Parse($FileName) or die
"Unable to open $FileName\n"; "$excel" is the object of workbook
my ($column_no, $sheet, $cell,$val);
my (@row_value)=();
print "\n\tReading the excel sheet\n";
foreach $sheet (@{$excel->{Worksheet}})
{
foreach my $col ($sheet->{MinCol} .. $sheet->{MaxCol})
{
For reading all the columns
$cell = $sheet->{Cells}[0][$col]->{Val} ;
$cell =~ /$column/ and $column_no=$col; "$column" contains the
name of that column which needs to be matched.
}
foreach my $row ($sheet->{MinRow}+1 .. $sheet->{MaxRow})
{
for reading the row according to the matched column name.
$val=$sheet->{Cells}[$row][$column_no]->{Val};
$val=~ /^$|^s+$/ and exit(0);
push (@row_value, $val); "@row_value" contains all the values of
row according to the matched column name.
}
}
No comments:
Post a Comment