Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^5: Reading Excel file in perl

by bitingduck (Chaplain)
on Nov 10, 2012 at 08:01 UTC ( #1003237=note: print w/replies, xml ) Need Help??

in reply to Re^4: Reading Excel file in perl
in thread Reading Excel file in perl

When I try this:

$worksheet1->write(0,1,"Modules", $format); $worksheet1->write(0,2,"Excel"); $worksheet1->write(0,3, "Dumper");

It gives me this:

Modules Excel Dumper

and when I do this (which is your code)

$worksheet1->write(0,1,"Modules", $format); $worksheet1->write(1,1,"Excel"); $worksheet1->write(2,1, "Dumper");

I get this:

Modules Excel Dumper

I think you just need to watch which index is for row and which is for column.

(EDITED because I misread and got backward what was desired vs. what you were getting)

Another EDIT:
and if I do this:

$worksheet1->write(0,0,"A1"); $worksheet1->write(0,1,"B1"); $worksheet1->write(0,2, "C1"); $worksheet1->write(1,0,"A2"); $worksheet1->write(1,1,"B2"); $worksheet1->write(1,2, "C2"); $worksheet1->write(2,0,"A3"); $worksheet1->write(2,1,"B3"); $worksheet1->write(2,2, "C3");

I get:

A1 B1 C1 A2 B2 C2 A3 B3 C3

Where each of the contents is also the name of the cell. Normally you'd do something like that with a nested loop

Replies are listed 'Best First'.
Re^6: Reading Excel file in perl
by Pauler (Initiate) on Nov 14, 2012 at 03:52 UTC
    Thanks a lott.. It really worked. Thanks for helping. Can u please help me in reading specific row or column value. If i wanna read the column B and its values from excel. Or a certain row. Can u please let me know where i can read these examples or modules.
        I have the below code which reads the column value. But the prb in the code is it prints each column value 3times. Could someone please help in finding the bug. The excel looks like below:
        perl flavors modules class Candidate Name vanilla excel first Nancy strawberry dumper second jimmy lettuce array third roma
        The perl code is as below:
        #use strict; use Spreadsheet::ParseExcel; my $FileName = "/home/dujnne/praice/excel/test.xls"; my $excel = Spreadsheet::ParseExcel::Workbook->Parse($FileName) or die + "Unable to open $FileName\n"; #locate columns in the spreadsheet from which we want to extract data my $found = 0; my ($rowCnt, $colCnt) = (0,0); foreach my $sheet (@{$excel->{Worksheet}}) { printf("Sheet: %s\n", $sheet->{Name}); $sheet->{MaxRow} ||= $sheet->{MinRow}; $rowCnt = $sheet->{MinRow}; foreach my $row ($sheet->{MinRow} .. $sheet->{MaxRow}) { $sheet->{MaxCol} ||= $sheet->{MinCol}; $colCnt = $sheet->{MinCol}; foreach my $col ($sheet->{MinCol} .. $sheet->{MaxCol}) { my $cell = $sheet->{Cells}[$row][$colCnt]; if ( lc $cell->{Val} eq "class" ) { $found = 1; print "OKAY: found the column as "class"\n"; print "INFO: searching for all classes \n"; $colCnt++; } if ( $found ) { print $sheet->{Cells}[$row][$colCnt]->{Val}, "\n"; next; } } } $found = 0; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1003237]
[Discipulus]: why perl -e 'print q(\'a string\'),"\n"' gives -bash: syntax error near unexpected token `)' ??
[Discipulus]: i'm not escaping correctly?
[moritz]: Discipulus] iirc bash doesn't let you escape ' with \
[moritz]: not inside a single-qouted string at least
[moritz]: echo 'a'\''

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2017-11-24 10:11 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (346 votes). Check out past polls.