You are here

public function PHPExcel_Shared_OLE::read in Loft Data Grids 6.2

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

* Reads an OLE container from the contents of the file given. * * @acces public *

Parameters

string $file: * @return mixed true on success, PEAR_Error on failure

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/OLE.php, line 96

Class

PHPExcel_Shared_OLE
OLE package base class.

Code

public function read($file) {
  $fh = fopen($file, "r");
  if (!$fh) {
    throw new PHPExcel_Reader_Exception("Can't open file {$file}");
  }
  $this->_file_handle = $fh;
  $signature = fread($fh, 8);
  if ("" != $signature) {
    throw new PHPExcel_Reader_Exception("File doesn't seem to be an OLE container.");
  }
  fseek($fh, 28);
  if (fread($fh, 2) != "") {

    // This shouldn't be a problem in practice
    throw new PHPExcel_Reader_Exception("Only Little-Endian encoding is supported.");
  }

  // Size of blocks and short blocks in bytes
  $this->bigBlockSize = pow(2, self::_readInt2($fh));
  $this->smallBlockSize = pow(2, self::_readInt2($fh));

  // Skip UID, revision number and version number
  fseek($fh, 44);

  // Number of blocks in Big Block Allocation Table
  $bbatBlockCount = self::_readInt4($fh);

  // Root chain 1st block
  $directoryFirstBlockId = self::_readInt4($fh);

  // Skip unused bytes
  fseek($fh, 56);

  // Streams shorter than this are stored using small blocks
  $this->bigBlockThreshold = self::_readInt4($fh);

  // Block id of first sector in Short Block Allocation Table
  $sbatFirstBlockId = self::_readInt4($fh);

  // Number of blocks in Short Block Allocation Table
  $sbbatBlockCount = self::_readInt4($fh);

  // Block id of first sector in Master Block Allocation Table
  $mbatFirstBlockId = self::_readInt4($fh);

  // Number of blocks in Master Block Allocation Table
  $mbbatBlockCount = self::_readInt4($fh);
  $this->bbat = array();

  // Remaining 4 * 109 bytes of current block is beginning of Master
  // Block Allocation Table
  $mbatBlocks = array();
  for ($i = 0; $i < 109; ++$i) {
    $mbatBlocks[] = self::_readInt4($fh);
  }

  // Read rest of Master Block Allocation Table (if any is left)
  $pos = $this
    ->_getBlockOffset($mbatFirstBlockId);
  for ($i = 0; $i < $mbbatBlockCount; ++$i) {
    fseek($fh, $pos);
    for ($j = 0; $j < $this->bigBlockSize / 4 - 1; ++$j) {
      $mbatBlocks[] = self::_readInt4($fh);
    }

    // Last block id in each block points to next block
    $pos = $this
      ->_getBlockOffset(self::_readInt4($fh));
  }

  // Read Big Block Allocation Table according to chain specified by
  // $mbatBlocks
  for ($i = 0; $i < $bbatBlockCount; ++$i) {
    $pos = $this
      ->_getBlockOffset($mbatBlocks[$i]);
    fseek($fh, $pos);
    for ($j = 0; $j < $this->bigBlockSize / 4; ++$j) {
      $this->bbat[] = self::_readInt4($fh);
    }
  }

  // Read short block allocation table (SBAT)
  $this->sbat = array();
  $shortBlockCount = $sbbatBlockCount * $this->bigBlockSize / 4;
  $sbatFh = $this
    ->getStream($sbatFirstBlockId);
  for ($blockId = 0; $blockId < $shortBlockCount; ++$blockId) {
    $this->sbat[$blockId] = self::_readInt4($sbatFh);
  }
  fclose($sbatFh);
  $this
    ->_readPpsWks($directoryFirstBlockId);
  return true;
}