How can you read and display excel file using php and save that details to the database? You can use this simple php class to do this.That is read row by row while reading column by column.While reading like this it gets each cells details.Look at this example that is simply describes this process and you can understand this better.
First download excel reader.php class file. You can download reader.php file here.
Also you must include this oleread.inc file of this reader.php file.Download oleread.inc.
Here is the sample.xls file format.
How to read excel file using php
Sheet 1:
$cell | \n"; // get each cells values $y++; } echo "\t
Note:
This is reading sheet1 details.If you want to read sheet 2 details, then change the sheets[0] to sheets[1] in both while loops.
Example:
while($x<=$excel->sheets[0]['numRows']) {
Remember “sheets” is the array.Array begin from 0.You already know about it. 😀
So,
Sheet1 -> sheets[0]
Sheet2 -> sheets[1]
Sheet3 -> sheets[2]
How to read and save details to the database using php
Table structure
DROP TABLE IF EXISTS `users_details`; CREATE TABLE `users_details` ( `id` int(11) NOT NULL auto_increment, `name` varchar(255) default NULL, `job` varchar(255) default NULL, `email` varchar(255) default NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;
Save Excel file details to the database
That’s only.
Download full source code(20 KB)