如何使用 PHP 将数据写入 Excel?

发布于 2024-09-28 07:02:16 字数 169 浏览 2 评论 0原文

是否可以使用 PHP fwrite() 将内容附加到 .xls 文件?

当我使用 fwrite() 尝试此操作时,生成的文件会在 Excel 2007 中导致错误消息。

是否有可以用来完成此操作的特定分隔符?

没有第三方库可以吗?

Is it possible to append content to an .xls file using PHP fwrite()?

When I try this using fwrite(), the resulting file causes an error message in Excel 2007.

Is there a specific separator I can use to accomplish this?

Is it possible without a third party library?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

深巷少女 2024-10-05 07:02:16

您可以使用 PhpSpreadsheet 库来读取现有的 Excel 文件,向其中添加新行/列,然后将其写回为真正的 Excel 文件。

免责声明:我是这个库的作者之一。

You can use the PhpSpreadsheet library, to read an existing Excel file, add new rows/columns to it, then write it back as a real Excel file.

Disclaimer: I am one of the authors of this library.

走过海棠暮 2024-10-05 07:02:16

您可以尝试创建一个 CSV 文件,如下所示:

name;surname;blabla
name;surname;blabla
name;surname;blabla
name;surname;blabla

Excel 应该吃这个:)

使用 PHP CVS 函数很方便: http://php.net/manual/en/function.fputcsv.php

You can try and create a CSV file, like this:

name;surname;blabla
name;surname;blabla
name;surname;blabla
name;surname;blabla

Excel should eat this :)

It is convenient to use PHP CVS functions: http://php.net/manual/en/function.fputcsv.php

李白 2024-10-05 07:02:16

编写您可以使用: Spreadsheet_Excel_Writer 是一个用于创建 Excel 文件的工具,无需 COM 组件

或使用 phpexcel (支持 excel 2007)

http://phpexcel.codeplex.com/

并且您可以附加查看示例:

http://phpexcel.codeplex.com/Thread/View.aspx?ThreadId =82996

to write you can use : Spreadsheet_Excel_Writer is a tool for creating Excel files without the need for COM components

http://pear.php.net/manual/en/package.fileformats.spreadsheet-excel-writer.php
but you cant appaend to file , only to create it.

or using phpexcel (support excel 2007)

http://phpexcel.codeplex.com/

and you can append see a example :

http://phpexcel.codeplex.com/Thread/View.aspx?ThreadId=82996

橙幽之幻 2024-10-05 07:02:16

使用 fputcsv 函数
例如:

 $data[] = array("item 1", "item 1");
    $export = fopen("file.csv", "w");
    foreach ($data as $row) {
        fputcsv($export, $row, "\t");
    }
    fclose($export);

更多示例: https://www.php.net/manual /en/function.fputcsv.php

use from fputcsv function
for example :

 $data[] = array("item 1", "item 1");
    $export = fopen("file.csv", "w");
    foreach ($data as $row) {
        fputcsv($export, $row, "\t");
    }
    fclose($export);

for more example : https://www.php.net/manual/en/function.fputcsv.php

能怎样 2024-10-05 07:02:16

if you just want/need to create a very simple table, you just need to make a *.csv-file which can be opened by excel - but not: you can't use formulas in this and you can't do any kind of formatting.

旧城空念 2024-10-05 07:02:16

你可以试试这个库
http://phpexcel.codeplex.com/

或者您可以创建 .csv 文件,然后将它们导入到出类拔萃。

you can try this library
http://phpexcel.codeplex.com/

or you can create .csv file for example and then import them to excel.

毅然前行 2024-10-05 07:02:16

我编写了一个简单的库,用于从 PHP 导出 Excel 友好的 XML 文件: http://github.com/ elidickinson/php-export-data

I wrote a simple library for exporting Excel-friendly XML files from PHP: http://github.com/elidickinson/php-export-data

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文