469,306 Members | 1,901 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

Read an excel file

Hi,

Can anybody tell me how to read an excel file.

I have written a script, it is not working with multi sheets. And also i want to print all workshet present in the excel file.


use Spreadsheet::ParseExcel::Simple;
use strict;

my $xls = Spreadsheet::ParseExcel::Simple->read('file.xls');
foreach my $sheet($xls->sheets)
{
while ($sheet->has_data)
{
my @data = $sheet->next_row;
print "@data\n";
}
}

~Thanks.
Sep 24 '08 #1
7 9190
nithinpes
410 Expert 256MB
What error do you get?
The same script worked for me in reading and printing data from multiple sheets in an excel file.
Sep 24 '08 #2
Hi Nithin,

It is showing some error:

Can't call method "sheets" on an undefined value at read_excel.pl line 10.

~Thanks
Sep 24 '08 #3
nithinpes
410 Expert 256MB
Hi Nithin,

It is showing some error:

Can't call method "sheets" on an undefined value at read_excel.pl line 10.

~Thanks
That error means that it could not fetch the excel sheet. Are you sure it is in the same directory in which you are running the script?
If not, give the absolute path in filename.
Sep 24 '08 #4
Hi,

The script can't open that particular xls file.

i have also given the absolute path for that file & same error is showing.


~Thanks
Sep 24 '08 #5
nithinpes
410 Expert 256MB
Then, it is not the problem with the script. Make sure the user running the script has read permissions for the file.
Sep 24 '08 #6
Hi,

Now it is working fine...

It was not working because of my OS, after restarted it is working fine.

Can u please tell me how i knoe how many workseets is present in my excel file.


~Thanks
Sep 24 '08 #7
nithinpes
410 Expert 256MB
That is quite straight-forward. As you can see in your script, $xls->sheets returns an array of sheets in the excel file. The length of this array would be the number of sheets present.
Expand|Select|Wrap|Line Numbers
  1. my $sheets = $xls->sheets;
  2. print "There are $sheets sheets"; 
  3.  
Sep 24 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by wstsoi | last post: by
4 posts views Thread by sukhmeet | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.