【问题标题】:PHP:Writing to excel file using PEARPHP:使用 PEAR 写入 excel 文件
【发布时间】:2015-09-06 09:43:11
【问题描述】:

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

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

提前致谢。

【问题讨论】:

  • 您未能共享代码。没有人会根据这个描述尝试它。

标签: php export-to-excel pear


【解决方案1】:

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

【讨论】:

  • 这是一个 .csv 文件,不是真正的 .xls 二进制文件。
【解决方案2】:

虽然这只是一个制表符分隔值文件,但您发送的标题建议浏览器将该数据视为 excel 文件。所以没有发布者可能需要的数据格式。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多