[Program] Read xls files with PHP
Like most of my post even this comes not only with the intent to do some 'information, to remind me of how I have solved a problem that occurred to me: In fact my memory is usually fallacious and googol To find the same information more than once I do not like very much ^ _ ^
An activity that often we have to do is to process "on the fly" a xls file (perhaps as a result dell'upload available to a user) and manage the data contained in it (possibly structured as we expected otherwise the thing is impractical ..) for example, the popular tables in a database or simply view them on our site.
Well, the solution to this problem is easier than you think.
It runs a project on Sourceforge that makes it available via the class ExcelReader everything we need.
Having included the two files reader.php and oleread.inc in our script and we will be ready to do the job "dirty".
First we initialize our class and then passiamogli the file to open:
$ data-> read ( 'nome_filel.xls'); The next thing to do, of course, is to make a loop for each row and column pointing out that:
$ data-> sheets [0] [ 'numRows']; $ data-> sheets [0] [ 'numCols'];
represent the number of rows and columns in the file xls (particularly in the first sheet of paper).
At this point we can take the value contained in each cell access it as we do with a trivial matrix:
$ data-> sheets [0] [ 'cells'] [$ i] [$ j]; A sample script to show a video data from a xls file in tabular form are the following:
<? require_once 'Excel / reader.php'; $ data = new Spreadsheet_Excel_Reader (); $ data-> setOutputEncoding ( 'CP1251'); $ data-> read ( 'nome_file.xls'); error_reporting (E_ALL ^ E_NOTICE); echo "<table>"; for ($ i = 1, $ i <= $ data-> sheets [0] [ 'numRows'], $ i + +) ( echo "<tr>"; for ($ j = 1, $ j <= $ data-> sheets [0] [ 'numCols'], $ j + +) ( echo "<td>. $ data-> sheets [0] [ 'cells'] [$ i] [$ j ]."</ td>"; ) echo "</ tr>"; ) echo "</ table>"; ?>
PS: Of course you can also loop on the sheets that compose the file .. xls
Popularity: 8% [?]
Tags: Excel, FAQs Help and Tutorials, Open Source, php, SourceForge.net
leave a response , or trackback from your own site. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.



![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=1a581053-a80a-4f72-acd1-fdf59ecf4c5a)
![Add '[Program] Read xls file with PHP' to Del.icio.us Aggiungi '[Programmazione] Leggere file xls con PHP' a Del.icio.us](http://www.vitruviantux.net/wp-content/plugins/social-bookmarking-reloaded/delicious.png)
![Add '[Program] Read xls file with PHP' to digg Aggiungi '[Programmazione] Leggere file xls con PHP' a digg](http://www.vitruviantux.net/wp-content/plugins/social-bookmarking-reloaded/digg.png)
![Add '[Program] Read xls file with PHP' to FURL Aggiungi '[Programmazione] Leggere file xls con PHP' a FURL](http://www.vitruviantux.net/wp-content/plugins/social-bookmarking-reloaded/furl.png)
![Add '[Program] Read xls file with PHP' to blinklist Aggiungi '[Programmazione] Leggere file xls con PHP' a blinklist](http://www.vitruviantux.net/wp-content/plugins/social-bookmarking-reloaded/blinklist.png)
![Add '[Program] Read xls file with PHP' to reddit Aggiungi '[Programmazione] Leggere file xls con PHP' a reddit](http://www.vitruviantux.net/wp-content/plugins/social-bookmarking-reloaded/reddit.png)
![Add '[Program] Read xls file with PHP' to Feed Me Links Aggiungi '[Programmazione] Leggere file xls con PHP' a Feed Me Links](http://www.vitruviantux.net/wp-content/plugins/social-bookmarking-reloaded/feedmelinks.png)
![Add '[Programming] Read xls file with PHP' to Technorati Aggiungi '[Programmazione] Leggere file xls con PHP' a Technorati](http://www.vitruviantux.net/wp-content/plugins/social-bookmarking-reloaded/technorati.png)
![Add '[Program] Read xls file with PHP' to Yahoo My Web Aggiungi '[Programmazione] Leggere file xls con PHP' a Yahoo My Web](http://www.vitruviantux.net/wp-content/plugins/social-bookmarking-reloaded/yahoo_myweb.png)
![Add '[Program] Read xls file with PHP' to Socializer Aggiungi '[Programmazione] Leggere file xls con PHP' a Socializer](http://www.vitruviantux.net/wp-content/plugins/social-bookmarking-reloaded/socializer.png)
![Add '[Program] Read xls file with PHP' to Ma.gnolia Aggiungi '[Programmazione] Leggere file xls con PHP' a Ma.gnolia](http://www.vitruviantux.net/wp-content/plugins/social-bookmarking-reloaded/magnolia.png)
![Add '[Program] Read xls file with PHP' to Google Bookmarks Aggiungi '[Programmazione] Leggere file xls con PHP' a Google Bookmarks](http://www.vitruviantux.net/wp-content/plugins/social-bookmarking-reloaded/google.png)
![Add '[Program] Read xls file with PHP' to Bloglines Aggiungi '[Programmazione] Leggere file xls con PHP' a Bloglines](http://www.vitruviantux.net/wp-content/plugins/social-bookmarking-reloaded/bloglines.png)
![Add '[Program] Read xls file with PHP' to Squidoo Aggiungi '[Programmazione] Leggere file xls con PHP' a OKnotizie](http://www.vitruviantux.net/wp-content/plugins/social-bookmarking-reloaded/oknotizie.gif)
![Add '[Program] Read xls file with PHP' to Bookmark.it Aggiungi '[Programmazione] Leggere file xls con PHP' a Bookmark.it](http://www.vitruviantux.net/wp-content/plugins/social-bookmarking-reloaded/bookmark.png)
![Add '[Program] Read xls file with PHP' to Ask Aggiungi '[Programmazione] Leggere file xls con PHP' a Ask](http://www.vitruviantux.net/wp-content/plugins/social-bookmarking-reloaded/ask.png)
![Add '[Program] Read xls file with PHP' to Delirious Aggiungi '[Programmazione] Leggere file xls con PHP' a Delirious](http://www.vitruviantux.net/wp-content/plugins/social-bookmarking-reloaded/delirious.png)
![Add '[Program] Read xls file with PHP' to Live-MSN Aggiungi '[Programmazione] Leggere file xls con PHP' a Live-MSN](http://www.vitruviantux.net/wp-content/plugins/social-bookmarking-reloaded/live.png)
![Add '[Program] Read xls file with PHP' to SlashDot Aggiungi '[Programmazione] Leggere file xls con PHP' a SlashDot](http://www.vitruviantux.net/wp-content/plugins/social-bookmarking-reloaded/slashdot.png)
![Add '[Programming] Read xls file with PHP' to Diggita Aggiungi '[Programmazione] Leggere file xls con PHP' a Diggita](http://www.vitruviantux.net/wp-content/plugins/social-bookmarking-reloaded/diggita.png)
![Add '[Program] Read xls file with PHP' to FaceBook Aggiungi '[Programmazione] Leggere file xls con PHP' a FaceBook](http://www.vitruviantux.net/wp-content/plugins/social-bookmarking-reloaded/facebook.png)
![Add '[Programming] Read xls file with PHP' to Wikio Aggiungi '[Programmazione] Leggere file xls con PHP' a Wikio](http://www.vitruviantux.net/wp-content/plugins/social-bookmarking-reloaded/wikio.png)
![Add '[Programming] Read xls file with PHP' to MySpace Aggiungi '[Programmazione] Leggere file xls con PHP' a MySpace](http://www.vitruviantux.net/wp-content/plugins/social-bookmarking-reloaded/myspace.png)
![Add '[Program] Read xls file with PHP' to Twitter Aggiungi '[Programmazione] Leggere file xls con PHP' a Twitter](http://www.vitruviantux.net/wp-content/plugins/social-bookmarking-reloaded/twitter.png)
![Add '[Programming] Read xls file with PHP' to Tailrank Aggiungi '[Programmazione] Leggere file xls con PHP' a Technotizie](http://www.vitruviantux.net/wp-content/plugins/social-bookmarking-reloaded/technotizie.png)
Leave a Reply