Parsing XLS files with PHP

We (at work) often offer clients the solution to batch upload data to a web site using excel files. The obvious alternative is to uplad a tab delimeted text file, but then you have to explain to the end user how to save the excel file to text (which is puting the client do our job in a way..).

The solution we had so far was to use xlhtml on the server side to transform the XLS file to XML. Then it is relatively easy to parse it using PHP. This worked quite fine for as long as we were on a Linux server (where compiling and running xlhtml is straight forward).

Lately we had to implement similar functionality (in PHP too) on an IIS (the MS equivelent of Apache) running on Windows NT. The solution Alex came up with was to use PHP-ExcelReader, an excelent library that can parse an XLS file and return a PHP array. It works like a charm!

Do you know of any alternatives?

11 Responses to Parsing XLS files with PHP

  1. erlen says:

    This parser are very useful!!! Thanks to its developer!

  2. windflower says:

    i find PHP-ExcelReader so hard ,thanks

  3. ling king says:

    I neet the parser,how can i download it,thanks

  4. PixelChutes says:

    Wow! PHP-ExcelReader saves the day! An extremely impressive Class–did just what I needed! Haven’t had a need for parsing XLS->Array since Perl, so I am truly grateful.

    It was so easy to implement, fit right into my model!

    Just download from SourceForge, take the example page and replace .XLS with file/paramter of your choice. Loop through each cell with ease!

  5. petersk says:

    PHP-ExcelReader is a really, really useful tool, just what I needed! Many thanks to the developers!!!
    I have just one question – is it possible to discard these rows and collumns that are hidden in the xls-file and how?

  6. Yonakin says:

    PHP-ExcelReader is a useful tool to parse XLS to PHP array. Thanks to the developers for publishing this tool to the web.

    P.S. How can I parse from php-array to xls file? If you have such script please notify my. Thanks

  7. Janusz says:

    There is a little problem with 64bit OS, function GetInt4d is not working
    Error:
    Notice: Uninitialized string offset: x in Excel/oleread.inc on line 27

    /* function for 32 bit os
    function GetInt4d($data, $pos) {^M
    return ord($data[$pos]) | (ord($data[$pos+1]) =128)
    $_ord_24 = -abs((256-$_or_24)

    I found this on:
    http://forum.ovh.com/showthread.php?t=12695

  8. Tomas says:

    Very good script.
    But how to make it work with UTF-8 encoding?
    $data->setOutputEncoding(‘utf-8′); – doesnt work.

    Please help!

  9. Pingback: Διαβάζοντας αρχεία xls με PHP « ale3andro’s blog

  10. Fernando says:

    Warning: main(Spreadsheet/Excel/Reader/OLERead.php): failed to open stream: No such file or directory in /www_mounted/interno/htdocs/interno/util/ExcelReader/Excel/reader.php on line 31

    There is the file in the package.”Spreadsheet/Excel/Reader/OLERead.php”.

  11. Eri says:

    I am using modified version of Simple XLSX PHP Class called XLSX Parser ( http://www.spyrozone.net/project/xlsx-parser/ ) by Sergey Shuchkin & Spyro Kid. The package contain the php class and some useful example (display the result as array, display the result in table, count worksheets, display all worksheet name, display desired worksheet name, convert excell date format, and more).