). */ use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Reader\Xls; use PhpOffice\PhpSpreadsheet\Reader\Xlsx; use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException; use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException; require_once dirname(__FILE__, 2) . '/base/delegate/delegate.class.php'; class phpExcel extends baseDelegate { protected static $className = 'PhpOffice\PhpSpreadsheet\Spreadsheet'; public function __construct() { $this->instance = new static::$className(); } public static function load($file) { return IOFactory::load($file); } public function createReader($type = 'Xlsx') { try { return IOFactory::createReader($type); } catch (ReaderException $e) { throw new Exception('Create reader error, the error message is ' . $e->getMessage()); } } public function createWriter($type = 'Xlsx') { try { return IOFactory::createWriter($this->instance, ucfirst($type)); } catch (WriterException $e) { throw new Exception('Create writer error, the error message is ' . $e->getMessage()); } } public static function canRead($file) { try { $fileType = IOFactory::identify($file); $reader = IOFactory::createReader($fileType); return $reader instanceof Xls || $reader instanceof Xlsx; } catch (ReaderException $e) { return false; } } }