composer下载phpspreadsheet
composer require phpoffice/phpspreadsheet
封装
<?php
namespace app\index\lib;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use think\exception\ValidateException;
use think\facade\Filesystem;
class Excel
{
// excel导入
public static function importExcel($filename = "")
{
$file[] = $filename;
try {
// 验证文件大小,名称等是否正确
validate(['file' => 'filesize:51200|fileExt:xls,xlsx'])
->check($file);
// 将文件保存到本地
$savename = Filesystem::putFile('topic', $file[0]);
// 截取后缀
$fileExtendName = substr(strrchr($savename, '.'), 1);
// 有Xls和Xlsx格式两种
if ($fil