|
 |
|
สอบถามเรื่องการตัดข้อความในไฟล์ Excel......(PHP, Excel (Excel.Application)) |
|
 |
|
|
 |
 |
|
Capture ไฟล์ กับเอา Code ที่เขียนปัจจุบันมาให้ดูหน่อยครับ 
|
 |
 |
 |
 |
Date :
2012-05-08 05:59:06 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
code page 1 Page 1Code (PHP)
<table width="670" border="0">
<tr>
<td height="35"><center>
<strong><font size="+1">ดึงข้อมูลจากไฟล์ Excel</font></strong>
</center></td>
</tr>
<tr>
<td><hr /></td>
</tr>
<tr>
<td><center><input type="file" name="fileUpload">
<font color="#FF0000">*แนบไฟล์ .csv เท่านั้น</font>
</center></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><center><div id="idProcessing" style="width: 35%; left: 40%; top: 70%; height: 13%; font-size: 32px; display: none;
z-index: 1; position: fixed; background-color:#FFF; color:#F00; padding: 10px 0; " >
<span style="margin-left: 75px;">กรุณารอสักครู่ <img src="images/loading.gif"></span> <span id="idDotAdding"></span>
</div>
<input name="submit2" type="submit" value="ค้นหา" onclick="this.blur(); Processing(); return true;"/>
<input name="submit3" type="reset" value="ยกเลิก" /></center></td>
</tr>
</table>
code page 2
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<?php
//echo "\$_FILES[\"fileUpload\"][\"name\"] = ".$_FILES["fileUpload"]["name"]."<br>";
//echo "\$_FILES[\"fileUpload\"][\"type\"] = ".$_FILES["fileUpload"]["type"]."<br>";
//echo "\$_FILES[\"fileUpload\"][\"size\"] = ".$_FILES["fileUpload"]["size"]."<br>";
//echo "\$_FILES[\"fileUpload\"][\"tmp_name\"] = ".$_FILES["fileUpload"]["tmp_name"]."<br>";
//echo "\$_FILES[\"fileUpload\"][\"error\"] = ".$_FILES["fileUpload"]["error"]."<br>";
if(move_uploaded_file($_FILES["fileUpload"]["tmp_name"],"".$_FILES["fileUpload"]["name"])) // Upload/Copy
{
echo "Copy/Upload Complete.";
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="98"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="59"> <div align="center">Budget </div></th>
<th width="71"> <div align="center">Used </div></th>
</tr>
<?
$objCSV = fopen("customer.csv", "r");
while (($objArr = fgetcsv($objCSV, 1000, ",")) !== FALSE) {
?>
<tr>
<td><div align="center"><?=$objArr[0];?></div></td>
<td><?=$objArr[1];?></td>
<td><?=$objArr[2];?></td>
<td><div align="center"><?=$objArr[3];?></div></td>
<td align="right"><?=$objArr[4];?></td>
<td align="right"><?=$objArr[5];?></td>
</tr>
<?
}
fclose($objCSV);
?>
</table>
<?
}
?>
</body>
</html>
ตัวอยา่งพอหนูลองเเสดงผลข้อมูลที่มีในไฟล์ excel Code (PHP)
echo $objArr[1]; //ตัวแปรอาร์เรย์ที่กำหนดช่องที่ต้องการให้เเสดงข้อมูลในช่องนั้นในไฟล์ excel
ซึ่งผลลัพท์ที่ได้จากการ echo คือ ปีการศึกษา : 2553 ภาคเรียนที่ : 2 เเต่หนูต้องการตัดเอาเเค่ 2553 กับ 2
ไม่ทราบว่าทำไงค่ะ
|
 |
 |
 |
 |
Date :
2012-05-08 15:32:43 |
By :
banana_bnn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูพวก substr() ครับ
Go to : PHP substr()
|
 |
 |
 |
 |
Date :
2012-05-08 22:26:49 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
explode ด้วย :
|
 |
 |
 |
 |
Date :
2012-05-09 00:24:08 |
By :
ikikkok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|