Read Excel with PHP

Using Excel for anything other than quick data tabulation is usually a bad idea. If you use a spreadsheet the way you should use a database, you are just asking for trouble. Unfortunately, in the world of accounting organizing information in excel sheets is a common practice.

Sooner or later a manager will get tired want to see a report based on that spreadsheet, and have it tie into your online time tracking and billing system. So they call up the IT, and say “make it so, #1”.

How do you make it happen? For one, I decided not to reinvent the wheel. I figured that the less code I write, the less bugs I introduce to my already kludge prone web app. Laziness is a very favorable trait for a programmer! It encourages code reuse and modularity :)

So I grabbed the PHP Excel Reader from freashmeat. For the last hour I have been playing with it, and essentially implemented half of the required application. I don’t even want to think how many hours would it take me to develop XLS parser from scratch.

Thank you freshmeat!

Update Thu Jul 13 11:54:06 EDT 2006

You should probably look at the brief documentation at sourceforge. Be aware that this app treats formulas as blank cells. For my purposes this is ok so I don’t really care.

By default dates are displayed in the European format (dd/mm/yy). To use American dates instead change line 88 in reader.php to:

0xe => "m/d/Y",

I hope this helps

[tags]php, programming, excel, php excel reader, freshmeat[/tags]

This entry was posted in Uncategorized. Bookmark the permalink.



3 Responses to Read Excel with PHP

  1. Sarika INDIA Internet Explorer Windows says:

    Can you send us the format for

    dd/mm/yyyy

    Reply  |  Quote
  2. Luke UNITED STATES Mozilla Firefox Windows says:

    This question would probably be best sent to the original developer. I will look at the code tomorrow, but I’m assuming that putting that string on the 0xe line didn’t work… If you haven’t tried it, go do it now.

    Quick and dirty hack would be simply look at the fist digit of the year and assume that if it is greater than say 4 then assume that you are dealing with 1900’s – otherwise you are dealing with 2000’s.

    Of course this means that your application will break in 2040 but you know… :P

    Reply  |  Quote
  3. Adham CANADA Internet Explorer Windows says:

    I have just recently finished setting phpExcelReadr for my intranet, and it reads the data and displays it perfectly. Nevertheless, my only concern is that it also prints and row/col numbers/letters. I am trying to have it disregard them and treat the first row as a header (for cosmetic purposes). Would you have any idea about the go around in achieving this result? Any suggestions and/or assistance will be really appreciated.

    Reply  |  Quote

Leave a Reply

Your email address will not be published. Required fields are marked *