Mayank
Mayank

Reputation: 231

Automate Excel tasks using perl

I have to automate an excel file, I have already checked Win32:OLE, just wanted to check if there are some other ways apart from that to achieve similar functionality.

Thanks in advance!

Upvotes: 1

Views: 412

Answers (1)

serenesat
serenesat

Reputation: 4709

Cpan module Spreadsheet::ParseExcel is a tool to read information from an Excel file. An example is here :

use warnings;
use strict;
use Spreadsheet::ParseExcel;

my $parser   = Spreadsheet::ParseExcel->new();
my $workbook = $parser->parse('Book1.xls');

if ( !defined $workbook ) {
    die $parser->error(), ".\n";
}

for my $worksheet ( $workbook->worksheets() ) {

    my ( $row_min, $row_max ) = $worksheet->row_range();
    my ( $col_min, $col_max ) = $worksheet->col_range();

    for my $row ( $row_min .. $row_max ) {
        for my $col ( $col_min .. $col_max ) {

            my $cell = $worksheet->get_cell( $row, $col );
            next unless $cell;

            print "Row, Col    = ($row, $col)\n";
            print "Value       = ", $cell->value(),       "\n";
            print "Unformatted = ", $cell->unformatted(), "\n";
            print "\n";
        }
    }
}

Upvotes: 1

Related Questions