|
|
|
อยากรู้วิธีอ่านข้อมูลจาก excel ในกรณีต้องการอ่าน จาก excel ที่มี sheet1 , 2 ,3 |
|
|
|
|
|
|
|
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP(COM) Excel.Application 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);
?>
Sheet 1
<table width="420" border="1">
<?for($i=1;$i<=5;$i++){?>
<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>
</tr>
<?}?>
</table>
<?
$xlSheet2 = $xlBook->Worksheets(2);
?>
Sheet 2
<table width="420" border="1">
<?for($i=1;$i<=5;$i++){?>
<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>
</tr>
<?}?>
</table>
<?
//*** Close & Quit ***//
$xlApp->Application->Quit();
$xlApp = null;
$xlBook = null;
$xlSheet1 = null;
?>
</body>
</html>
Go to : PHP Read Excel Multiple Sheet (Excel.Application)
|
|
|
|
|
Date :
2011-06-04 09:35:12 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|