#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Spreadsheet::ParseExcel; use Spreadsheet::ParseExcel::SaveParser; use constant ARGUMENTS => scalar 2; sub input_test { if (@_ > ARGUMENTS) { print "\nPlease no more than ".ARGUMENTS." arguments (ARGV[])!\n"; print "\nCorrect Syntax: perl $0 'in.xls' 'out.xls'\n\n"; exit(); } elsif (@_ < ARGUMENTS) { print "\nPlease no less than ".ARGUMENTS." arguments (ARGV[])\n"; print "\nCorrect Syntax: perl $0 'in.xls' 'out.xls'\n\n"; exit(); } return(@_); } my @input = input_test(@ARGV); sub excel { # You do need to define the @_, it would work with $(string) = shift; my $in = shift(@_); my $out = shift(@_); # Open an existing file with SaveParser my $parser = Spreadsheet::ParseExcel::SaveParser->new(); my $template = $parser->Parse($in); my $worksheet_count = $template->worksheet_count(); print $worksheet_count . "\n"; my $filename = $template->get_filename(); my ($print_areas,$print_titles); print $filename . "\n"; $template->SaveAs($out); =overwriting process foreach my $worksheet ( $workbook->worksheets() ) { my $row = 0; my $col = 0; # Overwrite the string in cell A1 $worksheet->AddCell( $row, $col, 'String in Cell A1' ); # Add a new string in cell B1 $worksheet->AddCell( $row, $col + 1, 'String in Cell A2' ); # Add a new string in cell C1 with the format from cell A3. my $cell = $worksheet->get_cell( $row + 2, $col ); my $format_number = $cell->{FormatNo}; $worksheet->AddCell( $row, $col + 2, 'String in Cell A3', $format_number ); # Write over the existing file or write a new file. $workbook->SaveAs($out); } =cut } excel(@ARGV); sub extra { my $in = shift(@_); my $out = shift(@_); my $parser = Spreadsheet::ParseExcel->new(); my $workbook = $parser->parse($in); if ( !defined $workbook ) { die $parser->error(), ".\n"; } foreach my $worksheet ( $workbook->worksheets() ) { my ( $row_min, $row_max ) = $worksheet->row_range(); my ( $col_min, $col_max ) = $worksheet->col_range(); foreach my $row ( $row_min .. $row_max ) { foreach 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"; } } } } extra(@ARGV)