50 define(
'NUM_BIG_BLOCK_DEPOT_BLOCKS_POS', 0x2c);
51 define(
'SMALL_BLOCK_DEPOT_BLOCK_POS', 0x3c);
52 define(
'ROOT_START_BLOCK_POS', 0x30);
53 define(
'BIG_BLOCK_SIZE', 0x200);
54 define(
'SMALL_BLOCK_SIZE', 0x40);
55 define(
'EXTENSION_BLOCK_POS', 0x44);
56 define(
'NUM_EXTENSION_BLOCK_POS', 0x48);
57 define(
'PROPERTY_STORAGE_BLOCK_SIZE', 0x80);
58 define(
'BIG_BLOCK_DEPOT_BLOCKS_POS', 0x4c);
59 define(
'SMALL_BLOCK_THRESHOLD', 0x1000);
61 define(
'SIZE_OF_NAME_POS', 0x40);
62 define(
'TYPE_POS', 0x42);
63 define(
'START_BLOCK_POS', 0x74);
64 define(
'SIZE_POS', 0x78);
65 define(
'IDENTIFIER_OLE', pack(
"CCCCCCCC",0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1));
69 $value = ord($data[$pos]) | (ord($data[$pos+1]) << 8) | (ord($data[$pos+2]) << 16) | (ord($data[$pos+3]) << 24);
70 if ($value>=4294967294) {
78 $k = array(
'seconds',
'minutes',
'hours',
'mday',
'wday',
'mon',
'year',
'yday',
'weekday',
'month',0);
79 return(
array_comb($k,split(
":",gmdate(
's:i:G:j:w:n:Y:z:l:F:U',is_null($ts)?time():$ts))));
85 foreach ($array1 as $key => $value) {
86 $out[$value] = $array2[$key];
91 function v($data,$pos) {
92 return ord($data[$pos]) | ord($data[$pos+1])<<8;
101 if(!is_readable($sFileName)) {
105 $this->data = @file_get_contents($sFileName);
120 $bigBlockDepotBlocks = array();
122 $bbdBlocks = $this->numBigBlockDepotBlocks;
123 if ($this->numExtensionBlocks != 0) {
127 for ($i = 0; $i < $bbdBlocks; $i++) {
128 $bigBlockDepotBlocks[$i] =
GetInt4d($this->data, $pos);
133 for ($j = 0; $j < $this->numExtensionBlocks; $j++) {
135 $blocksToRead = min($this->numBigBlockDepotBlocks - $bbdBlocks,
BIG_BLOCK_SIZE / 4 - 1);
137 for ($i = $bbdBlocks; $i < $bbdBlocks + $blocksToRead; $i++) {
138 $bigBlockDepotBlocks[$i] =
GetInt4d($this->data, $pos);
142 $bbdBlocks += $blocksToRead;
143 if ($bbdBlocks < $this->numBigBlockDepotBlocks) {
144 $this->extensionBlock =
GetInt4d($this->data, $pos);
151 $this->bigBlockChain = array();
153 for ($i = 0; $i < $this->numBigBlockDepotBlocks; $i++) {
157 $this->bigBlockChain[$index] =
GetInt4d($this->data, $pos);
166 $sbdBlock = $this->sbdStartBlock;
167 $this->smallBlockChain = array();
169 while ($sbdBlock != -2) {
172 $this->smallBlockChain[$index] =
GetInt4d($this->data, $pos);
176 $sbdBlock = $this->bigBlockChain[$sbdBlock];
181 $block = $this->rootStartBlock;
191 while ($block != -2) {
194 $block = $this->bigBlockChain[$block];
201 while ($offset < strlen($this->entry)) {
208 for ($i = 0; $i < $nameSize ; $i++) {
211 $name = str_replace(
"\x00",
"", $name);
212 $this->props[] = array (
215 'startBlock' => $startBlock,
217 if ((strtolower($name) ==
"workbook") || ( strtolower($name) ==
"book")) {
218 $this->wrkbook = count($this->props) - 1;
220 if ($name ==
"Root Entry") {
221 $this->rootentry = count($this->props) - 1;
231 $rootdata = $this->
__readData($this->props[$this->rootentry][
'startBlock']);
233 $block = $this->props[$this->wrkbook][
'startBlock'];
235 while ($block != -2) {
237 $streamData .= substr($rootdata, $pos, SMALL_BLOCK_SIZE);
238 $block = $this->smallBlockChain[$block];
242 $numBlocks = $this->props[$this->wrkbook][
'size'] /
BIG_BLOCK_SIZE;
247 if ($numBlocks == 0)
return '';
249 $block = $this->props[$this->wrkbook][
'startBlock'];
251 while ($block != -2) {
254 $block = $this->bigBlockChain[$block];
262 define(
'SPREADSHEET_EXCEL_READER_BIFF8', 0x600);
263 define(
'SPREADSHEET_EXCEL_READER_BIFF7', 0x500);
264 define(
'SPREADSHEET_EXCEL_READER_WORKBOOKGLOBALS', 0x5);
265 define(
'SPREADSHEET_EXCEL_READER_WORKSHEET', 0x10);
266 define(
'SPREADSHEET_EXCEL_READER_TYPE_BOF', 0x809);
267 define(
'SPREADSHEET_EXCEL_READER_TYPE_EOF', 0x0a);
268 define(
'SPREADSHEET_EXCEL_READER_TYPE_BOUNDSHEET', 0x85);
269 define(
'SPREADSHEET_EXCEL_READER_TYPE_DIMENSION', 0x200);
270 define(
'SPREADSHEET_EXCEL_READER_TYPE_ROW', 0x208);
271 define(
'SPREADSHEET_EXCEL_READER_TYPE_DBCELL', 0xd7);
272 define(
'SPREADSHEET_EXCEL_READER_TYPE_FILEPASS', 0x2f);
273 define(
'SPREADSHEET_EXCEL_READER_TYPE_NOTE', 0x1c);
274 define(
'SPREADSHEET_EXCEL_READER_TYPE_TXO', 0x1b6);
275 define(
'SPREADSHEET_EXCEL_READER_TYPE_RK', 0x7e);
276 define(
'SPREADSHEET_EXCEL_READER_TYPE_RK2', 0x27e);
277 define(
'SPREADSHEET_EXCEL_READER_TYPE_MULRK', 0xbd);
278 define(
'SPREADSHEET_EXCEL_READER_TYPE_MULBLANK', 0xbe);
279 define(
'SPREADSHEET_EXCEL_READER_TYPE_INDEX', 0x20b);
280 define(
'SPREADSHEET_EXCEL_READER_TYPE_SST', 0xfc);
281 define(
'SPREADSHEET_EXCEL_READER_TYPE_EXTSST', 0xff);
282 define(
'SPREADSHEET_EXCEL_READER_TYPE_CONTINUE', 0x3c);
283 define(
'SPREADSHEET_EXCEL_READER_TYPE_LABEL', 0x204);
284 define(
'SPREADSHEET_EXCEL_READER_TYPE_LABELSST', 0xfd);
285 define(
'SPREADSHEET_EXCEL_READER_TYPE_NUMBER', 0x203);
286 define(
'SPREADSHEET_EXCEL_READER_TYPE_NAME', 0x18);
287 define(
'SPREADSHEET_EXCEL_READER_TYPE_ARRAY', 0x221);
288 define(
'SPREADSHEET_EXCEL_READER_TYPE_STRING', 0x207);
289 define(
'SPREADSHEET_EXCEL_READER_TYPE_FORMULA', 0x406);
290 define(
'SPREADSHEET_EXCEL_READER_TYPE_FORMULA2', 0x6);
291 define(
'SPREADSHEET_EXCEL_READER_TYPE_FORMAT', 0x41e);
292 define(
'SPREADSHEET_EXCEL_READER_TYPE_XF', 0xe0);
293 define(
'SPREADSHEET_EXCEL_READER_TYPE_BOOLERR', 0x205);
294 define(
'SPREADSHEET_EXCEL_READER_TYPE_FONT', 0x0031);
295 define(
'SPREADSHEET_EXCEL_READER_TYPE_PALETTE', 0x0092);
296 define(
'SPREADSHEET_EXCEL_READER_TYPE_UNKNOWN', 0xffff);
297 define(
'SPREADSHEET_EXCEL_READER_TYPE_NINETEENFOUR', 0x22);
298 define(
'SPREADSHEET_EXCEL_READER_TYPE_MERGEDCELLS', 0xE5);
299 define(
'SPREADSHEET_EXCEL_READER_UTCOFFSETDAYS' , 25569);
300 define(
'SPREADSHEET_EXCEL_READER_UTCOFFSETDAYS1904', 24107);
301 define(
'SPREADSHEET_EXCEL_READER_MSINADAY', 86400);
302 define(
'SPREADSHEET_EXCEL_READER_TYPE_HYPER', 0x01b8);
303 define(
'SPREADSHEET_EXCEL_READER_TYPE_COLINFO', 0x7d);
304 define(
'SPREADSHEET_EXCEL_READER_TYPE_DEFCOLWIDTH', 0x55);
305 define(
'SPREADSHEET_EXCEL_READER_TYPE_STANDARDWIDTH', 0x99);
306 define(
'SPREADSHEET_EXCEL_READER_DEF_NUM_FORMAT',
"%s");
321 if (
$d < 16)
return "0" . dechex(
$d);
327 for ($i = 0; $i <= $length; $i++) {
328 $info .= ($i==0?
"":
" ") . $this->
myHex(ord(
$data[$pos + $i])) . (ord(
$data[$pos + $i])>31?
"[" .
$data[$pos + $i] .
"]":
'');
334 if (is_string($col)) {
335 $col = strtolower($col);
336 if (array_key_exists($col,$this->colnames)) {
337 $col = $this->colnames[$col];
347 $col = $this->
getCol($col);
348 if (array_key_exists(
$row,$this->sheets[$sheet][
'cells']) && array_key_exists($col,$this->sheets[$sheet][
'cells'][
$row])) {
349 return $this->sheets[$sheet][
'cells'][
$row][$col];
354 return $this->
val(
$row,$col,$sheet);
357 $col = $this->
getCol($col);
358 if (array_key_exists(
'cellsInfo',$this->sheets[$sheet])
359 && array_key_exists(
$row,$this->sheets[$sheet][
'cellsInfo'])
360 && array_key_exists($col,$this->sheets[$sheet][
'cellsInfo'][
$row])
361 && array_key_exists($type,$this->sheets[$sheet][
'cellsInfo'][$row][$col])) {
362 return $this->sheets[$sheet][
'cellsInfo'][
$row][$col][$type];
367 return $this->
info(
$row,$col,
'type',$sheet);
370 return $this->
info(
$row,$col,
'raw',$sheet);
373 $val = $this->
info(
$row,$col,
'rowspan',$sheet);
374 if ($val==
"") {
return 1; }
378 $val = $this->
info(
$row,$col,
'colspan',$sheet);
379 if ($val==
"") {
return 1; }
383 $link = $this->sheets[$sheet][
'cellsInfo'][
$row][$col][
'hyperlink'];
385 return $link[
'link'];
390 return $this->sheets[$sheet][
'numRows'];
393 return $this->sheets[$sheet][
'numCols'];
397 return $this->colInfo[$sheet][$col][
'width']/9142*200;
400 return !!$this->colInfo[$sheet][$col][
'hidden'];
403 return $this->rowInfo[$sheet][
$row][
'height'];
406 return !!$this->rowInfo[$sheet][
$row][
'hidden'];
413 $font=$this->
font(
$row,$col,$sheet);
415 $css .=
"font-family:$font;";
419 $css .=
"text-align:$align;";
423 $css .=
"font-size:$height".
"px;";
427 $bgcolor = $this->colors[$bgcolor];
428 $css .=
"background-color:$bgcolor;";
432 $css .=
"color:$color;";
434 $bold=$this->
bold(
$row,$col,$sheet);
436 $css .=
"font-weight:bold;";
440 $css .=
"font-style:italic;";
444 $css .=
"text-decoration:underline;";
456 if ($bLeft!=
"" && $bLeft==$bRight && $bRight==$bTop && $bTop==$bBottom) {
457 $css .=
"border:" . $this->lineStylesCss[$bLeft] .
";";
460 if ($bLeft!=
"") { $css .=
"border-left:" . $this->lineStylesCss[$bLeft] .
";"; }
461 if ($bRight!=
"") { $css .=
"border-right:" . $this->lineStylesCss[$bRight] .
";"; }
462 if ($bTop!=
"") { $css .=
"border-top:" . $this->lineStylesCss[$bTop] .
";"; }
463 if ($bBottom!=
"") { $css .=
"border-bottom:" . $this->lineStylesCss[$bBottom] .
";"; }
466 if ($bLeft!=
"" && $bLeftCol!=
"") { $css .=
"border-left-color:" . $bLeftCol .
";"; }
467 if ($bRight!=
"" && $bRightCol!=
"") { $css .=
"border-right-color:" . $bRightCol .
";"; }
468 if ($bTop!=
"" && $bTopCol!=
"") { $css .=
"border-top-color:" . $bTopCol .
";"; }
469 if ($bBottom!=
"" && $bBottomCol!=
"") { $css .=
"border-bottom-color:" . $bBottomCol .
";"; }
477 return $this->
info(
$row,$col,
'format',$sheet);
480 return $this->
info(
$row,$col,
'formatIndex',$sheet);
483 return $this->
info(
$row,$col,
'formatColor',$sheet);
489 $xfIndex = $this->
info(
$row,$col,
'xfIndex',$sheet);
491 return $this->xfRecords[$xfIndex];
497 if ($xfRecord!=null) {
498 return $xfRecord[$prop];
521 return $this->colors[$this->
xfProperty(
$row,$col,$sheet,
'borderLeftColor')];
524 return $this->colors[$this->
xfProperty(
$row,$col,$sheet,
'borderRightColor')];
527 return $this->colors[$this->
xfProperty(
$row,$col,$sheet,
'borderTopColor')];
530 return $this->colors[$this->
xfProperty(
$row,$col,$sheet,
'borderBottomColor')];
537 if ($xfRecord!=null) {
538 $font = $xfRecord[
'fontIndex'];
540 return $this->fontRecords[$font];
557 if ($formatColor!=
"") {
564 if (($ci <> 0x7FFF) && ($ci <>
'')) {
565 return $this->colors[$ci];
587 function dump($row_numbers=
false,$col_letters=
false,$sheet=0,$table_class=
'excel') {
588 $out =
"<table class=\"$table_class\" cellspacing=0>";
590 $out .=
"<thead>\n\t<tr>";
592 $out .=
"\n\t\t<th> </th>";
594 for($i=1;$i<=$this->
colcount($sheet);$i++) {
595 $style =
"width:" . ($this->
colwidth($i,$sheet)*1) .
"px;";
597 $style .=
"display:none;";
599 $out .=
"\n\t\t<th style=\"$style\">" . strtoupper($this->colindexes[$i]) .
"</th>";
601 $out .=
"</tr></thead>\n";
607 $style =
"height:" . ($rowheight*(4/3)) .
"px;";
609 $style .=
"display:none;";
611 $out .=
"\n\t<tr style=\"$style\">";
613 $out .=
"\n\t\t<th>$row</th>";
615 for($col=1;$col<=$this->
colcount($sheet);$col++) {
619 for($i=0;$i<$rowspan;$i++) {
620 for($j=0;$j<$colspan;$j++) {
622 $this->sheets[$sheet][
'cellsInfo'][
$row+$i][$col+$j][
'dontprint']=1;
626 if(!$this->sheets[$sheet][
'cellsInfo'][
$row][$col][
'dontprint']) {
629 $style .=
"display:none;";
631 $out .=
"\n\t\t<td style=\"$style\"" . ($colspan > 1?
" colspan=$colspan":
"") . ($rowspan > 1?
" rowspan=$rowspan":
"") .
">";
632 $val = $this->
val(
$row,$col,$sheet);
633 if ($val==
'') { $val=
" "; }
635 $val = htmlentities($val);
638 $val =
"<a href=\"$link\">$val</a>";
641 $out .=
"<nobr>".nl2br($val).
"</nobr>";
647 $out .=
"</tbody></table>";
699 0x5 =>
"\$#,##0;(\$#,##0)",
700 0x6 =>
"\$#,##0;[Red](\$#,##0)",
701 0x7 =>
"\$#,##0.00;(\$#,##0.00)",
702 0x8 =>
"\$#,##0.00;[Red](\$#,##0.00)",
706 0x25 =>
"#,##0;(#,##0)",
707 0x26 =>
"#,##0;[Red](#,##0)",
708 0x27 =>
"#,##0.00;(#,##0.00)",
709 0x28 =>
"#,##0.00;[Red](#,##0.00)",
710 0x29 =>
"#,##0;(#,##0)",
711 0x2a =>
"\$#,##0;(\$#,##0)",
712 0x2b =>
"#,##0.00;(#,##0.00)",
713 0x2c =>
"\$#,##0.00;(\$#,##0.00)",
804 0x08 =>
"Medium dashed",
805 0x09 =>
"Thin dash-dotted",
806 0x0A =>
"Medium dash-dotted",
807 0x0B =>
"Thin dash-dot-dotted",
808 0x0C =>
"Medium dash-dot-dotted",
809 0x0D =>
"Slanted medium dash-dotted"
813 "Thin" =>
"1px solid",
814 "Medium" =>
"2px solid",
815 "Dashed" =>
"1px dashed",
816 "Dotted" =>
"1px dotted",
817 "Thick" =>
"3px solid",
818 "Double" =>
"double",
819 "Hair" =>
"1px solid",
820 "Medium dashed" =>
"2px dashed",
821 "Thin dash-dotted" =>
"1px dashed",
822 "Medium dash-dotted" =>
"2px dashed",
823 "Thin dash-dot-dotted" =>
"1px dashed",
824 "Medium dash-dot-dotted" =>
"2px dashed",
825 "Slanted medium dash-dotte" =>
"2px dashed"
830 while (ord(
$data[$start + $len]) + ord(
$data[$start + $len + 1]) > 0) $len++;
831 return substr(
$data, $start, $len);
838 if ( (!$f && $format==
"%s") || ($f==49) || ($format==
"GENERAL") ) {
839 return array(
'string'=>$num,
'formatColor'=>null);
844 $parts = split(
";",$format);
845 $pattern = $parts[0];
847 if (count($parts)>2 && $num==0) {
848 $pattern = $parts[2];
851 if (count($parts)>1 && $num<0) {
852 $pattern = $parts[1];
858 $color_regex =
"/^\[(BLACK|BLUE|CYAN|GREEN|MAGENTA|RED|WHITE|YELLOW)\]/i";
859 if (preg_match($color_regex,$pattern,$matches)) {
860 $color = strtolower($matches[1]);
861 $pattern = preg_replace($color_regex,
"",$pattern);
865 $pattern = preg_replace(
"/_./",
"",$pattern);
868 $pattern = preg_replace(
"/\\\/",
"",$pattern);
871 $pattern = preg_replace(
"/\"/",
"",$pattern);
874 $pattern = preg_replace(
"/\#/",
"0",$pattern);
877 $has_commas = preg_match(
"/,/",$pattern);
879 $pattern = preg_replace(
"/,/",
"",$pattern);
883 if (preg_match(
"/\d(\%)([^\%]|$)/",$pattern,$matches)) {
885 $pattern = preg_replace(
"/(\d)(\%)([^\%]|$)/",
"$1%$3",$pattern);
889 $number_regex =
"/(\d+)(\.?)(\d*)/";
890 if (preg_match($number_regex,$pattern,$matches)) {
893 $right = $matches[3];
895 $formatted = number_format($num,strlen($right));
898 $sprintf_pattern =
"%1.".strlen($right).
"f";
899 $formatted = sprintf($sprintf_pattern, $num);
901 $pattern = preg_replace($number_regex, $formatted, $pattern);
906 'formatColor'=>$color
918 if ($outputEncoding !=
'') {
921 for ($i=1; $i<245; $i++) {
922 $name = strtolower(( (($i-1)/26>=1)?chr(($i-1)/26+64):
'') . chr(($i-1)%26+65));
923 $this->colnames[$name] = $i;
924 $this->colindexes[$i] = $name;
926 $this->store_extended_info = $store_extended_info;
936 $this->_defaultEncoding = $encoding;
945 $this->_encoderFunction =
'';
946 if ($encoder ==
'iconv') {
947 $this->_encoderFunction = function_exists(
'iconv') ?
'iconv' :
'';
948 } elseif ($encoder ==
'mb') {
949 $this->_encoderFunction = function_exists(
'mb_convert_encoding') ?
'mb_convert_encoding' :
'';
954 $this->_rowoffset = $iOffset;
955 $this->_coloffset = $iOffset;
962 $this->_defaultFormat = $sFormat;
969 $this->_columnsFormat[$column] = $sFormat;
976 $res = $this->_ole->read($sFileName);
981 if($this->_ole->error == 1) {
983 throw new Exception(
'The filename ' . $sFileName .
' is not readable');
987 $this->data = $this->_ole->getWorkBook();
1002 $length =
v(
$data,$pos+2);
1003 $version =
v(
$data,$pos+4);
1004 $substreamType =
v(
$data,$pos+6);
1006 $this->version = $version;
1017 $pos += $length + 4;
1020 $length =
v(
$data,$pos+2);
1026 $limitpos = $spos + $length;
1029 for ($i = 0; $i < $uniqueStrings; $i++) {
1031 if ($spos == $limitpos) {
1032 $opcode =
v(
$data,$spos);
1033 $conlength =
v(
$data,$spos+2);
1034 if ($opcode != 0x3c) {
1038 $limitpos = $spos + $conlength;
1040 $numChars = ord(
$data[$spos]) | (ord(
$data[$spos+1]) << 8);
1042 $optionFlags = ord(
$data[$spos]);
1044 $asciiEncoding = (($optionFlags & 0x01) == 0) ;
1045 $extendedString = ( ($optionFlags & 0x04) != 0);
1048 $richString = ( ($optionFlags & 0x08) != 0);
1052 $formattingRuns =
v(
$data,$spos);
1056 if ($extendedString) {
1062 $len = ($asciiEncoding)? $numChars : $numChars*2;
1063 if ($spos + $len < $limitpos) {
1064 $retstr = substr(
$data, $spos, $len);
1069 $retstr = substr(
$data, $spos, $limitpos - $spos);
1070 $bytesRead = $limitpos - $spos;
1071 $charsLeft = $numChars - (($asciiEncoding) ? $bytesRead : ($bytesRead / 2));
1074 while ($charsLeft > 0){
1075 $opcode =
v(
$data,$spos);
1076 $conlength =
v(
$data,$spos+2);
1077 if ($opcode != 0x3c) {
1081 $limitpos = $spos + $conlength;
1082 $option = ord(
$data[$spos]);
1084 if ($asciiEncoding && ($option == 0)) {
1085 $len = min($charsLeft, $limitpos - $spos);
1086 $retstr .= substr(
$data, $spos, $len);
1088 $asciiEncoding =
true;
1090 elseif (!$asciiEncoding && ($option != 0)) {
1091 $len = min($charsLeft * 2, $limitpos - $spos);
1092 $retstr .= substr(
$data, $spos, $len);
1093 $charsLeft -= $len/2;
1094 $asciiEncoding =
false;
1096 elseif (!$asciiEncoding && ($option == 0)) {
1099 $len = min($charsLeft, $limitpos - $spos);
1100 for ($j = 0; $j < $len; $j++) {
1101 $retstr .=
$data[$spos + $j].chr(0);
1104 $asciiEncoding =
false;
1108 for ($j = 0; $j < strlen($retstr); $j++) {
1109 $newstr = $retstr[$j].chr(0);
1112 $len = min($charsLeft * 2, $limitpos - $spos);
1113 $retstr .= substr(
$data, $spos, $len);
1114 $charsLeft -= $len/2;
1115 $asciiEncoding =
false;
1120 $retstr = ($asciiEncoding) ? $retstr : $this->
_encodeUTF16($retstr);
1123 $spos += 4 * $formattingRuns;
1127 if ($extendedString) {
1128 $spos += $extendedRunLength;
1130 $this->sst[]=$retstr;
1139 $indexCode =
v(
$data,$pos+4);
1141 $numchars =
v(
$data,$pos+6);
1142 if (ord(
$data[$pos+8]) == 0){
1143 $formatString = substr(
$data, $pos+9, $numchars);
1145 $formatString = substr(
$data, $pos+9, $numchars*2);
1148 $numchars = ord(
$data[$pos+6]);
1149 $formatString = substr(
$data, $pos+7, $numchars*2);
1151 $this->formatRecords[$indexCode] = $formatString;
1154 $height =
v(
$data,$pos+4);
1155 $option =
v(
$data,$pos+6);
1156 $color =
v(
$data,$pos+8);
1157 $weight =
v(
$data,$pos+10);
1158 $under = ord(
$data[$pos+14]);
1161 $numchars = ord(
$data[$pos+18]);
1162 if ((ord(
$data[$pos+19]) & 1) == 0){
1163 $font = substr(
$data, $pos+20, $numchars);
1165 $font = substr(
$data, $pos+20, $numchars*2);
1168 $this->fontRecords[] = array(
1169 'height' => $height / 20,
1170 'italic' => !!($option & 2),
1172 'under' => !($under==0),
1173 'bold' => ($weight==700),
1181 for ($coli = 0; $coli <
$colors; $coli++) {
1182 $colOff = $pos + 2 + ($coli * 4);
1183 $colr = ord(
$data[$colOff]);
1184 $colg = ord(
$data[$colOff+1]);
1185 $colb = ord(
$data[$colOff+2]);
1186 $this->colors[0x07 + $coli] =
'#' . $this->myhex($colr) . $this->myhex($colg) . $this->myhex($colb);
1191 $fontIndexCode = (ord(
$data[$pos+4]) | ord(
$data[$pos+5]) << 8) - 1;
1192 $fontIndexCode = max(0,$fontIndexCode);
1193 $indexCode = ord(
$data[$pos+6]) | ord(
$data[$pos+7]) << 8;
1194 $alignbit = ord(
$data[$pos+10]) & 3;
1195 $bgi = (ord(
$data[$pos+22]) | ord(
$data[$pos+23]) << 8) & 0x3FFF;
1196 $bgcolor = ($bgi & 0x7F);
1199 if ($alignbit==3) { $align=
"right"; }
1200 if ($alignbit==2) { $align=
"center"; }
1202 $fillPattern = (ord(
$data[$pos+21]) & 0xFC) >> 2;
1203 if ($fillPattern == 0) {
1208 $xf[
'formatIndex'] = $indexCode;
1209 $xf[
'align'] = $align;
1210 $xf[
'fontIndex'] = $fontIndexCode;
1211 $xf[
'bgColor'] = $bgcolor;
1212 $xf[
'fillPattern'] = $fillPattern;
1214 $border = ord(
$data[$pos+14]) | (ord(
$data[$pos+15]) << 8) | (ord(
$data[$pos+16]) << 16) | (ord(
$data[$pos+17]) << 24);
1215 $xf[
'borderLeft'] = $this->lineStyles[($border & 0xF)];
1216 $xf[
'borderRight'] = $this->lineStyles[($border & 0xF0) >> 4];
1217 $xf[
'borderTop'] = $this->lineStyles[($border & 0xF00) >> 8];
1218 $xf[
'borderBottom'] = $this->lineStyles[($border & 0xF000) >> 12];
1220 $xf[
'borderLeftColor'] = ($border & 0x7F0000) >> 16;
1221 $xf[
'borderRightColor'] = ($border & 0x3F800000) >> 23;
1222 $border = (ord(
$data[$pos+18]) | ord(
$data[$pos+19]) << 8);
1224 $xf[
'borderTopColor'] = ($border & 0x7F);
1225 $xf[
'borderBottomColor'] = ($border & 0x3F80) >> 7;
1227 if (array_key_exists($indexCode, $this->dateFormats)) {
1228 $xf[
'type'] =
'date';
1229 $xf[
'format'] = $this->dateFormats[$indexCode];
1230 if ($align==
'') { $xf[
'align'] =
'right'; }
1231 }elseif (array_key_exists($indexCode, $this->numberFormats)) {
1232 $xf[
'type'] =
'number';
1233 $xf[
'format'] = $this->numberFormats[$indexCode];
1234 if ($align==
'') { $xf[
'align'] =
'right'; }
1238 if ($indexCode > 0){
1239 if (isset($this->formatRecords[$indexCode]))
1240 $formatstr = $this->formatRecords[$indexCode];
1241 if ($formatstr!=
"") {
1242 $tmp = preg_replace(
"/\;.*/",
"",$formatstr);
1243 $tmp = preg_replace(
"/^\[[^\]]*\]/",
"",$tmp);
1244 if (preg_match(
"/[^hmsday\/\-:\s\\\,AMP]/i", $tmp) == 0) {
1247 $formatstr = str_replace(array(
'AM/PM',
'mmmm',
'mmm'), array(
'a',
'F',
'M'), $formatstr);
1251 $formatstr = preg_replace(
"/(h:?)mm?/",
"$1i", $formatstr);
1252 $formatstr = preg_replace(
"/mm?(:?s)/",
"i$1", $formatstr);
1254 $formatstr = preg_replace(
"/(^|[^m])m([^m]|$)/",
'$1n$2', $formatstr);
1255 $formatstr = preg_replace(
"/(^|[^m])m([^m]|$)/",
'$1n$2', $formatstr);
1257 $formatstr = str_replace(
'mm',
'm', $formatstr);
1259 $formatstr = preg_replace(
"/(^|[^d])d([^d]|$)/",
'$1j$2', $formatstr);
1260 $formatstr = str_replace(array(
'dddd',
'ddd',
'dd',
'yyyy',
'yy',
'hh',
'h'), array(
'l',
'D',
'd',
'Y',
'y',
'H',
'g'), $formatstr);
1261 $formatstr = preg_replace(
"/ss?/",
's', $formatstr);
1266 $xf[
'type'] =
'date';
1267 $xf[
'format'] = $formatstr;
1268 if ($align==
'') { $xf[
'align'] =
'right'; }
1271 if (preg_match(
"/[0#]/", $formatstr)) {
1272 $xf[
'type'] =
'number';
1273 if ($align==
'') { $xf[
'align']=
'right'; }
1276 $xf[
'type'] =
'other';
1278 $xf[
'format'] = $formatstr;
1279 $xf[
'code'] = $indexCode;
1282 $this->xfRecords[] = $xf;
1285 $this->nineteenFour = (ord(
$data[$pos+4]) == 1);
1289 $rec_typeFlag = ord(
$data[$pos+8]);
1290 $rec_visibilityFlag = ord(
$data[$pos+9]);
1291 $rec_length = ord(
$data[$pos+10]);
1294 $chartype = ord(
$data[$pos+11]);
1295 if ($chartype == 0){
1296 $rec_name = substr(
$data, $pos+12, $rec_length);
1301 $rec_name = substr(
$data, $pos+11, $rec_length);
1303 $this->boundsheets[] = array(
'name'=>$rec_name,
'offset'=>$rec_offset);
1308 $pos += $length + 4;
1309 $code = ord(
$data[$pos]) | ord(
$data[$pos+1])<<8;
1310 $length = ord(
$data[$pos+2]) | ord(
$data[$pos+3])<<8;
1313 foreach ($this->boundsheets as $key=>$val){
1327 $code = ord(
$data[$spos]) | ord(
$data[$spos+1])<<8;
1328 $length = ord(
$data[$spos+2]) | ord(
$data[$spos+3])<<8;
1330 $version = ord(
$data[$spos + 4]) | ord(
$data[$spos + 5])<<8;
1331 $substreamType = ord(
$data[$spos + 6]) | ord(
$data[$spos + 7])<<8;
1340 $spos += $length + 4;
1342 $lowcode = ord(
$data[$spos]);
1344 $code = $lowcode | ord(
$data[$spos+1])<<8;
1345 $length = ord(
$data[$spos+2]) | ord(
$data[$spos+3])<<8;
1347 $this->sheets[$this->sn][
'maxrow'] = $this->_rowoffset - 1;
1348 $this->sheets[$this->sn][
'maxcol'] = $this->_coloffset - 1;
1349 unset($this->rectype);
1352 if (!isset($this->numRows)) {
1354 $this->sheets[$this->sn][
'numRows'] = ord(
$data[$spos+2]) | ord(
$data[$spos+3]) << 8;
1355 $this->sheets[$this->sn][
'numCols'] = ord(
$data[$spos+6]) | ord(
$data[$spos+7]) << 8;
1357 $this->sheets[$this->sn][
'numRows'] = ord(
$data[$spos+4]) | ord(
$data[$spos+5]) << 8;
1358 $this->sheets[$this->sn][
'numCols'] = ord(
$data[$spos+10]) | ord(
$data[$spos+11]) << 8;
1363 $cellRanges = ord(
$data[$spos]) | ord(
$data[$spos+1])<<8;
1364 for ($i = 0; $i < $cellRanges; $i++) {
1365 $fr = ord(
$data[$spos + 8*$i + 2]) | ord(
$data[$spos + 8*$i + 3])<<8;
1366 $lr = ord(
$data[$spos + 8*$i + 4]) | ord(
$data[$spos + 8*$i + 5])<<8;
1367 $fc = ord(
$data[$spos + 8*$i + 6]) | ord(
$data[$spos + 8*$i + 7])<<8;
1368 $lc = ord(
$data[$spos + 8*$i + 8]) | ord(
$data[$spos + 8*$i + 9])<<8;
1369 if ($lr - $fr > 0) {
1370 $this->sheets[$this->sn][
'cellsInfo'][$fr+1][$fc+1][
'rowspan'] = $lr - $fr + 1;
1372 if ($lc - $fc > 0) {
1373 $this->sheets[$this->sn][
'cellsInfo'][$fr+1][$fc+1][
'colspan'] = $lc - $fc + 1;
1380 $column = ord(
$data[$spos+2]) | ord(
$data[$spos+3])<<8;
1384 $this->
addcell(
$row, $column, $info[
'string'],$info);
1388 $column = ord(
$data[$spos+2]) | ord(
$data[$spos+3])<<8;
1389 $xfindex = ord(
$data[$spos+4]) | ord(
$data[$spos+5])<<8;
1391 $this->
addcell(
$row, $column, $this->sst[$index], array(
'xfIndex'=>$xfindex) );
1395 $colFirst = ord(
$data[$spos+2]) | ord(
$data[$spos+3])<<8;
1396 $colLast = ord(
$data[$spos + $length - 2]) | ord(
$data[$spos + $length - 1])<<8;
1397 $columns = $colLast - $colFirst + 1;
1399 for ($i = 0; $i <
$columns; $i++) {
1401 $info = $this->
_getCellDetails($tmppos-4,$numValue,$colFirst + $i + 1);
1403 $this->
addcell(
$row, $colFirst + $i, $info[
'string'], $info);
1408 $column = ord(
$data[$spos+2]) | ord(
$data[$spos+3])<<8;
1409 $tmp = unpack(
"ddouble", substr(
$data, $spos + 6, 8));
1410 if ($this->
isDate($spos)) {
1411 $numValue = $tmp[
'double'];
1417 $this->
addcell(
$row, $column, $info[
'string'], $info);
1423 $column = ord(
$data[$spos+2]) | ord(
$data[$spos+3])<<8;
1424 if ((ord(
$data[$spos+6])==0) && (ord(
$data[$spos+12])==255) && (ord(
$data[$spos+13])==255)) {
1428 $previousRow =
$row;
1429 $previousCol = $column;
1430 } elseif ((ord(
$data[$spos+6])==1) && (ord(
$data[$spos+12])==255) && (ord(
$data[$spos+13])==255)) {
1433 if (ord($this->data[$spos+8])==1) {
1438 } elseif ((ord(
$data[$spos+6])==2) && (ord(
$data[$spos+12])==255) && (ord(
$data[$spos+13])==255)) {
1440 } elseif ((ord(
$data[$spos+6])==3) && (ord(
$data[$spos+12])==255) && (ord(
$data[$spos+13])==255)) {
1445 $tmp = unpack(
"ddouble", substr(
$data, $spos + 6, 8));
1446 if ($this->
isDate($spos)) {
1447 $numValue = $tmp[
'double'];
1453 $this->
addcell(
$row, $column, $info[
'string'], $info);
1458 $column = ord(
$data[$spos+2]) | ord(
$data[$spos+3])<<8;
1459 $string = ord(
$data[$spos+6]);
1467 $numChars =ord(
$data[$xpos]) | (ord(
$data[$xpos+1]) << 8);
1469 $optionFlags =ord(
$data[$xpos]);
1471 $asciiEncoding = (($optionFlags &0x01) == 0) ;
1472 $extendedString = (($optionFlags & 0x04) != 0);
1474 $richString = (($optionFlags & 0x08) != 0);
1477 $formattingRuns =ord(
$data[$xpos]) | (ord(
$data[$xpos+1]) << 8);
1480 if ($extendedString) {
1482 $extendedRunLength =$this->
_GetInt4d($this->data, $xpos);
1485 $len = ($asciiEncoding)?$numChars : $numChars*2;
1486 $retstr =substr(
$data, $xpos, $len);
1488 $retstr = ($asciiEncoding)? $retstr : $this->
_encodeUTF16($retstr);
1493 $numChars =ord(
$data[$xpos]) | (ord(
$data[$xpos+1]) << 8);
1495 $retstr =substr(
$data, $xpos, $numChars);
1497 $this->
addcell($previousRow, $previousCol, $retstr);
1507 $rowHidden = (ord(
$data[$spos + 12]) & 0x20) >> 5;
1508 $this->rowInfo[$this->sn][
$row+1] = Array(
'height' => $rowHeight / 20,
'hidden'=>$rowHidden );
1514 $column = ord(
$data[$spos+2]) | ord(
$data[$spos+3])<<8;
1515 $cols = ($length / 2) - 3;
1516 for ($c = 0; $c < $cols; $c++) {
1517 $xfindex = ord(
$data[$spos + 4 + ($c * 2)]) | ord(
$data[$spos + 5 + ($c * 2)])<<8;
1518 $this->
addcell(
$row, $column + $c,
"", array(
'xfIndex'=>$xfindex));
1523 $column = ord(
$data[$spos+2]) | ord(
$data[$spos+3])<<8;
1531 $row = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8;
1532 $row2 = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8;
1533 $column = ord($this->data[$spos+4]) | ord($this->data[$spos+5])<<8;
1534 $column2 = ord($this->data[$spos+6]) | ord($this->data[$spos+7])<<8;
1535 $linkdata = Array();
1536 $flags = ord($this->data[$spos + 28]);
1540 $linkdata[
'flags'] = $flags;
1541 if (($flags & 1) > 0 ) {
1543 if (($flags & 0x14) == 0x14 ) {
1545 $descLen = ord($this->data[$spos + 32]) | ord($this->data[$spos + 33]) << 8;
1546 $udesc = substr($this->data, $spos + $uloc, $descLen * 2);
1547 $uloc += 2 * $descLen;
1554 $linkdata[
'desc'] = $udesc;
1556 for ($r=
$row; $r<=$row2; $r++) {
1557 for ($c=$column; $c<=$column2; $c++) {
1558 $this->sheets[$this->sn][
'cellsInfo'][$r+1][$c+1][
'hyperlink'] = $linkdata;
1563 $this->defaultColWidth = ord(
$data[$spos+4]) | ord(
$data[$spos+5]) << 8;
1566 $this->standardColWidth = ord(
$data[$spos+4]) | ord(
$data[$spos+5]) << 8;
1569 $colfrom = ord(
$data[$spos+0]) | ord(
$data[$spos+1]) << 8;
1570 $colto = ord(
$data[$spos+2]) | ord(
$data[$spos+3]) << 8;
1571 $cw = ord(
$data[$spos+4]) | ord(
$data[$spos+5]) << 8;
1572 $cxf = ord(
$data[$spos+6]) | ord(
$data[$spos+7]) << 8;
1573 $co = ord(
$data[$spos+8]);
1574 for ($coli = $colfrom; $coli <= $colto; $coli++) {
1575 $this->colInfo[$this->sn][$coli+1] = Array(
'width' => $cw,
'xf' => $cxf,
'hidden' => ($co & 0x01),
'collapsed' => ($co & 0x1000) >> 12);
1585 if (!isset($this->sheets[$this->sn][
'numRows']))
1586 $this->sheets[$this->sn][
'numRows'] = $this->sheets[$this->sn][
'maxrow'];
1587 if (!isset($this->sheets[$this->sn][
'numCols']))
1588 $this->sheets[$this->sn][
'numCols'] = $this->sheets[$this->sn][
'maxcol'];
1592 $xfindex = ord($this->data[$spos+4]) | ord($this->data[$spos+5]) << 8;
1593 return ($this->xfRecords[$xfindex][
'type'] ==
'date');
1598 $xfindex = ord($this->data[$spos+4]) | ord($this->data[$spos+5]) << 8;
1599 $xfrecord = $this->xfRecords[$xfindex];
1600 $type = $xfrecord[
'type'];
1602 $format = $xfrecord[
'format'];
1603 $formatIndex = $xfrecord[
'formatIndex'];
1604 $fontIndex = $xfrecord[
'fontIndex'];
1610 if (isset($this->_columnsFormat[$column + 1])){
1611 $format = $this->_columnsFormat[$column + 1];
1614 if ($type ==
'date') {
1623 $fractionalDay = $numValue - floor($numValue) + .0000001;
1626 $secs = $totalseconds % 60;
1627 $totalseconds -= $secs;
1628 $hours = floor($totalseconds / (60 * 60));
1629 $mins = floor($totalseconds / 60) % 60;
1630 $string = date ($format, mktime($hours, $mins, $secs, $dateinfo[
"mon"], $dateinfo[
"mday"], $dateinfo[
"year"]));
1631 }
else if ($type ==
'number') {
1632 $rectype =
'number';
1633 $formatted = $this->
_format_value($format, $numValue, $formatIndex);
1634 $string = $formatted[
'string'];
1635 $formatColor = $formatted[
'formatColor'];
1641 $rectype =
'unknown';
1642 $formatted = $this->
_format_value($format, $numValue, $formatIndex);
1643 $string = $formatted[
'string'];
1644 $formatColor = $formatted[
'formatColor'];
1651 'rectype'=>$rectype,
1653 'formatIndex'=>$formatIndex,
1654 'fontIndex'=>$fontIndex,
1655 'formatColor'=>$formatColor,
1663 $rknumhigh = $this->
_GetInt4d($this->data, $spos + 10);
1664 $rknumlow = $this->
_GetInt4d($this->data, $spos + 6);
1665 $sign = ($rknumhigh & 0x80000000) >> 31;
1666 $exp = ($rknumhigh & 0x7ff00000) >> 20;
1667 $mantissa = (0x100000 | ($rknumhigh & 0x000fffff));
1668 $mantissalow1 = ($rknumlow & 0x80000000) >> 31;
1669 $mantissalow2 = ($rknumlow & 0x7fffffff);
1670 $value = $mantissa / pow( 2 , (20- ($exp - 1023)));
1671 if ($mantissalow1 != 0) $value += 1 / pow (2 , (21 - ($exp - 1023)));
1672 $value += $mantissalow2 / pow (2 , (52 - ($exp - 1023)));
1673 if ($sign) {$value = -1 * $value;}
1678 $this->sheets[$this->sn][
'maxrow'] = max($this->sheets[$this->sn][
'maxrow'],
$row + $this->_rowoffset);
1679 $this->sheets[$this->sn][
'maxcol'] = max($this->sheets[$this->sn][
'maxcol'], $col + $this->_coloffset);
1681 if ($this->store_extended_info && $info) {
1682 foreach ($info as $key=>$val) {
1690 if (($rknum & 0x02) != 0) {
1691 $value = $rknum >> 2;
1699 $sign = ($rknum & 0x80000000) >> 31;
1700 $exp = ($rknum & 0x7ff00000) >> 20;
1701 $mantissa = (0x100000 | ($rknum & 0x000ffffc));
1702 $value = $mantissa / pow( 2 , (20- ($exp - 1023)));
1704 $value = -1 * $value;
1708 if (($rknum & 0x01) != 0) {
1716 if ($this->_defaultEncoding){
1717 switch ($this->_encoderFunction){
1718 case 'iconv' :
$result = iconv(
'UTF-16LE', $this->_defaultEncoding, $string);
1720 case 'mb_convert_encoding' :
$result = mb_convert_encoding($string, $this->_defaultEncoding,
'UTF-16LE' );
1728 $value = ord(
$data[$pos]) | (ord(
$data[$pos+1]) << 8) | (ord(
$data[$pos+2]) << 16) | (ord(
$data[$pos+3]) << 24);
1729 if ($value>=4294967294) {