生成word没有问题,就是生成的excel打开是会报个错.
此外,模板的css样式就不能像写html一样随心所欲了,要实现的样式,可以先写一个word作为模板,然后另存为html,打开看看,你便了然矣...
function downloadWord($content, $file='newfile.xls'){
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$file");
$ext = substr(end(explode('.', $file)), 0, 3);
switch($ext){
case 'doc' :
$html = '<html xmlns:v="urn:schemas-microsoft-com:vml"xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml"xmlns="http://www.w3.org/TR/REC-html40">';
$html .= '<head></head>';
break;
case 'xls':
$html = '<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">';
$html .= '<head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name></x:Name><x:WorksheetOptions><x:Selected/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head>';
}
echo $html . '<body>'.$content .'</body></html>';
}
function index(){
downloadWord($this->fetch('excel'), 'abc.xls');
}模板:<table>
<tr>
<td><img src="http://test.com/Zbseoag/aaa.png" /></td>
<td>sssssss</td>
</tr>
</table>
最佳答案