首先,在index.php文件中,创建链接:导出excel。
test1.php文件内容:
代码示例:
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Content-type:application/vnd.ms-excel");
Header("Content-Disposition:attachment;filename=export_excel_gshjsl.xls");
$tx='表头';
echo $tx."\n\n";
echo "编号"."\t";
echo "姓名"."\t";
echo "\n";
echo "=\"411481198507150666\""."\t";
echo "=\"0123456\""."\t"; //带上引号方便字符串输出。相当于设置单元格格式为文本。
echo "\n";
?>
以上就是php导出excel的实例代码,大家可以测试下。
另外,提供一个导出word文档的例子。
代码:
代码示例:
/**
* php导出word文件
* site: www.
*/
header("Content-Type: application/msword");
header("Content-Disposition: attachment; filename=doc.doc");
header("Pragma: no-cache");
header("Expires: 0");
$output = '
$output .= '
图片';$output .= '
下面是一张图片';$output .= '
header("Content-Disposition:filename=test.xls");
echo "A\tB\n";
echo "C\tD\n";
?>