我已经安装了 PEAR、Spreadsheet_Excel_Writer
和 OLE。示例程序已成功执行,但当我尝试读取文件时,它显示垃圾值。我还尝试了 $workbook->setVersion(8);
和 $worksheet->setInputEncoding('UTF-8');
我正在使用本教程和谷歌来解决这个问题。
http://www.sitepoint.com/article/getting-started-with-pear/3/
提前致谢。
最佳答案
我只在真正需要时才尝试使用 PEAR...您可以使用如下内容轻松生成 excel 电子表格(假设它只是数据):
$header = "Last Name\tFirst Name\tAge\tJob\n"; // new line is start of new row, tab is next column
//ideally you would get this from a DB and just loop through it and append on
$row1 = "Smith\tBob\t25\tManager\n";
$row2 = "Anderson\tTrent\t32\tCEO\n";
$excel = $header.$row1.$row2;
$xlsfile = "excel_example".date("m-d-Y-hiA").".xls";
header('Content-type: application/vnd.ms-excel');
header("Content-Disposition: attachment; filename=$xlsfile");
echo $excel;
关于PHP:使用 PEAR 写入 excel 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/388816/