You are here

public static function PHPExcel_IOFactory::createReaderForFile in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php \PHPExcel_IOFactory::createReaderForFile()

* Create PHPExcel_Reader_IReader for file using automatic PHPExcel_Reader_IReader resolution * * @static * @access public *

Parameters

string $pFilename The name of the spreadsheet file: * @return PHPExcel_Reader_IReader * @throws PHPExcel_Reader_Exception

2 calls to PHPExcel_IOFactory::createReaderForFile()
PHPExcel_IOFactory::identify in vendor/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php
* Identify file type using automatic PHPExcel_Reader_IReader resolution * * @static * @access public *
PHPExcel_IOFactory::load in vendor/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php
* Loads PHPExcel from file using automatic PHPExcel_Reader_IReader resolution * * @static * @access public *

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php, line 221

Class

PHPExcel_IOFactory
PHPExcel_IOFactory

Code

public static function createReaderForFile($pFilename) {

  // First, lucky guess by inspecting file extension
  $pathinfo = pathinfo($pFilename);
  $extensionType = NULL;
  if (isset($pathinfo['extension'])) {
    switch (strtolower($pathinfo['extension'])) {
      case 'xlsx':

      //	Excel (OfficeOpenXML) Spreadsheet
      case 'xlsm':

      //	Excel (OfficeOpenXML) Macro Spreadsheet (macros will be discarded)
      case 'xltx':

      //	Excel (OfficeOpenXML) Template
      case 'xltm':

        //	Excel (OfficeOpenXML) Macro Template (macros will be discarded)
        $extensionType = 'Excel2007';
        break;
      case 'xls':

      //	Excel (BIFF) Spreadsheet
      case 'xlt':

        //	Excel (BIFF) Template
        $extensionType = 'Excel5';
        break;
      case 'ods':

      //	Open/Libre Offic Calc
      case 'ots':

        //	Open/Libre Offic Calc Template
        $extensionType = 'OOCalc';
        break;
      case 'slk':
        $extensionType = 'SYLK';
        break;
      case 'xml':

        //	Excel 2003 SpreadSheetML
        $extensionType = 'Excel2003XML';
        break;
      case 'gnumeric':
        $extensionType = 'Gnumeric';
        break;
      case 'htm':
      case 'html':
        $extensionType = 'HTML';
        break;
      case 'csv':

        // Do nothing
        // We must not try to use CSV reader since it loads
        // all files including Excel files etc.
        break;
      default:
        break;
    }
    if ($extensionType !== NULL) {
      $reader = self::createReader($extensionType);

      // Let's see if we are lucky
      if (isset($reader) && $reader
        ->canRead($pFilename)) {
        return $reader;
      }
    }
  }

  // If we reach here then "lucky guess" didn't give any result
  // Try walking through all the options in self::$_autoResolveClasses
  foreach (self::$_autoResolveClasses as $autoResolveClass) {

    //	Ignore our original guess, we know that won't work
    if ($autoResolveClass !== $extensionType) {
      $reader = self::createReader($autoResolveClass);
      if ($reader
        ->canRead($pFilename)) {
        return $reader;
      }
    }
  }
  throw new PHPExcel_Reader_Exception('Unable to identify a reader for this file');
}