Commit 27f71ded authored by 王源's avatar 王源
Browse files

[功能]添加xls报错处理

parent aec98c47
Loading
Loading
Loading
Loading
+8 −3
Original line number Original line Diff line number Diff line
@@ -19,10 +19,15 @@ class PhpSpreadsheetExceptionHandler extends ExceptionHandler
    public function handle(Throwable $throwable, ResponseInterface $response)
    public function handle(Throwable $throwable, ResponseInterface $response)
    {
    {
        $error = $throwable->getMessage();
        $error = $throwable->getMessage();
        if ($throwable instanceof PhpSpreadsheetException) {
            if (strpos($error, 'Formula Error') !== false) {
            if (strpos($error, 'Formula Error') !== false) {
                $msg = '表格公式错误, 请检查是否引用其它表格数据';
                $msg = '表格公式错误, 请检查是否引用其它表格数据';
                return $this->jsonResponse($msg, $response);
                return $this->jsonResponse($msg, $response);
            }
            }
        } else if (strpos($error, 'PhpOffice\PhpSpreadsheet\Writer\Xls::writeSummaryProp()') !== false) {
            $msg = '表格格式兼容错误,请上传 xlsx 结尾的excel';
            return $this->jsonResponse($msg, $response);
        }
        return $response;
        return $response;
    }
    }


@@ -40,7 +45,7 @@ class PhpSpreadsheetExceptionHandler extends ExceptionHandler


    public function isValid(Throwable $throwable): bool
    public function isValid(Throwable $throwable): bool
    {
    {
        return $throwable instanceof PhpSpreadsheetException;
        return true;
    }
    }


}
}