Home > Uncategorized > Parsing XLS files with PHP

Parsing XLS files with PHP

November 10th, 2004

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?

Panayotis Uncategorized

  1. December 12th, 2004 at 12:48 | #1

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

  2. January 10th, 2006 at 11:26 | #2

    i find PHP-ExcelReader so hard ,thanks

  3. ling king
    May 25th, 2006 at 15:50 | #3

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

  4. September 15th, 2006 at 09:45 | #4

    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. September 25th, 2006 at 00:44 | #5

    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. January 30th, 2007 at 16:03 | #6

    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
    June 4th, 2007 at 19:09 | #7

    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
    October 3rd, 2007 at 14:43 | #8

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

    Please help!

  9. Fernando
    July 8th, 2008 at 16:47 | #9

    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”.

  1. March 21st, 2008 at 22:48 | #1