Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

excel

xls

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?

like image 751
Kristian Rafteseth Avatar asked Nov 14 '11 21:11

Kristian Rafteseth


2 Answers

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.

like image 119
Matchu Avatar answered Oct 08 '22 04:10

Matchu


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/
like image 30
paulsm4 Avatar answered Oct 08 '22 05:10

paulsm4