 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
qualtrics
Joined: 28 Aug 2008 Posts: 1
|
Posted: Fri Aug 29, 2008 12:04 am Post subject: Excel Writer and Multiple Workbooks |
|
|
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 |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1000
|
Posted: Fri Aug 29, 2008 11:33 am Post subject: |
|
|
| 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 |
|
 |
|
|
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
|
|