|
 |
|
อยากถามเรื่อง PHPExcel จะ Import Excel 2007 เข้า MSSQL |
|
 |
|
|
 |
 |
|
ผมใช้ Code นี้ครับ
Code (PHP)
<?php
/** PHPExcel */
require_once 'Classes/PHPExcel.php';
/** PHPExcel_IOFactory - Reader */
include 'Classes/PHPExcel/IOFactory.php';
$inputFileName = $upload;
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($inputFileName);
echo " >>> upload ".$inputFileName." +++ ".$inputFileType;
$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 />';
//*** Connect to MySQL Database ***//
$objConnect = mssql_connect("localhost","sa","1111");
$objDB = mssql_select_db("testupload");
$i = 0;
foreach ($namedDataArray as $result) {
$i++;
$strSQL = "";
$strSQL .= "INSERT INTO customer ";
$strSQL .= "(CustomerID,Name,Email,CountryCode,Budget,Used) ";
$strSQL .= "VALUES ";
$strSQL .= "('".$result["CustomerID"]."','".$result["Name"]."' ";
$strSQL .= ",'".$result["Email"]."','".$result["CountryCode"]."' ";
$strSQL .= ",'".$result["Budget"]."','".$result["Used"]."') ";
mssql_query($strSQL);
echo "Row $i Inserted...<br>";
}
mssql_close($objConnect);
?>
ปัญหาคือ ผมใช้ $upload แทนการดึงไฟล์ มันสามารถดึงข้อมูล จาก Excel 2003 ได้ ที่มีนามสกุล.xls แต่พอดึงข้อมูล จาก Excel 2007 ที่มีนามสกุล .xlsx
มันเกิด Error นี้ครับ Fatal error: Call to undefined method PHPExcel_Reader_CSV::setReadDataOnly() อยากทราบว่า เป็นเพราะอะไรครับ
Tag : PHP, Ms SQL Server 2005, Ms SQL Server 2008, Ms SQL Server 2012, Excel (Excel.Application)

|
|
 |
 |
 |
 |
Date :
2014-06-04 13:21:43 |
By :
NUENG |
View :
1401 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
PHPExcel เวอร์ชั่นเก่าหรือเปล่าครับ?
|
 |
 |
 |
 |
Date :
2014-06-04 13:52:20 |
By :
Manussawin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|