Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Unable to Extract Data from Excel

by natty_dread (Acolyte)
on Oct 26, 2003 at 11:33 UTC ( [id://302193]=perlquestion: print w/replies, xml ) Need Help??

natty_dread has asked for the wisdom of the Perl Monks concerning the following question:

I'm unable to get my script to extract data from a spreadsheet using the logic in the script below. I receive the following error when trying to open the workbook:

Global symbol "@file" requires explicit package name at line 7.

I've even tried initializing the array with no values and receive different errors...
Here's the script I'm trying... use strict; use Win32::OLE; my $excel = Win32::OLE-> new ('Excel.Application', 'Quit') or die ("Ca +n't create object: ", Win32::OLE->LastError()); my $file = 'C:\EndPoint scripts\test.xls'; my $workbook = $excel->Workbooks->Open(@file) or die ("Can't open Work +book: ", Win32::OLE->LastError()); my $worksheet = $workbook->Worksheets(1); my $range = $worksheet->Range("A1:B2") -> {'Value'}; $workbook -> close; foreach my $row (@$range) { foreach my $cell (@$row) { print "$cell\t"; } print "\n"; }

Replies are listed 'Best First'.
Re: Unable to Extract Data from Excel
by Jaap (Curate) on Oct 26, 2003 at 11:50 UTC
    On this line:
    my $workbook = $excel->Workbooks->Open(@file) or die ...
    replace @file with $file.
      Thanx...that worked.
        can you guys post the code. i am new to this community and jus started learning perl. I would appreciate if you can post the code here. thank you.
Re: Unable to Extract Data from Excel
by PERLscienceman (Curate) on Oct 26, 2003 at 11:45 UTC
    Greetings Fellow Monk!

    May I suggest that you take a look at this CPAN Module: Spreadsheet::ParseExcel. Its primary claim to fame is to extact data from an Excel file, I have found it to be quite useful. Good Luck.
    Additional Note: If, in the future you should find the need to write/create an Excel using a Perl Module there is also: Spreadsheet::WriteExcel.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://302193]
Approved by PERLscienceman
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-25 20:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found