Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Extract column of excel

by Tux (Monsignor)
on Jun 04, 2013 at 09:40 UTC ( #1036927=note: print w/ replies, xml ) Need Help??


in reply to Extract column of excel

So deling with CSV in a spreadsheet way. Install Text::CSV_XS and Spreadsheet::Read, and then:

use Spreadsheet::Read; my $ss = ReadData ("file.csv"); # Spreadsheet::Read indexes from 1. 0 is the control record/column my @sheet = $ss->[1]; # CSV has just 1 sheet my @column = $sheet->{cell}[4]; # 4th column, unformatted

Enjoy, Have FUN! H.Merijn


Comment on Re: Extract column of excel
Download Code
Replies are listed 'Best First'.
Re^2: Extract column of excel
by MynameisAchint (Novice) on Jun 04, 2013 at 11:39 UTC
    #!/bin/perl -w use strict; #variables you can change to suit your needs my $column_separator = ","; my $column_number = "1"; $column_number--; my $file="Working_On.csv"; open(FILE,"<","$file"); my @lines=<FILE>; close FILE; foreach my $line (@lines){ my @columns = split(/$column_separator/,"$line"); print $columns[$column_number],"\n"; }
    This is my code , but it does not read the entire csv file but reads from a particular cell of csv . I am working on one sheet only but the entries in column are about 1000. So can you suggest a way that the entire csv file is read at once

      Your code works fine! I have only added a chomp but that does not really make a difference...

      #!/bin/perl -w use strict; #variables you can change to suit your needs my $column_separator = ","; my $column_number = "2"; $column_number--; my @lines=<DATA>; foreach my $line (@lines){ chomp($line); my @columns = split(/$column_separator/,"$line"); print $columns[$column_number],"\n"; } __DATA__ 1,2,3,4 A,B,C,D
        Hey thank you for replying , now the problem I am having is that when code gets a blank cell it does not copy it to the array , it copies the next entry in column but I desire that even blank cells be copied as blank entry in array

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1036927]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2015-07-29 02:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls