PHP:使用 PEAR 写入 excel 文件

标签 php export-to-excel pear

我已经安装了 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/

相关文章:

php - 请比较 Facebook Connect 与 Facebook (OpenID+Oauth)?

python - 如何识别并突出显示 pandas 数据帧每一行中的异常值

MySQL 数据库到 Excel(1 个表到 1 个工作表)

php - CentOS 7 安装 pecl/pear ius

PHPunit 代码覆盖错误

php - 将我自己的静态网页添加到 wordpress 站点

php - 将 Javascript 时钟与服务器时钟同步

php - “git pull”在 SSH 中执行,但不在 github 接收后脚本中执行

php - 将 php 输出导出为 excel

php - 使用 Wamp 2.1 安装 PEAR