Import data from excel file to php database
You have an Excel file, and if you want to import that Excel file to your database, then fetch the cell value using these tutorials. You can directly import to your MySQL, MS SQL, and various databases using this library and tutorials. Just download the library and integrate the below code there.
Step 1)
Download the Excel read library from here. click here for download
Step 2)
Make a form for uploading your Excel file as below.
<html>
<body>
<form method="post" enctype="multipart/form-data">
<table>
<tr>
<td>
Select File:
</td>
<td>
<input type="file" name="file" id="file">
</td>
</tr>
<tr>
<td colspan="2" align="left">
<input type="submit" name="submit" value="Submit">
</td>
</tr>
</table>
</form>
</body>
</html>
Step 3)
Now make code to read the Excel file cell and import it to the database as below.
<?php
include('PHPExcel-1.8/Classes/PHPExcel/IOFactory.php');
if(isset($_POST["submit"]))
{
$inputFileName = $_FILES["file"]["tmp_name"];
try {
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);
} catch (Exception $e) {
die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' .
$e->getMessage());
}
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
$newArr = array();
for($row = 1; $row <= $highestRow; $row++) {
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, null, true, false);
array_push($newArr, $rowData);
}
echo "<pre>";
print_r($newArr);
echo "Record Update Successfully...";
}
?>
Step 4)
Now upload your Excel to the form and submit the Excel; it will return you all the cell values, which you will insert into your database.
I always emailed this webpage post page to all my associates, for the reason that if like to read it then my links will too.
This compares to the simply over 600 million who play games usually on PCs, and roughly 200 million for video games consoles.
Hello! I’ve been following your weblog for a long time now and finally got the bravery to go ahead and give you a shout out from Atascocita Tx! Just wanted to mention keep up the great work!
I needed to thank you for this good read!! I definitely enjoyed every little bit of it. I have you saved as a favorite to check out new things you
It’s very easy to find out any topic on web as compared to textbooks, as I found this paragraph at this web site.
Its excellent as your other posts :D, thank you for putting up.
Hello it’s me, I am also visiting this web page daily, this site is actually good and the viewers are truly sharing nice thoughts.
Hi man, This was a great page for such a hard subject to discuss. I look forward to reading many more great posts like these. Thanks.
Hi, I do believe this is a great site. I stumbledupon it 😉 I am going to come back once again since I book marked it. Money and freedom is the best way to change, may you be rich and continue to help other people.
Hey there! I just wish to give you a big thumbs up for your excellent info you have right here on this post. I am coming back to your site for more soon.
I needed to thank you for this very good read!! I definitely enjoyed every bit of it. I’ve got you book marked to check out new things you
I just could not depart your website before suggesting that I actually enjoyed the standard info an individual supply for your visitors? Is going to be back often in order to investigate cross-check new posts
I’ll immediately snatch your rss feed as I can’t find your e-mail subscription link or newsletter service. Do you have any? Please let me recognise in order that I may just subscribe. Thanks.
I love it when folks come together and share opinions. Great website, keep it up!
Currently it seems like WordPress is the best blogging platform out there right now. (from what I’ve read) Is that what you’re using on your blog?
Of course, what a magnificent blog and illuminating posts, I definitely will bookmark your blog.Best Regards!
**back biome**
Backbiome is a naturally crafted, research-backed daily supplement formulated to gently relieve back tension and soothe sciatic discomfort.