In my php file I have a simple table:
<head>
<style><!-- styles go here--></style>
</head>
<body>
<table border="1" align="center">
<thead>
<tr>
<th rowspan=3>Three words here</th>
<th rowspan=3>Full Name</th>
<!-- other headers ... -->
</tr>
<tr></tr>
<tr></tr>
</thead>
<tr>
<td width="50px">content</td>
<!-- other definitions ... -->
</tr>
</table>
</body>
Using header function
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=summary.xls");
I exported my *.php file to *.xls format. And then I found Excel didn’t make a word wrap for table headers. It sets <th> element width by its content without wrapping it. Why?
Thanks!
Simple answer: No!
Excel is capable of reading HTML files (even though this isn’t an xls file, it’s very forgiving of you for lying to it). Excel’s HTML import can read some style elements, but it is not a fully-fledged html/css parser.
The only way to get all elements styled correctly is to create a genuine xls or xlsx file