Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spreadsheet::WriteExcel help ?

Status
Not open for further replies.

rabinski

Programmer
May 13, 2005
21
GB
Hi gurus once again -

I am looping throgh a csv with a number of fields splitting on the comma -

I need to take one of the fields and make this a tab in a spreadheet (on each iteration)- then add the remaining fields from the csv to the worksheet

The problem I have is when I do the foreach to do the split ,on each loop the 'worksheet' variable is overwritten - resulting in just the last 'worksheet' being visible -

I need to get all the tab names like this

my $sheet1 = $workbook->addworksheet("$variable_from_csv");

but on the next iteration the sheet is replaced - but
I want it to be added ....

Hope this makes sense !

thanks in advance

Rab




 
Hmmm, not sure I understand.
But I wonder if your "my $sheet1" is dropping out of scope (curly brackets) and being recreated.
Maybe you need an array of sheets and "push" the newly created sheet to the end of the array each time.
Without more code to look at it's difficult to comment more.


Trojan.
 
Cheers Trojan -

The spec has changed slightly -

I am running a foreach over a config file - within this I split out the details with another foreach, and then I need to print the details to a spreadheet ...

eg -

foreach over config file {

foreach $entry (@rs) {

$var1,$var2 = split (/,/, $i);

print $var1,$var2 to spreadsheet
}

}

The inner foreach just gives me the last entry - how can I get all the entries ?

Any clearer ?

cheers
 
Sorted ....

cheers anyway ....

I had the worksheet name within the loop - DOH !

Rab
 
Hehehe
Sometimes you can't see the wood for the trees.
In future though, you might like to understand that we look at your problems cold, and without any code or just pseudo code to work with we can't do much.
This is a classic example. Because you supplied pseudo code, I would not know that you had the worksheet name in the loop.
With a good slice of real code we may have been able to solve the problem much more quickly for you.
I realise that there is an issue of copyright and secrecy and all that other good stuff that goes against the open source model but people normally find a way to post enough real code that we can sort the problem.

Food for thought maybe.

Anyway, glad you sorted your problem. :)


Trojan.
 
Cheers Trojan -

I will take your points on board ...

Rab
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top