29    define(
'IDENTIFIER_OLE', pack(
'CCCCCCCC', 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1));
 
   76        public function read($sFileName)
 
   79                if(!is_readable($sFileName)) {
 
   80                        throw new PHPExcel_Reader_Exception(
"Could not open " . $sFileName . 
" for reading! File does not exist, or it is not readable.");
 
   85                $this->
data = file_get_contents($sFileName, FALSE, NULL, 0, 8);
 
   88                if ($this->
data != self::IDENTIFIER_OLE) {
 
   93                $this->
data = file_get_contents($sFileName);
 
   96                $this->numBigBlockDepotBlocks = 
self::_GetInt4d($this->
data, self::NUM_BIG_BLOCK_DEPOT_BLOCKS_POS);
 
  110                $bigBlockDepotBlocks = array();
 
  113                $bbdBlocks = $this->numBigBlockDepotBlocks;
 
  115                if ($this->numExtensionBlocks != 0) {
 
  119                for (
$i = 0; 
$i < $bbdBlocks; ++
$i) {
 
  124                for ($j = 0; $j < $this->numExtensionBlocks; ++$j) {
 
  125                        $pos = ($this->extensionBlock + 1) * self::BIG_BLOCK_SIZE;
 
  126                        $blocksToRead = min($this->numBigBlockDepotBlocks - $bbdBlocks, self::BIG_BLOCK_SIZE / 4 - 1);
 
  128                        for (
$i = $bbdBlocks; 
$i < $bbdBlocks + $blocksToRead; ++
$i) {
 
  133                        $bbdBlocks += $blocksToRead;
 
  134                        if ($bbdBlocks < $this->numBigBlockDepotBlocks) {
 
  140                $this->bigBlockChain = 
'';
 
  141                $bbs = self::BIG_BLOCK_SIZE / 4;
 
  142                for (
$i = 0; 
$i < $this->numBigBlockDepotBlocks; ++
$i) {
 
  143                        $pos = ($bigBlockDepotBlocks[
$i] + 1) * self::BIG_BLOCK_SIZE;
 
  145                        $this->bigBlockChain .= substr($this->
data, $pos, 4*$bbs);
 
  150                $sbdBlock = $this->sbdStartBlock;
 
  151                $this->smallBlockChain = 
'';
 
  152                while ($sbdBlock != -2) {
 
  153                        $pos = ($sbdBlock + 1) * self::BIG_BLOCK_SIZE;
 
  155                        $this->smallBlockChain .= substr($this->
data, $pos, 4*$bbs);
 
  162                $block = $this->rootStartBlock;
 
  181                if ($this->props[
$stream][
'size'] < self::SMALL_BLOCK_THRESHOLD) {
 
  182                        $rootdata = $this->
_readData($this->props[$this->rootentry][
'startBlock']);
 
  184                        $block = $this->props[
$stream][
'startBlock'];
 
  186                        while ($block != -2) {
 
  188                                $streamData .= substr($rootdata, $pos, self::SMALL_BLOCK_SIZE);
 
  196                        if ($this->props[
$stream][
'size'] % self::BIG_BLOCK_SIZE != 0) {
 
  200                        if ($numBlocks == 0) 
return '';
 
  202                        $block = $this->props[
$stream][
'startBlock'];
 
  204                        while ($block != -2) {
 
  205                                $pos = ($block + 1) * self::BIG_BLOCK_SIZE;
 
  206                                $streamData .= substr($this->
data, $pos, self::BIG_BLOCK_SIZE);
 
  225                while ($block != -2)  {
 
  226                        $pos = ($block + 1) * self::BIG_BLOCK_SIZE;
 
  227                        $data .= substr($this->
data, $pos, self::BIG_BLOCK_SIZE);
 
  240                $entryLen = strlen($this->entry);
 
  241                while ($offset < $entryLen) {
 
  243                        $d = substr($this->entry, $offset, self::PROPERTY_STORAGE_BLOCK_SIZE);
 
  246                        $nameSize = ord(
$d[self::SIZE_OF_NAME_POS]) | (ord(
$d[self::SIZE_OF_NAME_POS+1]) << 8);
 
  249                        $type = ord(
$d[self::TYPE_POS]);
 
  257                        $name = str_replace(
"\x00", 
"", substr(
$d,0,$nameSize));
 
  260                        $this->props[] = array (
 
  263                                'startBlock' => $startBlock,
 
  267                        $upName = strtoupper(
$name);
 
  270                        if (($upName === 
'WORKBOOK') || ($upName === 
'BOOK')) {
 
  271                                $this->wrkbook = count($this->props) - 1;
 
  273                        else if ( $upName === 
'ROOT ENTRY' || $upName === 
'R') {
 
  275                                $this->rootentry = count($this->props) - 1;
 
  279                        if (
$name == chr(5) . 
'SummaryInformation') {
 
  281                                $this->summaryInformation = count($this->props) - 1;
 
  285                        if (
$name == chr(5) . 
'DocumentSummaryInformation') {
 
  287                                $this->documentSummaryInformation = count($this->props) - 1;
 
  307                $_or_24 = ord(
$data[$pos + 3]);
 
  308                if ($_or_24 >= 128) {
 
  310                        $_ord_24 = -abs((256 - $_or_24) << 24);
 
  312                        $_ord_24 = ($_or_24 & 127) << 24;
 
  314                return ord(
$data[$pos]) | (ord(
$data[$pos + 1]) << 8) | (ord(
$data[$pos + 2]) << 16) | $_ord_24;
 
An exception for terminatinating execution or to throw for unit testing.
const PROPERTY_STORAGE_BLOCK_SIZE
const BIG_BLOCK_DEPOT_BLOCKS_POS
const SMALL_BLOCK_DEPOT_BLOCK_POS
read($sFileName)
Read the file.
static _GetInt4d($data, $pos)
Read 4 bytes of data at specified position.
_readData($bl)
Read a standard stream (by joining sectors using information from SAT)
getStream($stream)
Extract binary stream data.
const SMALL_BLOCK_THRESHOLD
const NUM_EXTENSION_BLOCK_POS
const ROOT_START_BLOCK_POS
const NUM_BIG_BLOCK_DEPOT_BLOCKS_POS
_readPropertySets()
Read entries in the directory stream.
const EXTENSION_BLOCK_POS
$documentSummaryInformation
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
$stream
PHP stream implementation.
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'