TP5 do Excel import (with the Phpexcel Class), defective 2007 and 2003 can only be selected one

Source: Internet
Author: User
Tags bulk insert

 Public function Excelinsert ()    {        if($this->request->isPost ())        {            $filestr$ this->request->param ();

Loader::import (' Phpexcel ', extend_path);
Loader::import (' PHPExcel.Classes.PHPExcel.IOFactory.PHPExcel_IOFactory ');
Loader::import (' PHPExcel.PHPExcel.IOFactory ', extend_path);
Loader::import (' PHPExcel.PHPExcel.Reader.Excel5 ', extend_path);

       $file= Request ()file(' File '); $info=$file->validate ([' Size ' =>156780, ' ext ' = ' xlsx,xls,csv '])->move (Root_path. ' Public '. Ds. ' Excel '); if($info)            {                //echo $info->getfilename ();                $exclePath=$info->getsavename ();//Get file name                $file _name= Root_path. ' Public '. Ds. ' Excel '. Ds.$exclePath; $objReader=\phpexcel_iofactory::createreader (' Excel2007 '); $obj _phpexcel=$objReader->load ($file _name,$encode= ' utf-8 ');//loading file contents, encoding Utf-8                $excel _array=$obj _phpexcel->getsheet (0)->toarray ();//convert to array format                Array_shift($excel _array); $data= []; foreach($excel _array  as $k=$v)                {                    $data[$k[' price '] =isset($v[16]) ==true?$v[16]: '; $data[$k[' Group '] =isset($v[17]) ==true?$v[17]: '; $data[$k[' flag '] =isset($v[18]) ==true?$v[18]: '; $data[$k[' status '] = 1; }                $rtn= db::table (' table ')->insertall ($data);//BULK INSERT Data                if($rtn)                {                    $this->success (' Import done ')); }            }            Else            {                Echo $file-GetError (); }        }    }

Class placed in the Extend.

Tp5 do Excel import (with the Phpexcel Class), defective 2007 and 2003 can only be selected by one

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.