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.