in reply to Re^11: protect excel file in perl script
in thread protect excel file in perl script

NO error throwing in my code.Making Password protection functionality is not working on my perl version v5.8.8 and current installed parse excel module version: perl-Spreadsheet-ParseExcel.x86_64 0.3200-3.el5 #!/usr/bin/perl -w use strict; use Spreadsheet::ParseExcel; my $file='/home/muthum/excel1.xls'; my $parser = Spreadsheet::ParseExcel->new( Password => 'secret' ); my $workbook = $parser->Parse($file);
  • Comment on Re^12: protect excel file in perl script

Replies are listed 'Best First'.
Re^13: protect excel file in perl script
by poj (Abbot) on Mar 15, 2017 at 18:29 UTC

    Try

    #!/usr/bin/perl -w use strict; use Spreadsheet::ParseExcel; my $file = '/home/muthum/excel1.xls'; my $parser = Spreadsheet::ParseExcel->new( Password => 'secret' ); my $workbook = $parser->Parse($file); if ( !defined $workbook ) { die $parser->error(), "\n"; } for my $worksheet ( $workbook->worksheets() ) { my $cell = $worksheet->get_cell( 0, 0 ); next unless $cell; print "[A1] = ", $cell->value(),"\n"; }
    poj
      I tried to execute the code you gave me but am getting the below error please let me know am I missing anything or module version need to be upgraded or dependency required? -bash-3.2$ dos2unix test.pl dos2unix: converting file test.pl to UNIX format ... -bash-3.2$ perl test.pl Can't locate object method "worksheets" via package "Spreadsheet::ParseExcel::Workbook" at test.pl line 15.

        Try without worksheets method which was added in version 0.43 January 7 2009

        #!/usr/bin/perl -w use strict; use Spreadsheet::ParseExcel; my $file = '/home/muthum/excel1.xls'; my $parser = Spreadsheet::ParseExcel->new( Password => 'secret' ); my $workbook = $parser->Parse($file); if ( !defined $workbook ) { die $parser->error(), ".\n"; } my $count = $workbook->{SheetCount}; print "Workbook has $count sheets\n"; for my $i (0..$count-1){ my $worksheet = $workbook->{Worksheet}[$i]; my $cell = $worksheet->get_cell( 0, 0 ); if ($cell){ print "[A1] = '", $cell->Value,"'\n"; } }

        What are you trying to do with the spreadsheet, just read the contents ?

        poj