|
 |
|
ขอ code php import excel file.xls ที่มากกว่า 1 sheet |
|
 |
|
|
 |
 |
|
PHPExcel
ลองศึกษาดูสามารถกำหนดให้มันอ่าน sheet ไหนก็ได้
|
 |
 |
 |
 |
Date :
2011-04-05 15:14:48 |
By :
naskw |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำ Sheet เดียวได้แล้ว Sheet อื่น ๆ ก็ไม่น่าจะยากครับ Code นี้เป็นการอ่านแบบ Multiple Sheet ครับ
Code (PHP)
<?
//*** 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;
?>
|
 |
 |
 |
 |
Date :
2011-04-05 15:15:55 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถามเพิ่มอีกนิสสค่ะ แล้วไฟล์ของพวก microsoft 2007 ที่นามสกุลจะมี 4 digit (xlsx) สามารถ upload ได้หรือป่าวคะ
|
 |
 |
 |
 |
Date :
2011-04-08 09:45:33 |
By :
yuri_arkin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|