By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,661 Members | 1,330 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,661 IT Pros & Developers. It's quick & easy.

Read an excel file

P: 41
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
Share this Question
Share on Google+
7 Replies


nithinpes
Expert 100+
P: 410
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

P: 41
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
Expert 100+
P: 410
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

P: 41
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
Expert 100+
P: 410
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

P: 41
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
Expert 100+
P: 410
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.