摘要:
本文讲的是基于PHP导出Excel的小经验 完美解决乱码问题,我在PHP项目里要求把数据导出为Excel,并且数据中包含中文.网上大概了解一下可是使用PHPExcel,可是相对我的需求,这个框架太复杂了.于是还是想找找简单做法.网上发现其实最简单可以这样写,但问题是这种做法中文的编码不可靠..<
<?php header("Content-type:application/vnd.ms-excel"); header("Content-Disposition:attachment;filename=export_data.xls"); echo "姓名"."/t"; echo "繁體"."/t"; echo "博客"."/t"; echo "/n"; echo "jason"."/t"; echo "@"."/t"; echo "javaeye"."/t"; ?>
header("Content-type:application/vnd.ms-excel;charset=UTF-8");
echo iconv("当前编码","GB18030","此博客来源于javaeye,by jason");
<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-type" content="text/html;charset=UTF-8" /> <style id="Classeur1_16681_Styles"></style> </head> <body> <div id="Classeur1_16681" align=center x:publishsource="Excel"> <table x:str border=0 cellpadding=0 cellspacing=0 width=100% style="border-collapse: collapse"> <tr><td class=xl2216681 nowrap>1234</td><td class=xl2216681 nowrap>Robbin会吐口水</td></tr> <tr><td class=xl2216681 nowrap>5678</td><td class=xl2216681 nowrap>javaeye网站</td></tr> </table> </div> </body> </html>
header("Content-type:application/vnd.ms-excel"); header("Content-Disposition:attachment;filename=export_data.xls");
以上是云栖社区小编为您精心准备的的内容,在云栖社区的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索excel ,以便于您获取更多的相关知识。