473,386 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 9458
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

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

Similar topics

10
by: QQ | last post by:
I am trying to read data from Excel files I use the following codes, however, it didn't work Can anyone tell me what the format excel files have, what I should do to read it from C? Thanks a...
0
by: Peter | last post by:
I am having a problem reading an Excel file that is XML based. The directory I am reading contains Excel files that can be of two types. Either generic Microsoft based or XML based. I am reading...
1
by: Roger Twomey | last post by:
I have a form that allows a user to upload a microsoft Excel Spreadsheet. (I am testing with one created in Excel 2000) The spreadsheet is uploaded correctly. It is then supposed to be read...
2
by: Reza Solouki | last post by:
Hello, I never had to do anything with office tools programmatically till now(I guess there is first time for everything), so this might be a very silly and simple question for some of you. Any...
4
by: Seok Bee | last post by:
Dear Experts, I have created a script to extract the Event Logs from the system into an excel sheet. The logs are separated into 2 worksheets (Application Log and System Log). After this excel...
1
by: ashok0866 | last post by:
I had created a macro to read data from an excel sheet and write the values to a text file. I had used "ActiveSheet.Range("GB" & k).Value" command to read the values from the excel. The issue...
2
by: wstsoi | last post by:
hi I have to read images from spreadsheet, is it possible to do with php?
4
by: sukhmeet | last post by:
Hi, I am trying to load a csv file in Iframe element. I just want to load it as a text file. however when i load the file in iframe it asks to open the file and finally opens it with excel in IE...
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.