Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Think about Loose Coupling
 
PerlMonks  

How to Modify and Rewrite Excel Files in perl

by bimleshsharma (Beadle)
on May 22, 2012 at 13:55 UTC ( #971795=perlquestion: print w/ replies, xml ) Need Help??
bimleshsharma has asked for the wisdom of the Perl Monks concerning the following question:

Hi, How to Modify and Rewrite existing Excel Files in perl? I tried below but not looking worthy. Please help.
#!/usr/bin/perl –w use strict; use Spreadsheet::WriteExcel; # Create a new Excel file my $FileName = “/home/selva/Report.xls"; my $workbook = Spreadsheet::WriteExcel->new($FileName); # Add a worksheet my $worksheet1 = $workbook->add_worksheet('PERL’); # Define the format and add it to the worksheet my $format = $workbook->add_format( center_across => 1, bold => 1, size => 10, border => 4, color => 'black', bg_color => 'cyan', border_color => 'black', align => 'vcenter', ); # Change width for only first column $worksheet1->set_column(0,0,20); # Write a formatted and unformatted string, row and column # notation. $worksheet1->write(0,0, "PERL FLAVOURS", $format); $worksheet1->write(1,0,"Active State PERL"); $worksheet1->write(2,0,"Strawberry PERL"); $worksheet1->write(3,0,"Vennila PERL");

Comment on How to Modify and Rewrite Excel Files in perl
Download Code
Re: How to Modify and Rewrite Excel Files in perl
by Corion (Pope) on May 22, 2012 at 13:58 UTC
      I am getting format of cell but i am unknown about the actual properties. Because i have to use same format for other cell if bg_color=red. I am using code below to get format..
      # Get the format from the cell my $format = $template->{Worksheet}[$sheet] ->{Cells}[$row][$col] ->{FormatNo};
Re: How to Modify and Rewrite Excel Files in perl
by Khen1950fx (Canon) on May 22, 2012 at 16:34 UTC
    It's actually a trivial task. Try this:
    #!/usr/bin/perl use strict; use warnings; use Spreadsheet::WriteExcel; my $workbook = Spreadsheet::WriteExcel->new("Report.xls"); my $first = $workbook->add_worksheet('Perl'); my $second = $workbook->add_worksheet('Perl Flavours'); my $third = $workbook->add_worksheet('ActivePerl'); my $fourth = $workbook->add_worksheet('StrawberryPerl'); my $fifth = $workbook->add_worksheet('VanilaPerl'); my $format = $workbook->add_format( center_across => 1, bold => 1, size => 10, border => 4, color => 'black', bg_color => 'cyan', border_color => 'black', align => 'vcenter', ); $first->set_column(0,0,20); foreach my $worksheet ($workbook->sheets()) { $worksheet->write(0,0, "Perl", $format); $worksheet->write(1,0, "Perl FLAVOURS"); $worksheet->write(2,0, "Active Perl"); $worksheet->write(3,0, "Strawberry Perl"); $worksheet->write(4,0, "Vanilla Perl"); } $first->activate();

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://971795]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (17)
As of 2014-04-18 19:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (471 votes), past polls