Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Spreadsheet::ParseExcel::Simple

by hpuxperl (Initiate)
on May 24, 2003 at 14:43 UTC ( [id://260586]=perlquestion: print w/replies, xml ) Need Help??

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

I am very new to Perl, and I was wondering if anyone had a commented example of how to use this module to ask for columns of data you want out of a excel file you specify, and copy them to a text file you specify. The data fields are named and are in separate columns. The data for any specified item is in the same row. Example of flow: What is your excel file? Answer: /tmp/carlist.xls What columns do you want? Vin model year (These would be column headers) What is the output text file name (just text, not csv/commas) It write file. Thanks

Replies are listed 'Best First'.
(jeffa) Re: Spreadsheet::ParseExcel::Simple
by jeffa (Bishop) on May 24, 2003 at 15:14 UTC
    You need to be concentrating on Learning Perl, as this code will not teach you all the parts you need to understand the whole. But here goes. All i did was grab the Synopsis code from the documention for Spreadsheet::ParseExcel::Simple and added a line to open the output file and line to print each row of data from the spreadsheet (seperated by a single space) to that output file. Since you didn't specify the column numbers for vin, model, and year ... well ... i'll just make them up! This code is untested:
    use strict; use warnings; my $xls = Spreadsheet::ParseExcel::Simple->read('/tmp/carlist.xls'); open OUT, '>', 'carlist.txt' or die $!; # these are made up: vin = 2, model = 4, year = 7 # put the right column numbers in here my @cols = (2,4,7); foreach my $sheet ($xls->sheets) { while ($sheet->has_data) { my @data = $sheet->next_row; print OUT, "@data[@cols]\n"; } }

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-12-07 15:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which IDE have you been most impressed by?













    Results (50 votes). Check out past polls.