thinkphp3.2 Export

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.