web 2.0

How to use PHP & Import Excel Spreadsheet Data into Database (Excel.Application)

How to use PHP & Export Import Spreadsheet Data into Database (Excel.Application) The Learn / tutorial php programming how to using  PHP Import Excel Spreadsheet Data into Database.

ShotDev Focus:
- PHP  & Import Excel Spreadsheet Data into Database.

Example

php_excel_import.php


<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<?
//*** Get Document Path ***//
$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp
$OpenFile = "MyXls/MyExcelDB.xls";
//*** Create Exce.Application ***//
$xlApp = new COM("Excel.Application");
$xlBook = $xlApp->Workbooks->Open($strPath."/".$OpenFile);
//$xlBook = $xlApp->Workbooks->Open(realpath($OpenFile));

$xlSheet1 = $xlBook->Worksheets(1);

//*** Insert to MySQL Database ***//
$objConnect = mysql_connect("localhost","root","root") or die(mysql_error());
$objDB = mysql_select_db("mydatabase");

$i=2;
while($xlSheet1->Cells->Item($i,1) != "")
{
$strSQL = "";
$strSQL .= "INSERT INTO customer ";
$strSQL .= "(CustomerID,Name,Email,CountryCode,Budget,Used) ";
$strSQL .= "VALUES ";
$strSQL .= "('".$xlSheet1->Cells->Item($i,1)."','".$xlSheet1->Cells->Item($i,2)."' ";
$strSQL .= ",'".$xlSheet1->Cells->Item($i,3)."','".$xlSheet1->Cells->Item($i,4)."' ";
$strSQL .= ",'".$xlSheet1->Cells->Item($i,5)."','".$xlSheet1->Cells->Item($i,6)."') ";
mysql_query($strSQL);
$i++;
}

//*** Close MySQL ***//
@mysql_close($objConnect);

//*** Close & Quit ***//
$xlApp->Application->Quit();
$xlApp = null;
$xlBook = null;
$xlSheet1 = null;
?>
Data Import/Inserted.
</body>
</html>

Create a php file and save to path root-path/myphp/

Run
http://localhost/myphp/php_excel_import.php

Screenshot

PHP & Add Style & Import Excel Spreadsheet Data into Database
.
.
.

Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 1.00 out of 10)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.