PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Excel Writer and Multiple Workbooks

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> PEAR
View previous topic :: View next topic  
Author Message
qualtrics



Joined: 28 Aug 2008
Posts: 1

PostPosted: Fri Aug 29, 2008 12:04 am    Post subject: Excel Writer and Multiple Workbooks Reply with quote

I need to create several workbooks and save them all in a folder. I am new to this to all I have now is a single workbook coming out of the foreach loop.
how can and produce and save a workbook for each "name"?

foreach ($names as $nombres)
{
$workbook_name=$nombres.'.xls';
$headernames=array();
$workbook = new Spreadsheet_Excel_Writer();
$data=$name[0];
// sending HTTP headers
$workbook->send($workbook_name);
$questiontext =& $workbook->addFormat( array('bold'=>1));
$questiontext->setTextWrap();
$worksheet =& $workbook->addWorksheet();
$worksheet->write(0,0, $nombres);
$headers=mysql_query("select distinct names from db where ".getStrings($nombres))
or die(mysql_error());
while ($row3 = mysql_fetch_row($headers)){
$headernames[]=$row3[0];}
$countheaders = count($headernames);
$j=1;
foreach($headernames as $header)
{
$worksheet->write(0,$j, $header);
$j++;
}
foreach ($code as $qs)
{
$worksheet->setColumn(0,0,45);

$worksheet->write(1+$qs, 0, $question[$qs], $questiontext);
}
$workbook->close();
}
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1235

PostPosted: Fri Aug 29, 2008 11:33 am    Post subject: Reply with quote

Your code isn't easily readable (please use the [code] environment here in the forum), but it looks right. Are you sure that $nombres isn't always the same value, causing the file to be overwritten in each step of the loop?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> PEAR All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement