|
 |
|
อยากสอบถามเรื่องการส่งค่าข้อมูลจาก Excel โดยใช้ ภาษา PHP |
|
 |
|
|
 |
 |
|
ผมทำการupload จาก Excel เพื่อมาแสดงในหน้าเว็บ โดยใช้ภาษา PHP

อยากจะสอบถามว่าจะทำยังไงให้เลือกข้อมูลที่เป็นประเภท Date ครับ เพราะมันดึงแต่ค่า Genaral หมดเลย แล้วค่าที่ Excel ที่เป็น Genaralในส่วนที่ผมกรอกเป็นวันที่มันแปลงออกมาเป็นตามภาพเลยครับ

ผมต้องการให้ StartPeriod, EndPeriod ,ExtendDate มันเลือกข้อมูลเป็นประเภทของ Date ต้องทำยังไงครับ
อันนี้ code ในการดึงข้อมูลมาแสดง ช่วยแปลงให้ StartPeriod, EndPeriod ,ExtendDate มันเลือกข้อมูลประเภท Date ทีนะครับ
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="customerss.php" method="get" enctype="multipart/form-data" name="form1" id="form1">
<label>
<input type="file" name="upload" id="upload" />
<input type="submit" name="button" id="button" value="Submit" />
</label>
</form>
<p></p>
<?php
/** PHPExcel */
require_once 'Classes/PHPExcel.php';
/** PHPExcel_IOFactory - Reader */
include 'Classes/PHPExcel/IOFactory.php';
//$inputFileName = "myData.xlsx";
$inputFileName = $upload;
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($inputFileName);
echo " >>> upload ".$inputFileName." +++ ".$inputFileType;
// for No header
$objWorksheet = $objPHPExcel->setActiveSheetIndex(0);
$highestRow = $objWorksheet->getHighestRow();
$highestColumn = $objWorksheet->getHighestColumn();
$r = -1;
$namedDataArray = array();
for ($row = 1; $row <= $highestRow; ++$row) {
$dataRow = $objWorksheet->rangeToArray('A'.$row.':'.$highestColumn.$row,null, true, true, true);
if ((isset($dataRow[$row]['A'])) && ($dataRow[$row]['A'] > '')) {
++$r;
$namedDataArray[$r] = $dataRow[$row];
}
}
$objWorksheet = $objPHPExcel->setActiveSheetIndex(0);
$highestRow = $objWorksheet->getHighestRow();
$highestColumn = $objWorksheet->getHighestColumn();
$headingsArray = $objWorksheet->rangeToArray('A1:'.$highestColumn.'1',null, true, true, true);
$headingsArray = $headingsArray[1];
$r = -1;
$namedDataArray = array();
for ($row = 2; $row <= $highestRow; ++$row) {
$dataRow = $objWorksheet->rangeToArray('A'.$row.':'.$highestColumn.$row,null, true, true, true);
if ((isset($dataRow[$row]['A'])) && ($dataRow[$row]['A'] > '')) {
++$r;
foreach($headingsArray as $columnKey => $columnHeading) {
$namedDataArray[$r][$columnHeading] = $dataRow[$row][$columnKey];
}
}
}
//echo '<pre>';
//var_dump($namedDataArray);
//echo '</pre><hr />';
?>
<form id="form2" name="form2" method="get" enctype="multipart/form-data" action="ExtendProjectSQL.php">
<table width="800" border="1">
<tr>
<td>CustomerCode</td>
<td>CustomerName</td>
<td>ProjectCode</td>
<td>Incoterm</td>
<td>StartPeriod</td>
<td>EndPeriod</td>
<td>ExtendDate</td>
<td>Offinvoice</td>
<td>Rebate</td>
<td>TotalDisc</td>
</tr>
<?
foreach ($namedDataArray as $result) {
?>
<tr>
<td><?=$result["CustomerCode"];?></td>
<td><?=$result["CustomerName"];?></td>
<td><?=$result["ProjectCode"];?></td>
<td><?=$result["Incoterm"];?></td>
<td><?=$result["StartPeriod"];?></td>
<td><?=$result["EndPeriod"];?></td>
<td><?=$result["ExtendDate"];?></td>
<td><?=$result["Offinvoice"];?></td>
<td><?=$result["Rebate"];?></td>
<td><?=$result["TotalDisc"];?></td>
</tr>
<?
}
?>
</table>
<p></p>
<input type="text" name="upload2" id="upload2" value= "<?=$upload ?>" readonly="readonly" />
<input type="submit" name="button2" id="button2" value="Confirm" />
</form>
</body>
</html>
ขอบคุณครับ
Tag : PHP, Ms SQL Server 2005, Ms SQL Server 2008, Ms SQL Server 2012, Excel (Excel.Application)

|
|
 |
 |
 |
 |
Date :
2014-06-06 15:59:42 |
By :
NUENG |
View :
1213 |
Reply :
6 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<td>'<?=$result["EndPeriod"];?></td>
มันก็แค่เพิ่ม ' มาข้างหน้าเองนะครับ
|
 |
 |
 |
 |
Date :
2014-06-06 16:24:17 |
By :
NUENG |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้ไหม๊ครับ
|
 |
 |
 |
 |
Date :
2014-06-06 16:38:26 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ได้อ่ะครับ มีวิธีอื่นอีกหรือป่าวครับ 
|
 |
 |
 |
 |
Date :
2014-06-06 17:01:06 |
By :
NUENG |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หรือไม่ก็แปลง PHP ให้เป็นรูปแบบวันที่ก่อนครับ เช่น 01-Jan-2014
|
 |
 |
 |
 |
Date :
2014-06-07 08:07:59 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือผมจะบอกว่า ในส่วนของ Excel อะครับ มันเป็นข้อมูลประเภท DATE ตามรูปก่อนลูกศรชี้ด้านบนของรูปใน Excel แต่พอผมเรียกผ่าน PHP นั้น มันกลับเรียกข้อมูลที่เป็นประเภท General ของ Excel อะครับ ผมควรไปแก้ไขตรงไหนดีครับ
|
ประวัติการแก้ไข 2014-06-09 11:43:51
 |
 |
 |
 |
Date :
2014-06-09 10:45:37 |
By :
nung006 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|