web 2.0

How to use PHP & Connect Excel Using ADO (DRIVER={Microsoft Excel Driver (*.xls)})

How to use PHP & Connect Excel Using ADO (DRIVER={Microsoft Excel Driver (*.xls)}) The Learn / tutorial php programming how to using  PHP Connect Excel ADO Driver.

ShotDev Focus:
- PHP  & Connect Excel Using ADO.

PHP & Add Style & Connect Excel Using ADO

Example

php_excel_ado.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";

//*** Connect to ADO ***//
$strConn = new COM("ADODB.Connection");
$strConn->Open("DRIVER={Microsoft Excel Driver (*.xls)}; IMEX=1;
HDR=NO; Excel 8.0; DBQ=".$strPath."/".$OpenFile.";");
// DBQ=realpath($OpenFile)

//*** Select Sheet ***//
$strSQL = "SELECT * FROM [Sheet1$]";
$objRec = $strConn->Execute($strSQL);
?>
<table width="420" border="1">
<tr>
<td>CustomerID</td>
<td>Name</td>
<td>Email</td>
<td>CountryCode</td>
<td>Budget</td>
<td>Used</td>
</tr>
<?
While (!$objRec->EOF)
{
?>
<tr>
<td><?=$objRec->Fields["CustomerID"]->Value;?></td> <!-- $objRec->Fields(0)->Value or $objRec->Fields("Column1")->Value -->
<td><?=$objRec->Fields["Name"]->Value;?></td>
<td><?=$objRec->Fields["Email"]->Value;?></td>
<td><?=$objRec->Fields["CountryCode"]->Value;?></td>
<td><?=$objRec->Fields["Budget"]->Value;?></td>
<td><?=$objRec->Fields["Used"]->Value;?></td>
</tr>
<?
$objRec->MoveNext();
}
?>
</table>
<?
$objRec->Close();
$strConn->Close();
$strConn = null;
?>
</body>
</html>

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

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

Screenshot

PHP & Add Style & Connect Excel Using ADO
.
.
.

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.