作者:乔山办公网日期:
返回目录:excel表格制作
右键—属性—最后修改时间。
function printResultExcel_one_sheet($statResult, $fileName = "total") {
header ( "Content-type:application/vnd.ms-excel;charset=utf-8" );
header ( "Content-Disposition:filename=".$fileName.".xls" );
echo '<table border="1" cellspace="1" bordercolor="#D3D3D3">';
foreach ( $statResult as $result ) {
度echo "<tr>";
foreach ( $result as $i ) {
echo '<td style="vnd.ms-excel.numberformat:@">'.$i.'</td>';
}
echo "</tr>";
}
echo '</table>';
}
$statResult 是你知的数组,然道后调用这内个方法就可以下载excel文件了容
$retdata=array(); //内容 //二维数组
$filename= "文件.csv";
//生成头文件
$now = gmdate("D, d M Y H:i:s");
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
header("Last-Modified: {$now} GMT");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment;filename={$filename}");
header("Content-Transfer-Encoding: binary");
//生成表格
$title=array('"金额"','"会员"','"余额e799bee5baa6e79fa5e98193e59b9ee7ad94361"'); //每列的标题
$str=implode(',',$title) . PHP_EOL;
foreach ($retdata as $row) {
// print_r($row);
$str_arr = array();
foreach ($row as $column) {
$str_arr[] = '"' . str_replace('"', '""', $column) . '"';
}
$str.=implode(',', $str_arr) . PHP_EOL;
}
print(chr(0xEF).chr(0xBB).chr(0xBF));
echo $str;