You are here

public function PHPExcel_Shared_OLERead::read in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/OLERead.php \PHPExcel_Shared_OLERead::read()

* Read the file * *

Parameters

$sFileName string Filename: * @throws PHPExcel_Reader_Exception

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/OLERead.php, line 76

Class

PHPExcel_Shared_OLERead

Code

public function read($sFileName) {

  // Check if file exists and is readable
  if (!is_readable($sFileName)) {
    throw new PHPExcel_Reader_Exception("Could not open " . $sFileName . " for reading! File does not exist, or it is not readable.");
  }

  // Get the file identifier
  // Don't bother reading the whole file until we know it's a valid OLE file
  $this->data = file_get_contents($sFileName, FALSE, NULL, 0, 8);

  // Check OLE identifier
  if ($this->data != self::IDENTIFIER_OLE) {
    throw new PHPExcel_Reader_Exception('The filename ' . $sFileName . ' is not recognised as an OLE file');
  }

  // Get the file data
  $this->data = file_get_contents($sFileName);

  // Total number of sectors used for the SAT
  $this->numBigBlockDepotBlocks = self::_GetInt4d($this->data, self::NUM_BIG_BLOCK_DEPOT_BLOCKS_POS);

  // SecID of the first sector of the directory stream
  $this->rootStartBlock = self::_GetInt4d($this->data, self::ROOT_START_BLOCK_POS);

  // SecID of the first sector of the SSAT (or -2 if not extant)
  $this->sbdStartBlock = self::_GetInt4d($this->data, self::SMALL_BLOCK_DEPOT_BLOCK_POS);

  // SecID of the first sector of the MSAT (or -2 if no additional sectors are used)
  $this->extensionBlock = self::_GetInt4d($this->data, self::EXTENSION_BLOCK_POS);

  // Total number of sectors used by MSAT
  $this->numExtensionBlocks = self::_GetInt4d($this->data, self::NUM_EXTENSION_BLOCK_POS);
  $bigBlockDepotBlocks = array();
  $pos = self::BIG_BLOCK_DEPOT_BLOCKS_POS;
  $bbdBlocks = $this->numBigBlockDepotBlocks;
  if ($this->numExtensionBlocks != 0) {
    $bbdBlocks = (self::BIG_BLOCK_SIZE - self::BIG_BLOCK_DEPOT_BLOCKS_POS) / 4;
  }
  for ($i = 0; $i < $bbdBlocks; ++$i) {
    $bigBlockDepotBlocks[$i] = self::_GetInt4d($this->data, $pos);
    $pos += 4;
  }
  for ($j = 0; $j < $this->numExtensionBlocks; ++$j) {
    $pos = ($this->extensionBlock + 1) * self::BIG_BLOCK_SIZE;
    $blocksToRead = min($this->numBigBlockDepotBlocks - $bbdBlocks, self::BIG_BLOCK_SIZE / 4 - 1);
    for ($i = $bbdBlocks; $i < $bbdBlocks + $blocksToRead; ++$i) {
      $bigBlockDepotBlocks[$i] = self::_GetInt4d($this->data, $pos);
      $pos += 4;
    }
    $bbdBlocks += $blocksToRead;
    if ($bbdBlocks < $this->numBigBlockDepotBlocks) {
      $this->extensionBlock = self::_GetInt4d($this->data, $pos);
    }
  }
  $pos = 0;
  $this->bigBlockChain = '';
  $bbs = self::BIG_BLOCK_SIZE / 4;
  for ($i = 0; $i < $this->numBigBlockDepotBlocks; ++$i) {
    $pos = ($bigBlockDepotBlocks[$i] + 1) * self::BIG_BLOCK_SIZE;
    $this->bigBlockChain .= substr($this->data, $pos, 4 * $bbs);
    $pos += 4 * $bbs;
  }
  $pos = 0;
  $sbdBlock = $this->sbdStartBlock;
  $this->smallBlockChain = '';
  while ($sbdBlock != -2) {
    $pos = ($sbdBlock + 1) * self::BIG_BLOCK_SIZE;
    $this->smallBlockChain .= substr($this->data, $pos, 4 * $bbs);
    $pos += 4 * $bbs;
    $sbdBlock = self::_GetInt4d($this->bigBlockChain, $sbdBlock * 4);
  }

  // read the directory stream
  $block = $this->rootStartBlock;
  $this->entry = $this
    ->_readData($block);
  $this
    ->_readPropertySets();
}