How to use PHP & Read excel file (Excel.Application) The Learn / tutorial php programming how to using PHP Read excel file.
ShotDev Focus:
- PHP & Read excel file.
Example
php_read_excel.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 Excel.Application ***// $xlApp = new COM("Excel.Application"); $xlBook = $xlApp->Workbooks->Open($strPath."/".$OpenFile); //$xlBook = $xlApp->Workbooks->Open(realpath($OpenFile)); $xlSheet1 = $xlBook->Worksheets(1); ?> <table width="420" border="1"> <? $i=1; while($xlSheet1->Cells->Item($i,1) != "") { ?> <tr> <td><?=$xlSheet1->Cells->Item($i,1);?></td> <td><?=$xlSheet1->Cells->Item($i,2);?></td> <td><?=$xlSheet1->Cells->Item($i,3);?></td> <td><?=$xlSheet1->Cells->Item($i,4);?></td> <td><?=$xlSheet1->Cells->Item($i,5);?></td> <td><?=$xlSheet1->Cells->Item($i,6);?></td> </tr> <? $i = $i + 1; } ?> </table> <? //*** Close & Quit ***// $xlApp->Application->Quit(); $xlApp = null; $xlBook = null; $xlSheet1 = null; ?> </body> </html>
Create a php file and save to path root-path/myphp/
Run
http://localhost/myphp/php_read_excel.php
Screenshot