Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Writing multiple Excel::Writer::XLSX worksheets in parallel (3rd and final attempts)

by marioroy (Prior)
on Jul 05, 2015 at 04:00 UTC ( [id://1133225]=note: print w/replies, xml ) Need Help??


in reply to Writing multiple Excel::Writer::XLSX worksheets in parallel (3rd and final attempts)

The following is the serial version for comparison.

#!/usr/bin/env perl use strict; use warnings; # --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- package main; use Excel::Writer::XLSX; my ($nodeList, $wb, $center, $format); $nodeList = [ [ 'AMS' , 'a' ], [ 'APJ' , 'ap' ], [ 'EMEA', 'e' ] ]; $wb = Excel::Writer::XLSX->new("Node_List.xlsx"); # Set workbook properties $wb->set_properties( title => 'Node List', author => 'L_WC demo', comments => 'Node List', ); # Define/add formats to the workbook $center = $wb->add_format(align => 'center'); $format = $wb->add_format(align => 'center', bg_color => 44); # Add worksheets, specify formats for columns/rows for (0 .. @{ $nodeList } - 1) { $wb->add_worksheet($nodeList->[$_][0]); $wb->sheets($_)->set_column(0, 4, 15, $center); } # Run foreach (@{ $nodeList }) { doSomething($_->[0], $_->[1]); } $wb->close(); print "Node List is Done.\n"; # --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- sub doSomething { my ($region, $sql) = @_; my $ws; # Acquire data from the DB # Fill worksheet rows/cells if ($region eq 'AMS') { $ws = $wb->sheets(0); $ws->write(0, 2, 'foo', $format); for ( 1 .. 111_111 ) { $ws->write(0 + $_, 0, 1000 + $_); $ws->write(1 + $_, 2, 2000 + $_); $ws->write(2 + $_, 4, 3000 + $_); } print "AMS ---- DONE.\n"; } elsif ($region eq 'APJ') { $ws = $wb->sheets(1); $ws->write(0, 2, 'bar', $format); for ( 1 .. 111_111 ) { $ws->write(0 + $_, 0, 4000 + $_); $ws->write(1 + $_, 2, 5000 + $_); $ws->write(2 + $_, 4, 6000 + $_); } print "APJ ---- DONE.\n"; } elsif ($region eq 'EMEA') { $ws = $wb->sheets(2); $ws->write(0, 2, 'baz', $format); for ( 1 .. 111_111 ) { $ws->write(0 + $_, 0, 7000 + $_); $ws->write(1 + $_, 2, 8000 + $_); $ws->write(2 + $_, 4, 9000 + $_); } print "EMEA ---- DONE.\n"; } return; }

Kind regards, Mario

  • Comment on Re: Writing multiple Excel::Writer::XLSX worksheets in parallel (3rd and final attempts)
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1133225]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (9)
As of 2024-04-18 12:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found