How can i read .xls files (Excel) with PHP?

我的梦境 提交于 2019-12-09 15:12:25

问题


I need to convert an .xls file to text, i dont need it formatted in any way. The file is filled with productids like PN-5098P, which i will preg_match_all to get.

What is the simplest solution? I tried simply opening the file in a regular texteditor, the ids are not showing, so i guess i need some kind of binary converter?


回答1:


XLS is a complex proprietary format, and it might be difficult to work with. If you end up having trouble with libraries like Clint suggested, consider only accepting files in a more simpler format, like CSV, which is super-duper easy to deal with. If that solution is acceptable in this situation, it'll end up making your life much easier.




回答2:


Newer versions of MS Office can output your spreadsheet directly in XML format. Here's an example of using such an XML-format spreadsheet directly from PHP:

  • http://www.ibm.com/developerworks/opensource/library/os-phpexcel/

Otherwise, I've heard good things about PHPExcel:

  • http://phpexcel.codeplex.com/

Here's one other link that might at least give you some additional ideas:

  • http://www.the-art-of-web.com/php/dataexport/



回答3:


I convert my Excel sheets to MySQL using xls2mysql.com, but it isn't perfect. It doesn't recognize characters like -, /, é, ü, ô etc.. I've been working around this by converting those characters to a number in between hash tags (#4# for -) and unconverting them afterwards, but it is a bit of a hassle.



来源:https://stackoverflow.com/questions/8128616/how-can-i-read-xls-files-excel-with-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!