How to use PHP & Read Multiple Worksheet from excel (Excel.Application) The Learn / tutorial php programming how to using PHP Read Multiple Worksheet from excel.
ShotDev Focus:
- PHP & Read Multiple Worksheet from excel.
Example
php_read_multiple.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); ?> Sheet 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> <? $xlSheet2 = $xlBook->Worksheets(2); ?> Sheet 2 <table width="420" border="1"> <? $i=1; while($xlSheet2->Cells->Item($i,1) != "") { ?> <tr> <td><?=$xlSheet2->Cells->Item($i,1);?></td> <td><?=$xlSheet2->Cells->Item($i,2);?></td> <td><?=$xlSheet2->Cells->Item($i,3);?></td> <td><?=$xlSheet2->Cells->Item($i,4);?></td> <td><?=$xlSheet2->Cells->Item($i,5);?></td> <td><?=$xlSheet2->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_multiple.php
Screenshot