perl scripting code for excel parsing

Upload: aameen-fayyaz

Post on 10-Oct-2015

8 views

Category:

Documents


0 download

DESCRIPTION

Perl Scripting Code for Excel parsing

TRANSCRIPT

  • 5/20/2018 Perl Scripting Code for Excel parsing

    1/2

    #!/usr/bin/perl w

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

    my $file = "";my $directory = 'C:\Users\Name\Desktop\test';opendir( DIR, $directory ) or die "cannot open direction $directory";my @files = glob "$directory/*.xls";closedir(DIR);

    open( OF1, ">" . 'C:\Users\Name\Desktop\test\XLS.txt' ) or die $!;open( OF2, ">" . 'C:\Users\Name\Desktop\test\XLS_error.txt' ) or die $!;

    foreach $file (@files) {

    my $parser = Spreadsheet::ParseExcel->new(); my $workbook = $parser->parse($file);

    eval { $parser->parse($file); }; if ($@) { print OF2 substr( $file, 13 ), "\n"; next; }

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

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

    for my $row ( 0 .. 1 ) { if ( $row_max == 0 ) { next; } print OF1 $file, "|", $worksheet->get_name(), "|";

    for my $col ( $col_min .. $col_max ) {

    my $cell = $worksheet->get_cell( $row, $col ); if ( !defined $cell ) { print OF1 "|"; } next unless $cell;

    print OF1 $cell->unformatted(), "|"; } print OF1 "\n"; } }}

  • 5/20/2018 Perl Scripting Code for Excel parsing

    2/2