Original article from (www.ympfb.com/show-29-154…

You must use think\PHPExcel before using it; Composer require phpoffice/ phpExcel

Public function save(){ini_set('memory_limit','1024M'); // Load the third-party class file require_once ".. /extend/PHPExcel/PHPExcel.php"; // Prevent garbled header(" content-type :text/ HTML; charset=utf-8"); $file = $_FILES['file']; $file = $_FILES['file']; $extension = strtolower(pathinfo($file['name'],PATHINFO_EXTENSION)); $objReader =\PHPExcel_IOFactory::createReader(' excel_iofactory '); $objReader =\PHPExcel_IOFactory::createReader(' excel '); $objReader = PHPExcel_IOFactory::createReader('Excel5'); $objReader = PHPExcel_IOFactory::createReader('Excel5'); } $objContent = $objReader -> load($file['tmp_name']); if ($objContent){ $sheetContent = $objContent -> getSheet(0) -> toArray(); //dump($sheetContent); die; $sheetContent = count($sheetContent); $sheetContent = count($sheetContent); //var_dump($len); exit; If ($len == 1){echo "<script>alert($len == 1); window.history.back(); </script>"; exit(); } for($i = 1; $i<$len; $i++){ $data = [ 'id' => '', 'phone' => $sheetContent[$i][0], 'company_name' => $sheetContent[$i][1], 'add_id' => $sheetContent[$i][2], 'industry_id' => $sheetContent[$i][3], 'data_name' => $sheetContent[$i][4], 'data_address' => $sheetContent[$i][5], 'data_class' => $sheetContent[$i][6], 'data_set_up_date' => $sheetContent[$i][6], 'create_time' => date('Y-m-d') ]; //dump($data); die; $re = Db::name('data_decoration_company')->insert($data); } //var_dump($res); die; If ($re){echo "<script>alert(' import successful '); window.history.back(); </script>"; exit(); $this->redirect('/')->remember(); }else{echo "<script>alert(' import failed, slow slow @! @ This computer's brain can't keep up with you '); window.history.back(); </script>"; exit(); $this->redirect('/')->remember(); }}else{$this->error($this->error) '); }}Copy the code