<html> <head> <title>ThaiCreate.Com PHP(COM) Excel.Application Tutorial</title> </head> <body> <?php //*** 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); ?> <table width="420" border="1"> <?php for($i=1;$i<=5;$i++){?> <tr> <td><?php echo $xlSheet1->Cells->Item($i,1);?></td> <td><?php echo $xlSheet1->Cells->Item($i,2);?></td> <td><?php echo $xlSheet1->Cells->Item($i,3);?></td> <td><?php echo $xlSheet1->Cells->Item($i,4);?></td> </tr> <?php }?> </table> <?php //*** Close & Quit ***// $xlApp->Application->Quit(); $xlApp = null; $xlBook = null; $xlSheet1 = null; ?> </body> </html>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท