CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [Tejas] How to append or prepend a string to a variable : Edit Log



Zhris
Enthusiast

Nov 19, 2014, 1:26 AM


Views: 13033
Re: [Tejas] How to append or prepend a string to a variable

Hi,

The below is again untested, I am also inexperienced using Excel::Writer::XLSX therefore my code is likely more convuluted than it could be (I was looking through the documentation to try and find methods to get/set single worksheets and get their max row number, with no luck). It creates a single workbook, then worksheets are added as and when an org is seen. Worksheets and row numbers are held in the worksheets state hash.


Code
my %worksheets; 

my $workbook = Excel::Writer::XLSX->new( 'workbook.xlsx' );

open $gl_fh, '<', $gl_file or die "could not open $gl_fh <$!>";

while ( my $line = <$gl_fh> )
{
chomp $line;

my ( $org, @data ) = split /,|\|/, $line;

my ( $worksheet, $row );

if ( defined $worksheets{$org} )
{
$worksheet = $worksheets{$org}{worksheet};
$row = ++$worksheets{$org}{row};
}
else
{
$worksheet = $worksheets{$org}{worksheet} = $workbook->add_worksheet( "${org}_GL_Sheet" );
$row = $worksheets{$org}{row} = 0;
}

for my $col ( 0 .. $#data )
{
$worksheet->write_string( $row, $col, $data[$col], $frmt );
}
}

close $gl_fh;

__DATA__
US,one|two|three
GB,four|five|six


I'm still not certain this is what you desire, but appears to be more fitting based on your most recent description.

Regards,

Chris


(This post was edited by Zhris on Nov 19, 2014, 2:26 AM)


Edit Log:
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 1:27 AM
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 1:27 AM
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 1:29 AM
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 1:31 AM
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 2:26 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives