in reply to Re^2: writing after parsing
in thread writing after parsing

Hello Ashwitha,

I spend some time today trying to figure out how to combine two excel files. To be honest since I am not an expert I figure it that maybe through 6-7 modules that I tried is was not possible. Again do not take my word or experience as granted because this was my first attempt on this area.

But yesterday I was reading about "CSV files" take a look on those. I started working with them, and I think it would be easier to solve your problem like this.

I mean read and export your excel files into a CSV file, then combine them in one common and regenerate your excel file combined. ;)

This is the only solution that I can imagine for your problem.

In case that you want for fun to experiment with some code that I create to test your question I have posted under. It is nothing complicated and also have included some documentation to assist you with the explanation.

#!/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) = shi +ft; 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)

I hope my proposed solution did confused you more. My intention was to propose an alternative solution to your problem.

Seeking for Perl wisdom...on the process...not there...yet!

Replies are listed 'Best First'.
Re^4: writing after parsing
by Ashwitha (Novice) on Aug 07, 2014 at 11:49 UTC

    hello thanos1983, yeah the proposalit kinda confused me ;). But thanks a lot for replying.