基于yaf框架和uploadify插件,做的一个导入excel文件(2)

//上传文件处理 public function uploadExcelAction() { $targetFolder = '/public/uploadFile/'; // Relative to the root      $salt = 'test'; $verifyToken = md5($test . $_POST['guid']); if (!empty($_FILES) && $_POST['token'] == $verifyToken) { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; $targetFile = rtrim($targetPath,'https://www.jb51.net/') . 'https://www.jb51.net/' . $verifyToken.'.xlsx'; $fileTypes = array('xlsx'); $fileParts = pathinfo($_FILES['Filedata']['name']); if (in_array($fileParts['extension'],$fileTypes)) { move_uploaded_file($tempFile,$targetFile); echo '1'; } else { echo 'Invalid file type.'; } }else{ echo 'Invalid params.'; } die; }

处理excel数据,就说两个关键点:取单元格的值和背景色

   $objReader = \PHPExcel_IOFactory::createReader('Excel2007'); $objPHPExcel = $objReader->load($targetFile); $sheet = $objPHPExcel->getSheet(); $sheetRows = $sheet->getHighestDataRow(); // 取得总行数 $sheetColumns = PHPExcel_Cell::columnIndexFromString($sheet->getHighestDataColumn()); //列数 //读取单元格 $value = $objPHPExcel->getActiveSheet()->getCell($columns[$k] . $j)->getValue(); //获取每个单元格的值 $fillColor = $objPHPExcel->getActiveSheet()->getStyle($columns[$k] . $j)->getFill()->getStartColor()->getARGB(); //背景色

下面附图:

导入界面:

excel表:

基于yaf框架和uploadify插件,做的一个导入excel文件

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/8b3edd2d266dc1bb505e68363672cec0.html