How to tell what Excel version?

Topics: User Forum
Jul 9, 2010 at 3:20 PM
Edited Jul 9, 2010 at 3:21 PM
I am going to use this class to allow users to import records from Excel files into our database.
I need to know how to tell what version the files are so I will know which reader to implement.
Or do you have better ideas?
Jul 9, 2010 at 10:00 PM

Aside from testing the file extension:

$loaderList = array('xls' => 'Excel5', 'xlsx' => 'Excel2007', 'ods' => 'OOCalc');
$extension = strtolower(fileinfo($fileName,PATHINFO_EXTENSION));
if (array_key_exists($extension,$loaderList)) {
   $loaderType = $loaderList[$extension];
} else {
   die('Invalid File Type');
$objReader = PHPExcel_IOFactory::createReader($loaderType);
$objPHPExcel = $objReader->load($fileName);

alternatively, use the autoloader option, which will try and determine the appropriate loader to use:

$objPHPExcel = PHPExcel_IOFactory::load($fileName);