Page 1 of 1

Formatting for dynamically made XLS not working

Posted: Thu Aug 10, 2006 3:31 pm
by ibanez270dx
Hi,
I have a portion of code that dynamically creates an XLS file - which works - and then it posts the information into the correct cells - which works. The problem is that only a bit of it actually formats correctly according to my code.

So the top bar (the column labels) works pretty ok. The bgcolor tag works and so does the text formatting in each cell. However, the width tag doesn't work - same with the style tag. Oddly enough, the bottoms of the cells are misaligned in every other cell.

Even a bigger problem, none of the tags in the second table (data) work, except the text formatting. I still need it to be vertically aligned in the middle, and the cell background be #e5e5e5 in every other cell.

Lastly, there are no gridlines when the file is opened... which seems really weird.

Here is my code:

Code: Select all

$catanames = "
<table width=95% style=border: 1px solid; border-color:#000000;><tr>
<td bgcolor=#000000 width=100><font color=#FFFFFF><center><b>Type</b></center></font></td>
<td bgcolor=#000000 width=100><font color=#FFFFFF><center><b>Date</b></center></font></td>
<td bgcolor=#000000 width=100><font color=#FFFFFF><center><b>Downtime</b></center></font></td>
<td bgcolor=#000000 width=100><font color=#FFFFFF><center><b>Hours Down</b></center></font></td>
<td bgcolor=#000000 width=100><font color=#FFFFFF><center><b>ATA</b></center></font></td>
<td bgcolor=#000000><font color=#FFFFFF><center><b>Discrepancy</b></center></font></td>
<td bgcolor=#000000><font color=#FFFFFF><center><b>Resolution</b></center></font></td>
<td bgcolor=#000000 width=120><font color=#FFFFFF><center><b>Logged</b></center></font></td>
<td bgcolor=#000000 width=150><font color=#FFFFFF><center><b>Logged By</b></center></font></td>
</tr></table>";

 	 $data .= "
<table width=95%><tr>
<td bgcolor=#e5e5e5 width=100 valign=middle valign=middle><center>$dwntime_type</center></td>
<td width=100 valign=middle><center>$dwntime_date</center></td>
<td width=100 valign=middle bgcolor=#e5e5e5><center>$dwntime_times</center></td>
<td width=100 valign=middle><center>$dwntime_hrs</center></td>
<td width=100 valign=middle bgcolor=#e5e5e5><center>$dwntime_ata</center></td>
<td valign=middle><center>$dwntime_reason</center></td>
<td valign=middle bgcolor=#e5e5e5><center>$dwntime_solution</center></td>
<td width=120 valign=middle><center>$dwntime_log</center></td>
<td width=150 valign=middle bgcolor=#e5e5e5><center>$dwntime_log_by</center></td>
</tr><tr><td colspan=9><hr size=1></td></tr></table>";
	}

$fp = fopen($filename2,"a");
	if($fp)
	{

	 fwrite($fp, $catanames);
	 fwrite($fp, $data);
	 fclose($fp);
	 echo "File saved successfully. <a href=$filename2>click here to access $filename2</a>";
	} else {
	 echo "Error saving file!";
	}
this ends up looking like:

Image

Can anyone help me figure out why it won't format correctly?

Thanks!!
- Jeff

Posted: Fri Aug 11, 2006 12:04 am
by Uranium-235
Excel is somewhat strange when it comes to HTML tables. for instance, it does not read the valign tag (at least 2002 dosen't), but it does read a CSS decloration for vertical aligning.

My suggestion:
Create a basic document of what you want, save it in XML format (Excel 2002 or higher). Copy most of the XML to your PHP document, and just make loops for the on the <row>, <cell> and <data>'s in the middle of the document. Keep in mind it will currently work on 2002 and 2003