Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^5: Reading Excel file in perl

by bitingduck (Friar)
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


Comment on Re^5: Reading Excel file in perl
Select or Download Code
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (15)
As of 2014-08-28 15:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (263 votes), past polls