Example of conducting a database on multiple Excel files in tp3.2

Source: Internet
Author: User
Templates page/index.html

  
   

Click Jump to control to put the Phpexcel file used in the tinkphp/vendor/excel/(the Excel folder should be created manually)

Public function uploads () {
$upload = new \think\upload ();//instantiation of upload class
$upload->maxsize = 3145728;//Set attachment upload size
$upload->exts = array (' jpg ', ' gif ', ' PNG ', ' jpeg ', ' xls ');//Set attachment upload type
Uploading files
$info = $upload->upload ();
if (! $info) {//Upload error error message
$this->error ($upload->geterror ());
}else{//Upload Success
foreach ($info as $file) {
$files = './public/'. $file [' Savepath ']. $file [' Savename '];
Vendor ("Excel.phpexcel");
Vendor ("Excel.PHPExcel.PHPExcel_IOFactory");
$PHPExcel = new \phpexcel ();
Var_dump ($PHPExcel);
$PHPReader = new \phpexcel_iofactory ();
Var_dump ($PHPReader);d ie;
$xlsPath = $files; Specifies the Exls path to read
$type = ' Excel2007 '; Set the type of Excel to resolve Excel5 (2003 or later) or Excel2007
Echo $xlsPath;
$type = ' Excel5 ';
$xlsReader = $PHPReader->createreader ($type);
$xlsReader->setreaddataonly (TRUE);
$xlsReader->setloadsheetsonly (TRUE);
$Sheets = $xlsReader->load ($xlsPath);
Start reading a
$Sheet = $Sheets->getsheet (0)->toarray (); Read the first worksheet (note number starting from 0) If reading multiple can do a loop 0,1,2,3 ....
Get the two-dimensional array, where each decimal group is a row of Excel table content containing data for each column of this row
Echo '

';
Print_r ($Sheet);

$model = M (' student ');//Successful upload of file information
$data [' name ']= $v [0];
$result = $model->add ($data);
if ($result) {
$this->success ("warehousing Success", U (' index/excellist '));
}else{
$this->error ("warehousing failure");
}
}
}
}
}

The above describes a number of Excel files on the tp3.2 in the database sample, including the contents of the content, I hope the PHP tutorial interested in a friend helpful.

  • Related Article

    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.