PHP:使用PEAR写入excel文件

时间:2021-01-24 07:14:01

I have installed PEAR, Spreadsheet_Excel_Writer and OLE. The sample program is executed successfully but when I try to read the file it shows garbage values. I also tried $workbook->setVersion(8); and $worksheet->setInputEncoding('UTF-8');

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

I am using this tutorial and Google lot for this problem.
http://www.sitepoint.com/article/getting-started-with-pear/3/

我正在使用本教程和Google批次来解决这个问题。 http://www.sitepoint.com/article/getting-started-with-pear/3/

Thanks in advance.

提前致谢。

2 个解决方案

#1


I try to use PEAR only when I really need to...you can easily generate an excel spreadsheet( assuming it's just data) with something like this:

我尝试只在我真正需要时使用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;

#2


that's just a tab seperated value file though and you're sending headers suggesting the browser treat that data as an excel file. so there's no formatting of data which the poster may require.

这只是一个标签分隔值文件,你发送标题建议浏览器将该数据视为excel文件。所以没有海报可能需要的数据格式。

#1


I try to use PEAR only when I really need to...you can easily generate an excel spreadsheet( assuming it's just data) with something like this:

我尝试只在我真正需要时使用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;

#2


that's just a tab seperated value file though and you're sending headers suggesting the browser treat that data as an excel file. so there's no formatting of data which the poster may require.

这只是一个标签分隔值文件,你发送标题建议浏览器将该数据视为excel文件。所以没有海报可能需要的数据格式。