Public Function test ()
{
Set_time_limit (0);
Ini_set (' Memory_limit ', ' 500M ');
Import the Phpexcel class library because Phpexcel does not use a namespace, only inport import
Import ("Org.Excel.PHPExcel");
The XLS file to import, located in the public folder under the root directory
Create a Phpexcel object, note that there is no less \
$PHPExcel = new \phpexcel ();
If the Excel file suffix is named. xlsx, import this class
Import ("Org.Util.PHPExcel.Reader.Excel2007");
$PHPReader =new \phpexcel_reader_excel2007 ();
If the Excel file suffix name is. xls, import this class
Import ("Org.Util.PHPExcel.Reader.Excel5");
$PHPReader = new \phpexcel_reader_excel5 ();
if ($_post) {
$filePath = $_files[' FILES ' [' tmp_name '];
$PHPReader = new phpexcel_reader_excel2007 ();
$PHPReader = new \phpexcel_reader_excel2007 ();
if (! $filePath) {
echo "Return
}
if (! $PHPReader->canread ($filePath)) {
$PHPReader = new \phpexcel_reader_excel5 ();
if (! $PHPReader->canread ($filePath)) {
$PHPReader = new \phpexcel_reader_csv ();
if (! $PHPReader->canread ($filePath)) {
Echo ' no Excel ';
Return
}
}
}
$PHPExcel = $PHPReader->load ($filePath);
$currentSheet = $PHPExcel->getsheet (0);
/* Get a total number of columns */
$allColumn = $currentSheet->gethighestcolumn ();
/* Get a total number of lines */
$allRow = $currentSheet->gethighestrow ();
for ($currentRow =2; $currentRow <= $allRow; $currentRow + +) {
$trsaction _id = $currentSheet->getcell (' A '. $currentRow)->getvalue ();
Here the loop gets the result.
}
}
//-----------------------------------------------------------
$this->display ();
}
2. Page:
<! DOCTYPE html>
<meta charset= "UTF-8" >
<title></title>
<body>
<form action= "__url__/test" method= "post" enctype= "Multipart/form-data" >
Import: <input type= "file" name= "Files"/>
<input type= "Submit" Name= "sub" value= "Submit"/>
</form>
</body>
thinkphp3.2 Export