473,466 Members | 1,376 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Read an excel file

41 New Member
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 9460
nithinpes
410 Recognized Expert Contributor
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
dillipkumar
41 New Member
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 Recognized Expert Contributor
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
dillipkumar
41 New Member
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 Recognized Expert Contributor
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
dillipkumar
41 New Member
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 Recognized Expert Contributor
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...
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.