编程语言
首页 > 编程语言> > PHP:使用PEAR写入excel文件

PHP:使用PEAR写入excel文件

作者:互联网

我已经安装了PEAR,Spreadsheet_Excel_Writer和OLE.示例程序执行成功,但是当我尝试读取文件时,它显示垃圾值.我也试过$workbook-> setVersion(8);和$worksheet-> setInputEncoding(‘UTF-8’);

我正在使用本教程和Google批次来解决这个问题.
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,export-to-excel,pear
来源: https://codeday.me/bug/20190705/1386745.html