Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^3: Reading Excel file in perl

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

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

Assuming you already know you have perl installed in your system, can run a perl program, and know that the Spreadsheet::ParseExcel module is installed:

It looks like you can take the code in the "synopsis" and cut and paste it to be your test program. Copy it into a text editor and save it as something like "". this is your perl program.

Then take a simple excel file (maybe 4 cells by 4 cells, and fill them with numbers 1 through 16 in order) and save it into the same directory as your perl program that you just saved. For convenience you can save it as "Book1.xls", which is the name used in the example

Then you should be able to go to the directory that your program is in and run the program from there. (e.g. assuming you're on a unix system, type perl

If you haven't even gotten as far as running a perl program, tell us about your system and depending on what it is, someone will probably be able to point you to somewhere that will help you sort out how to do that first.

Replies are listed 'Best First'.
Re^4: Reading Excel file in perl
by Pauler (Initiate) on Nov 09, 2012 at 04:07 UTC
    Hey thanks... I tried as per ur suggestion. But i tried 2 prgs, one for write to excel and another for read excel. I have the below code for write to excel:
    #!/sbcimp/run/pd/csm/32-bit/perl/5.14.2/bin/perl use lib qw(/sbcimp/run/pd/csm/32-bit/cpan/5.14.2-2012.03/lib); use strict; use Spreadsheet::WriteExcel; # Create a new Excel file my $FileName = "/home/dujne/ptice/port.xls"; my $workbook = Spreadsheet::WriteExcel->new($FileName); # Add a worksheet my $worksheet1 = $workbook->add_worksheet('PERL'); # Define the format and add it to the worksheet my $format = $workbook->add_format( center_across => 1, bold => 1, size => 10, border => 4, color => 'black', bg_color => 'cyan', border_color => 'black', align => 'vcenter', ); # Change width for only first column $worksheet1->set_column(0,0,20); # Write a formatted and unformatted string, row and column # notation. $worksheet1->write(0,0, "PERL FLAVOURS", "Modules",$format); $worksheet1->write(1,0,"Active State PERL"); $worksheet1->write(2,0,"Strawberry PERL"); $worksheet1->write(3,0,"Vennila PERL" );
    The above code runs fine. I m trying to update the next column and add the details next to the column. I have the below code,
    $worksheet1->write(0,1,"Modules", $format); $worksheet1->write(1,1,"Excel"); $worksheet1->write(2,1, "Dumper");
    bt this code adds 3 different columns, i wanted as Column B as Modules, and below this column i need 2 rows as 1)Excel & 2) Dumper Something like below is needed::
    MODULES Excel Dumper
    But with my code i see the below
    MODULES Excel Dumper
    Can someone let me know whats wrong in the avove code??? Or how can i add 3 by 3 cells?

      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

        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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002814]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2018-06-20 19:18 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.