|
 |
|
สอบถามเรื่อง excel หน่อยค่ะ มีไฟล์ excel ชื่อ mydata.xls ภายในมีอยู่ 2 sheet |
|
 |
|
|
 |
 |
|
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>
Ref : PHP Read Excel Multiple Sheet (Excel.Application)
|
 |
 |
 |
 |
Date :
2009-07-28 11:40:36 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พี่คะ ไม่ทราบว่า code ที่ให้นี้ถ้าเอาขึ้น server ต้องเพิ่มตรงไหนเปล่าคะ และอีกอย่าง ตรงคำว่า $xlBook = $xlApp->Workbooks->Open($strPath."/".$OpenFile); คงเดิมไว้หรือต้องเปลี่ยนตรง Workbooks
ส่วน $xlSheet1 = $xlBook->Worksheets(1); ต้องเปลี่ยนตรง Worksheets มั้ย
ขอบคุณค่ะ
|
 |
 |
 |
 |
Date :
2009-07-28 12:44:09 |
By :
น้องเอ๋ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|