|
 |
|
ใช้ PHP อ่านไฟล์ Excel แล้วเอามาแสดงบน html ทำยังไงครับ |
|
 |
|
|
 |
 |
|
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);
?>
<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>
<?
//*** Close & Quit ***//
$xlApp->Application->Quit();
$xlApp = null;
$xlBook = null;
$xlSheet1 = null;
?>
</body>
</html>
Go to : PHP Read Excel (Excel.Application)
|
 |
 |
 |
 |
Date :
2010-11-19 12:42:13 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากครับพี่วิน
|
 |
 |
 |
 |
Date :
2010-11-19 13:00:56 |
By :
- - |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สำหรับคนใช้ phpexcel นะครับ เมือ่กี้ลืมใส่ - -
<?php
include(".../PHPExcel.php"); //ใส่ไฟล์ phpexcel
$objPHPExcel = PHPExcel_IOFactory::load("file/ex1.xls"); //โหลดไฟล์ excel
?>
<table width="420" border="1">
<? for($i=2;$i<8;$i++){?>
<tr>
<td><?=$objPHPExcel->getActiveSheet()->getCellByColumnAndRow(0,$i)->getValue();?></td> //ดึงค่ามาแสดง getCellByColumnAndRow(0,$i) 0 =column A, 1=column B, $i=แถวที่1,2,3
<td><?=$objPHPExcel->getActiveSheet()->getCellByColumnAndRow(1,$i)->getValue();?></td>
<td><?=$objPHPExcel->getActiveSheet()->getCellByColumnAndRow(2,$i)->getValue();?></td>
</tr>
<? }?>
</table>
|
 |
 |
 |
 |
Date :
2010-11-19 13:10:46 |
By :
- - |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ของตัวอย่างที่พี่แนะนำมันใช้ผ่าน DCOM น่ะครับ คือ Server จะต้องเป็น Windows และลง Microsoft Office Excel
|
 |
 |
 |
 |
Date :
2010-11-19 16:45:59 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|