我们可以通过如下方式去规定数据保存的格式:
1)文本:vnd.ms-excel.numberformat:@
2)日期:vnd-ms-excel.numberformat:yyyy/mm/dd
3)数字:vnd-ms-excel.numberformat:#,##0.00
4)货币:vnd-ms-excel.numberformat:$#,##0.00
5)百分比:vnd-ms-excel.numberformat:#0.00%
使用方法:
date_default_timezone_set('PRC'); //设置中国时区
header('Content-Type: text/xls');
header ( "Content-type:application/vnd.ms-excel;charset=utf-8" );
$fname ='标题'.date('Y-m-d H:i',time());
$str = mb_convert_encoding($fname, 'gbk', 'utf-8');
header('Content-Disposition: attachment;filename="' .$str . '.xls"');
header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
header('Expires:0');
header('Pragma:public');
echo "<style>body,table{padding:0px; margin:0px;}</style>";
//在Excel上显示完整的数字
$tables="<table width="100%" border="1" cellpadding="1" cellspacing="1"><tr><td style='vnd.ms-excel.numberformat:@'>123123123123123123123123123</td></tr></table>";
echo $tables;
die();