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, 2:20 AM


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

Hi,

I am by no means 100% clear. Careful of your namespacing, i.e. workbooks, books, worksheets, sheets, tabs etc, its very confusing when you say worksheet but you mean workbook etc. The most useful thing you could do would be to attach example input and the resultant xlsx output.

Here is another untested attempt. It creates a workbook for each unique org found, stores this in the workbooks state hash along with the gl worksheet and row number and sl worksheet and row number. It proceeds to write the data to the gl worksheet only as per your code:


Code
my %workbooks; 

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 $workbook = $workbooks{$org}{workbook} //= Excel::Writer::XLSX->new( "${org}_GL_SL.xlsx" );
my $gl_sheet = $workbooks{$org}{worksheets}{gl}{worksheet} //= $workbook->add_worksheet( 'GL_Sheet' );
my $gl_row = $workbooks{$org}{worksheets}{gl}{row} += ( defined $workbooks{$org}{worksheets}{gl}{row} ) ? 1 : 0;
my $sl_sheet = $workbooks{$org}{worksheets}{sl}{worksheet} //= $workbook->add_worksheet( 'SL_Sheet' );
my $sl_row = $workbooks{$org}{worksheets}{sl}{row} += ( defined $workbooks{$org}{worksheets}{sl}{row} ) ? 1 : 0;

for my $gl_col ( 0 .. $#data )
{
$gl_sheet->write_string( $gl_row, $gl_col, $data[$gl_col], $frmt );
}
}

close $gl_fh;

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


Regards,

Chris


(This post was edited by Zhris on Nov 19, 2014, 3:01 AM)


Edit Log:
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 2:22 AM
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 2:23 AM
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 2:26 AM
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 2:27 AM
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 2:31 AM
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 2:32 AM
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 2:35 AM
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 2:58 AM
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 2:59 AM
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 2:59 AM
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 3:00 AM
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 3:00 AM
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 3:01 AM
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 3:01 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