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);
99 $this->rootStartBlock = self::_GetInt4d($this->
data, self::ROOT_START_BLOCK_POS);
102 $this->sbdStartBlock = self::_GetInt4d($this->
data, self::SMALL_BLOCK_DEPOT_BLOCK_POS);
105 $this->extensionBlock = self::_GetInt4d($this->
data, self::EXTENSION_BLOCK_POS);
108 $this->numExtensionBlocks = self::_GetInt4d($this->
data, self::NUM_EXTENSION_BLOCK_POS);
110 $bigBlockDepotBlocks =
array();
111 $pos = self::BIG_BLOCK_DEPOT_BLOCKS_POS;
113 $bbdBlocks = $this->numBigBlockDepotBlocks;
115 if ($this->numExtensionBlocks != 0) {
116 $bbdBlocks = (self::BIG_BLOCK_SIZE - self::BIG_BLOCK_DEPOT_BLOCKS_POS)/4;
119 for (
$i = 0;
$i < $bbdBlocks; ++
$i) {
120 $bigBlockDepotBlocks[
$i] = self::_GetInt4d($this->
data, $pos);
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) {
129 $bigBlockDepotBlocks[
$i] = self::_GetInt4d($this->
data, $pos);
133 $bbdBlocks += $blocksToRead;
134 if ($bbdBlocks < $this->numBigBlockDepotBlocks) {
135 $this->extensionBlock = self::_GetInt4d($this->
data, $pos);
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);
158 $sbdBlock = self::_GetInt4d($this->bigBlockChain, $sbdBlock*4);
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) {
187 $pos = $block * self::SMALL_BLOCK_SIZE;
188 $streamData .= substr($rootdata, $pos, self::SMALL_BLOCK_SIZE);
190 $block = self::_GetInt4d($this->smallBlockChain, $block*4);
195 $numBlocks = $this->props[
$stream][
'size'] / self::BIG_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);
207 $block = self::_GetInt4d($this->bigBlockChain, $block*4);
225 while ($block != -2) {
226 $pos = ($block + 1) * self::BIG_BLOCK_SIZE;
227 $data .= substr($this->
data, $pos, self::BIG_BLOCK_SIZE);
228 $block = self::_GetInt4d($this->bigBlockChain, $block*4);
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]);
253 $startBlock = self::_GetInt4d(
$d, self::START_BLOCK_POS);
255 $size = self::_GetInt4d(
$d, self::SIZE_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;
290 $offset += self::PROPERTY_STORAGE_BLOCK_SIZE;
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;
const NUM_EXTENSION_BLOCK_POS
static _GetInt4d($data, $pos)
Read 4 bytes of data at specified position.
getStream($stream)
Extract binary stream data.
const SMALL_BLOCK_DEPOT_BLOCK_POS
$documentSummaryInformation
_readData($bl)
Read a standard stream (by joining sectors using information from SAT)
$stream
PHP stream implementation.
const BIG_BLOCK_DEPOT_BLOCKS_POS
read($sFileName)
Read the file.
Create styles array
The data for the language used.
_readPropertySets()
Read entries in the directory stream.
const EXTENSION_BLOCK_POS
const SMALL_BLOCK_THRESHOLD
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
const ROOT_START_BLOCK_POS
const NUM_BIG_BLOCK_DEPOT_BLOCKS_POS
const PROPERTY_STORAGE_BLOCK_SIZE
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d