From 8bf4bad8496000f23ea5f48d6dccbb858bbd4bc3 Mon Sep 17 00:00:00 2001 From: Alone <675061370@qq.com> Date: Fri, 23 Aug 2024 15:32:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=87=BA=E5=A2=9E=E5=8A=A0xlsx?= =?UTF-8?q?=E3=80=81xls=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Source.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/app/admin/controller/Source.php b/app/admin/controller/Source.php index d220fe2..5f399b5 100644 --- a/app/admin/controller/Source.php +++ b/app/admin/controller/Source.php @@ -203,13 +203,20 @@ class Source extends QfShop ini_set("memory_limit",-1); $file_name = app()->getRootPath()."public/uploads/".$saveName; - //读取excel文件 - $PHPReader = new \PHPExcel_Reader_CSV(); - //默认输入字符集// 判断文件编码 - $encoding = $this->detectFileEncoding($file_name); - $PHPReader->setInputEncoding($encoding); - //默认的分隔符 - $PHPReader->setDelimiter(','); + + $extension = pathinfo($file_name, PATHINFO_EXTENSION); + if ($extension == 'csv') { + $PHPReader = new \PHPExcel_Reader_CSV(); + $PHPReader->setInputEncoding($encoding); + $PHPReader->setDelimiter(','); + } elseif ($extension == 'xlsx') { + $PHPReader = new \PHPExcel_Reader_Excel2007(); + } elseif ($extension == 'xls') { + $PHPReader = new \PHPExcel_Reader_Excel5(); + } else { + return jerr('不支持的文件类型'); + } + //载入文件 $objExcel = $PHPReader->load($file_name); $excel_array = $objExcel ->getSheet(0)->toArray();