php 如何使用PHP将数据写入excel
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3968973/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can i write data into an excel using PHP
提问by zod
Is it possible to append content to an .xls file using PHP fwrite()?
是否可以使用 PHP fwrite() 将内容附加到 .xls 文件?
When i try this using fwrite(), the resulting file causes an error message in Excel 2007.
当我使用 fwrite() 尝试此操作时,生成的文件会导致 Excel 2007 中出现错误消息。
Is there a specific separator I can use to accomplish this?
我可以使用特定的分隔符来完成此操作吗?
Is it possible without a third party library?
没有第三方库有可能吗?
回答by Mark Baker
You can use the PhpSpreadsheetlibrary, to read an existing Excel file, add new rows/columns to it, then write it back as a real Excel file.
您可以使用PhpSpreadsheet库来读取现有的 Excel 文件,向其中添加新的行/列,然后将其作为真正的 Excel 文件写回。
Disclaimer: I am one of the authors of this library.
免责声明:我是该库的作者之一。
回答by Silver Light
You can try and create a CSV file, like this:
您可以尝试创建一个 CSV 文件,如下所示:
name;surname;blabla
name;surname;blabla
name;surname;blabla
name;surname;blabla
Excel should eat this :)
Excel 应该吃这个:)
It is convenient to use PHP CVS functions: http://php.net/manual/en/function.fputcsv.php
使用PHP CVS函数很方便:http: //php.net/manual/en/function.fputcsv.php
回答by samrockon
you can try this library http://phpexcel.codeplex.com/
你可以试试这个库 http://phpexcel.codeplex.com/
or you can create .csv file for example and then import them to excel.
或者您可以创建 .csv 文件,然后将它们导入到 Excel 中。
回答by Eli
I wrote a simple library for exporting Excel-friendly XML files from PHP: http://github.com/elidickinson/php-export-data
我写了一个简单的库,用于从 PHP 导出 Excel 友好的 XML 文件:http: //github.com/elidickinson/php-export-data
回答by Haim Evgi
to write you can use : Spreadsheet_Excel_Writer is a tool for creating Excel files without the need for COM components
编写您可以使用:Spreadsheet_Excel_Writer 是一种无需 COM 组件即可创建 Excel 文件的工具
http://pear.php.net/manual/en/package.fileformats.spreadsheet-excel-writer.phpbut you cant appaend to file , only to create it.
http://pear.php.net/manual/en/package.fileformats.spreadsheet-excel-writer.php但你不能附加到文件,只能创建它。
or using phpexcel (support excel 2007)
或使用 phpexcel(支持 excel 2007)
and you can append see a example :
你可以附上一个例子:
http://phpexcel.codeplex.com/Thread/View.aspx?ThreadId=82996
http://phpexcel.codeplex.com/Thread/View.aspx?ThreadId=82996