Helix Installation   Getting Started   Reference Documentation   Global Functions   Quick Start
ModulesClassesFunctions
 

Class Reference

class excel_reader

Hide Inherited MembersHelix Core
Description
No description.
 
Constants
No constants.
 
Properties
publicboundsheets[ excel_reader ]
public_coloffset[ excel_reader ]
public_columnsFormat[ excel_reader ]
publicdata[ excel_reader ]
publicdateFormats[ excel_reader ]
public_defaultEncoding[ excel_reader ]
public_defaultFormat[ excel_reader ]
publicformatRecords[ excel_reader ]
publicnumberFormats[ excel_reader ]
public_ole[ excel_reader ]
public_rowoffset[ excel_reader ]
publicsheets[ excel_reader ]
publicsst[ excel_reader ]
 
Methods
public_GetIEEE754 ( rknum )[ excel_reader ]
Parameters
requiredrknum
Code
1012      function _GetIEEE754($rknum)
1013      {
1014          if (($rknum & 0x02) != 0) {
1015                  $value = $rknum >> 2;
1016          } else {
1017  //mmp
1018  // first comment out the previously existing 7 lines of code here
1019  //                $tmp = unpack("d", pack("VV", 0, ($rknum & 0xfffffffc)));
1020  //                //$value = $tmp[''];
1021  //                if (array_key_exists(1, $tmp)) {
1022  //                    $value = $tmp[1];
1023  //                } else {
1024  //                    $value = $tmp[''];
1025  //                }
1026  // I got my info on IEEE754 encoding from
1027  // http://research.microsoft.com/~hollasch/cgindex/coding/ieeefloat.html
1028  // The RK format calls for using only the most significant 30 bits of the
1029  // 64 bit floating point value. The other 34 bits are assumed to be 0
1030  // So, we use the upper 30 bits of $rknum as follows...
1031           $sign = ($rknum & 0x80000000) >> 31;
1032          $exp = ($rknum & 0x7ff00000) >> 20;
1033          $mantissa = (0x100000 | ($rknum & 0x000ffffc));
1034          $value = $mantissa / pow( 2 , (20- ($exp - 1023)));
1035          if ($sign) {$value = -1 * $value;}
1036  //end of changes by mmp
1037 
1038          }
1039 
1040          if (($rknum & 0x01) != 0) {
1041              $value /= 100;
1042          }
1043          return $value;
1044      }
public_GetInt4d ( data , pos )[ excel_reader ]
Parameters
requireddata
requiredpos
Code
1060      function _GetInt4d($data, $pos)
1061      {
1062          $value = ord($data[$pos]) | (ord($data[$pos+1]) << 8) | (ord($data[$pos+2]) << 16) | (ord($data[$pos+3]) << 24);
1063          if ($value>=4294967294)
1064          {
1065              $value=-2;
1066          }
1067          return $value;
1068      }
publicaddcell ( row , col , string , raw [""] )[ excel_reader ]
Parameters
requiredrow
requiredcol
requiredstring
optionalraw [""]
Code
998      function addcell($row, $col, $string, $raw = '')
999      {
1000          //echo "ADD cel $row-$col $string\n";
1001          $this->sheets[$this->sn]['maxrow'] = max($this->sheets[$this->sn]['maxrow'], $row + $this->_rowoffset);
1002          $this->sheets[$this->sn]['maxcol'] = max($this->sheets[$this->sn]['maxcol'], $col + $this->_coloffset);
1003          $this->sheets[$this->sn]['cells'][$row + $this->_rowoffset][$col + $this->_coloffset] = $string;
1004          if ($raw)
1005              $this->sheets[$this->sn]['cellsInfo'][$row + $this->_rowoffset][$col + $this->_coloffset]['raw'] = $raw;
1006          if (isset($this->rectype))
1007              $this->sheets[$this->sn]['cellsInfo'][$row + $this->_rowoffset][$col + $this->_coloffset]['type'] = $this->rectype;
1008 
1009      }
publiccreateDate ( numValue )[ excel_reader ]
Parameters
requirednumValue
Code
962      function createDate($numValue)
963      {
964          if ($numValue > 1) {
965              $utcDays = $numValue - ($this->nineteenFour ? SPREADSHEET_EXCEL_READER_UTCOFFSETDAYS1904 : SPREADSHEET_EXCEL_READER_UTCOFFSETDAYS);
966              $utcValue = round(($utcDays+1) * SPREADSHEET_EXCEL_READER_MSINADAY);
967              $string = date ($this->curformat, $utcValue);
968              $raw = $utcValue;
969          } else {
970              $raw = $numValue;
971              $hours = floor($numValue * 24);
972              $mins = floor($numValue * 24 * 60) - $hours * 60;
973              $secs = floor($numValue * SPREADSHEET_EXCEL_READER_MSINADAY) - $hours * 60 * 60 - $mins * 60;
974              $string = date ($this->curformat, mktime($hours, $mins, $secs));
975          }
976 
977          return array($string, $raw);
978      }
publiccreateNumber ( spos )[ excel_reader ]
Parameters
requiredspos
Code
980      function createNumber($spos)
981      {
982          $rknumhigh = $this->_GetInt4d($this->data, $spos + 10);
983          $rknumlow = $this->_GetInt4d($this->data, $spos + 6);
984          //for ($i=0; $i<8; $i++) { echo ord($this->data[$i+$spos+6]) . " "; } echo "<br>";
985          $sign = ($rknumhigh & 0x80000000) >> 31;
986          $exp =  ($rknumhigh & 0x7ff00000) >> 20;
987          $mantissa = (0x100000 | ($rknumhigh & 0x000fffff));
988          $mantissalow1 = ($rknumlow & 0x80000000) >> 31;
989          $mantissalow2 = ($rknumlow & 0x7fffffff);
990          $value = $mantissa / pow( 2 , (20- ($exp - 1023)));
991          if ($mantissalow1 != 0) $value += 1 / pow (2 , (21 - ($exp - 1023)));
992          $value += $mantissalow2 / pow (2 , (52 - ($exp - 1023)));
993          //echo "Sign = $sign, Exp = $exp, mantissahighx = $mantissa, mantissalow1 = $mantissalow1, mantissalow2 = $mantissalow2<br>\n";
994          if ($sign) {$value = -1 * $value;}
995          return  $value;
996      }
public_encodeUTF16 ( string )[ excel_reader ]
Parameters
requiredstring
Code
1046      function _encodeUTF16($string)
1047      {
1048          $result = $string;
1049          if ($this->_defaultEncoding){
1050              switch ($this->_encoderFunction){
1051                  case 'iconv' :     $result = iconv('UTF-16LE', $this->_defaultEncoding, $string);
1052                                  break;
1053                  case 'mb_convert_encoding' :     $result = mb_convert_encoding($string, $this->_defaultEncoding, 'UTF-16LE' );
1054                                  break;
1055              }
1056          }
1057          return $result;
1058      }
publicexcel_reader ( )[ excel_reader ]
Parameters
No parameters for this method
Code
255      function excel_reader()
256      {
257          $this->_ole = new oleread();
258          $this->setUTFEncoder('iconv');
259      }
publicisDate ( spos )[ excel_reader ]
Parameters
requiredspos
Code
924      function isDate($spos)
925      {
926          //$xfindex = GetInt2d(, 4);
927          $xfindex = ord($this->data[$spos+4]) | ord($this->data[$spos+5]) << 8;
928          //echo 'check is date '.$xfindex.' '.$this->formatRecords['xfrecords'][$xfindex]['type']."\n";
929          //var_dump($this->formatRecords['xfrecords'][$xfindex]);
930          if ($this->formatRecords['xfrecords'][$xfindex]['type'] == 'date') {
931              $this->curformat = $this->formatRecords['xfrecords'][$xfindex]['format'];
932              $this->rectype = 'date';
933              return true;
934          } else {
935              if ($this->formatRecords['xfrecords'][$xfindex]['type'] == 'number') {
936                  $this->curformat = $this->formatRecords['xfrecords'][$xfindex]['format'];
937                  $this->rectype = 'number';
938                  if (($xfindex == 0x9) || ($xfindex == 0xa)){
939                      $this->multiplier = 100;
940                  }
941              }else{
942                  $this->curformat = $this->_defaultFormat;
943                  $this->rectype = 'unknown';
944              }
945              return false;
946          }
947      }
public_parse ( )[ excel_reader ]
Parameters
No parameters for this method
Code
433      function _parse()
434      {
435          $pos = 0;
436 
437          $code = ord($this->data[$pos]) | ord($this->data[$pos+1])<<8;
438          $length = ord($this->data[$pos+2]) | ord($this->data[$pos+3])<<8;
439 
440          $version = ord($this->data[$pos + 4]) | ord($this->data[$pos + 5])<<8;
441          $substreamType = ord($this->data[$pos + 6]) | ord($this->data[$pos + 7])<<8;
442          //echo "Start parse code=".base_convert($code,10,16)." version=".base_convert($version,10,16)." substreamType=".base_convert($substreamType,10,16).""."\n";
443 
444          if (($version != SPREADSHEET_EXCEL_READER_BIFF8) &&
445              ($version != SPREADSHEET_EXCEL_READER_BIFF7)) {
446              return false;
447          }
448 
449          if ($substreamType != SPREADSHEET_EXCEL_READER_WORKBOOKGLOBALS){
450              return false;
451          }
452 
453          //print_r($rec);
454          $pos += $length + 4;
455 
456          $code = ord($this->data[$pos]) | ord($this->data[$pos+1])<<8;
457          $length = ord($this->data[$pos+2]) | ord($this->data[$pos+3])<<8;
458 
459          while ($code != SPREADSHEET_EXCEL_READER_TYPE_EOF) {
460              switch ($code) {
461                  case SPREADSHEET_EXCEL_READER_TYPE_SST:
462                      //echo "Type_SST\n";
463                       $spos = $pos + 4;
464                       $limitpos = $spos + $length;
465                       $uniqueStrings = $this->_GetInt4d($this->data, $spos+4);
466                                                  $spos += 8;
467                                         for ($i = 0; $i < $uniqueStrings; $i++) {
468          // Read in the number of characters
469                                                  if ($spos == $limitpos) {
470                                                  $opcode = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8;
471                                                  $conlength = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8;
472                                                          if ($opcode != 0x3c) {
473                                                                  return -1;
474                                                          }
475                                                  $spos += 4;
476                                                  $limitpos = $spos + $conlength;
477                                                  }
478                                                  $numChars = ord($this->data[$spos]) | (ord($this->data[$spos+1]) << 8);
479                                                  //echo "i = $i pos = $pos numChars = $numChars ";
480                                                  $spos += 2;
481                                                  $optionFlags = ord($this->data[$spos]);
482                                                  $spos++;
483                                          $asciiEncoding = (($optionFlags & 0x01) == 0) ;
484                                                  $extendedString = ( ($optionFlags & 0x04) != 0);
485 
486                                                  // See if string contains formatting information
487                                                  $richString = ( ($optionFlags & 0x08) != 0);
488 
489                                                  if ($richString) {
490                                          // Read in the crun
491                                                          $formattingRuns = ord($this->data[$spos]) | (ord($this->data[$spos+1]) << 8);
492                                                          $spos += 2;
493                                                  }
494 
495                                                  if ($extendedString) {
496                                                    // Read in cchExtRst
497                                                    $extendedRunLength = $this->_GetInt4d($this->data, $spos);
498                                                    $spos += 4;
499                                                  }
500 
501                                                  $len = ($asciiEncoding)? $numChars : $numChars*2;
502                                                  if ($spos + $len < $limitpos) {
503                                                                  $retstr = substr($this->data, $spos, $len);
504                                                                  $spos += $len;
505                                                  }else{
506                                                          // found countinue
507                                                          $retstr = substr($this->data, $spos, $limitpos - $spos);
508                                                          $bytesRead = $limitpos - $spos;
509                                                          $charsLeft = $numChars - (($asciiEncoding) ? $bytesRead : ($bytesRead / 2));
510                                                          $spos = $limitpos;
511 
512                                                           while ($charsLeft > 0){
513                                                                  $opcode = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8;
514                                                                  $conlength = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8;
515                                                                          if ($opcode != 0x3c) {
516                                                                                  return -1;
517                                                                          }
518                                                                  $spos += 4;
519                                                                  $limitpos = $spos + $conlength;
520                                                                  $option = ord($this->data[$spos]);
521                                                                  $spos += 1;
522                                                                    if ($asciiEncoding && ($option == 0)) {
523                                                                                  $len = min($charsLeft, $limitpos - $spos); // min($charsLeft, $conlength);
524                                                                      $retstr .= substr($this->data, $spos, $len);
525                                                                      $charsLeft -= $len;
526                                                                      $asciiEncoding = true;
527                                                                    }elseif (!$asciiEncoding && ($option != 0)){
528                                                                                  $len = min($charsLeft * 2, $limitpos - $spos); // min($charsLeft, $conlength);
529                                                                      $retstr .= substr($this->data, $spos, $len);
530                                                                      $charsLeft -= $len/2;
531                                                                      $asciiEncoding = false;
532                                                                    }elseif (!$asciiEncoding && ($option == 0)) {
533                                                                  // Bummer - the string starts off as Unicode, but after the
534                                                                  // continuation it is in straightforward ASCII encoding
535                                                                                  $len = min($charsLeft, $limitpos - $spos); // min($charsLeft, $conlength);
536                                                                          for ($j = 0; $j < $len; $j++) {
537                                                                   $retstr .= $this->data[$spos + $j].chr(0);
538                                                                  }
539                                                              $charsLeft -= $len;
540                                                                  $asciiEncoding = false;
541                                                                    }else{
542                                                              $newstr = '';
543                                                                      for ($j = 0; $j < strlen($retstr); $j++) {
544                                                                        $newstr = $retstr[$j].chr(0);
545                                                                      }
546                                                                      $retstr = $newstr;
547                                                                                  $len = min($charsLeft * 2, $limitpos - $spos); // min($charsLeft, $conlength);
548                                                                      $retstr .= substr($this->data, $spos, $len);
549                                                                      $charsLeft -= $len/2;
550                                                                      $asciiEncoding = false;
551                                                                          //echo "Izavrat\n";
552                                                                    }
553                                                            $spos += $len;
554 
555                                                           }
556                                                  }
557                                                  $retstr = ($asciiEncoding) ? $retstr : $this->_encodeUTF16($retstr);
558  //                                              echo "Str $i = $retstr\n";
559                                          if ($richString){
560                                                    $spos += 4 * $formattingRuns;
561                                                  }
562 
563                                                  // For extended strings, skip over the extended string data
564                                                  if ($extendedString) {
565                                                    $spos += $extendedRunLength;
566                                                  }
567                                                          //if ($retstr == 'Derby'){
568                                                          //      echo "bb\n";
569                                                          //}
570                                                  $this->sst[]=$retstr;
571                                         }
572                      /*$continueRecords = array();
573                      while ($this->getNextCode() == Type_CONTINUE) {
574                          $continueRecords[] = &$this->nextRecord();
575                      }
576                      //echo " 1 Type_SST\n";
577                      $this->shareStrings = new SSTRecord($r, $continueRecords);
578                      //print_r($this->shareStrings->strings);
579                       */
580                       // echo 'SST read: '.($time_end-$time_start)."\n";
581                      break;
582 
583                  case SPREADSHEET_EXCEL_READER_TYPE_FILEPASS:
584                      return false;
585                      break;
586                  case SPREADSHEET_EXCEL_READER_TYPE_NAME:
587                      //echo "Type_NAME\n";
588                      break;
589                  case SPREADSHEET_EXCEL_READER_TYPE_FORMAT:
590                          $indexCode = ord($this->data[$pos+4]) | ord($this->data[$pos+5]) << 8;
591 
592                          if ($version == SPREADSHEET_EXCEL_READER_BIFF8) {
593                              $numchars = ord($this->data[$pos+6]) | ord($this->data[$pos+7]) << 8;
594                              if (ord($this->data[$pos+8]) == 0){
595                                  $formatString = substr($this->data, $pos+9, $numchars);
596                              } else {
597                                  $formatString = substr($this->data, $pos+9, $numchars*2);
598                              }
599                          } else {
600                              $numchars = ord($this->data[$pos+6]);
601                              $formatString = substr($this->data, $pos+7, $numchars*2);
602                          }
603 
604                      $this->formatRecords[$indexCode] = $formatString;
605                     // echo "Type.FORMAT\n";
606                      break;
607                  case SPREADSHEET_EXCEL_READER_TYPE_XF:
608                          //global $dateFormats, $numberFormats;
609                          $indexCode = ord($this->data[$pos+6]) | ord($this->data[$pos+7]) << 8;
610                          //echo "\nType.XF ".count($this->formatRecords['xfrecords'])." $indexCode ";
611                          if (array_key_exists($indexCode, $this->dateFormats)) {
612                              //echo "isdate ".$dateFormats[$indexCode];
613                              $this->formatRecords['xfrecords'][] = array(
614                                      'type' => 'date',
615                                      'format' => $this->dateFormats[$indexCode]
616                                      );
617                          }elseif (array_key_exists($indexCode, $this->numberFormats)) {
618                          //echo "isnumber ".$this->numberFormats[$indexCode];
619                              $this->formatRecords['xfrecords'][] = array(
620                                      'type' => 'number',
621                                      'format' => $this->numberFormats[$indexCode]
622                                      );
623                          }else{
624                              $isdate = FALSE;
625                              if ($indexCode > 0){
626                                  if (isset($this->formatRecords[$indexCode]))
627                                      $formatstr = $this->formatRecords[$indexCode];
628                                  //echo '.other.';
629                                  //echo "\ndate-time=$formatstr=\n";
630                                  if ($formatstr)
631                                  if (preg_match("/[^hmsday\/\-:\s]/i", $formatstr) == 0) { // found day and time format
632                                      $isdate = TRUE;
633                                      $formatstr = str_replace('mm', 'i', $formatstr);
634                                      $formatstr = str_replace('h', 'H', $formatstr);
635                                      //echo "\ndate-time $formatstr \n";
636                                  }
637                              }
638 
639                              if ($isdate){
640                                  $this->formatRecords['xfrecords'][] = array(
641                                          'type' => 'date',
642                                          'format' => $formatstr,
643                                          );
644                              }else{
645                                  $this->formatRecords['xfrecords'][] = array(
646                                          'type' => 'other',
647                                          'format' => '',
648                                          'code' => $indexCode
649                                          );
650                              }
651                          }
652                          //echo "\n";
653                      break;
654                  case SPREADSHEET_EXCEL_READER_TYPE_NINETEENFOUR:
655                      //echo "Type.NINETEENFOUR\n";
656                      $this->nineteenFour = (ord($this->data[$pos+4]) == 1);
657                      break;
658                  case SPREADSHEET_EXCEL_READER_TYPE_BOUNDSHEET:
659                      //echo "Type.BOUNDSHEET\n";
660                          $rec_offset = $this->_GetInt4d($this->data, $pos+4);
661                          $rec_typeFlag = ord($this->data[$pos+8]);
662                          $rec_visibilityFlag = ord($this->data[$pos+9]);
663                          $rec_length = ord($this->data[$pos+10]);
664 
665                          if ($version == SPREADSHEET_EXCEL_READER_BIFF8){
666                              $chartype ord($this->data[$pos+11]);
667                              if ($chartype == 0){
668                                  $rec_name    = substr($this->data, $pos+12, $rec_length);
669                              } else {
670                                  $rec_name    = $this->_encodeUTF16(substr($this->data, $pos+12, $rec_length*2));
671                              }
672                          }elseif ($version == SPREADSHEET_EXCEL_READER_BIFF7){
673                                  $rec_name    = substr($this->data, $pos+11, $rec_length);
674                          }
675                      $this->boundsheets[] = array('name'=>$rec_name,
676                                                   'offset'=>$rec_offset);
677 
678                      break;
679 
680              }
681 
682              //echo "Code = ".base_convert($r['code'],10,16)."\n";
683              $pos += $length + 4;
684              $code = ord($this->data[$pos]) | ord($this->data[$pos+1])<<8;
685              $length = ord($this->data[$pos+2]) | ord($this->data[$pos+3])<<8;
686 
687              //$r = &$this->nextRecord();
688              //echo "1 Code = ".base_convert($r['code'],10,16)."\n";
689          }
690 
691          foreach ($this->boundsheets as $key=>$val){
692              $this->sn = $key;
693              $this->_parsesheet($val['offset']);
694          }
695          return true;
696 
697      }
public_parsesheet ( spos )[ excel_reader ]
Parameters
requiredspos
Code
706      function _parsesheet($spos)
707      {
708          $cont = true;
709          // read BOF
710          $code = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8;
711          $length = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8;
712 
713          $version = ord($this->data[$spos + 4]) | ord($this->data[$spos + 5])<<8;
714          $substreamType = ord($this->data[$spos + 6]) | ord($this->data[$spos + 7])<<8;
715 
716          if (($version != SPREADSHEET_EXCEL_READER_BIFF8) && ($version != SPREADSHEET_EXCEL_READER_BIFF7)) {
717              return -1;
718          }
719 
720          if ($substreamType != SPREADSHEET_EXCEL_READER_WORKSHEET){
721              return -2;
722          }
723          //echo "Start parse code=".base_convert($code,10,16)." version=".base_convert($version,10,16)." substreamType=".base_convert($substreamType,10,16).""."\n";
724          $spos += $length + 4;
725          //var_dump($this->formatRecords);
726      //echo "code $code $length";
727          while($cont) {
728              //echo "mem= ".memory_get_usage()."\n";
729  //            $r = &$this->file->nextRecord();
730              $lowcode = ord($this->data[$spos]);
731              if ($lowcode == SPREADSHEET_EXCEL_READER_TYPE_EOF) break;
732              $code = $lowcode | ord($this->data[$spos+1])<<8;
733              $length = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8;
734              $spos += 4;
735              $this->sheets[$this->sn]['maxrow'] = $this->_rowoffset - 1;
736              $this->sheets[$this->sn]['maxcol'] = $this->_coloffset - 1;
737              //echo "Code=".base_convert($code,10,16)." $code\n";
738              unset($this->rectype);
739              $this->multiplier = 1; // need for format with %
740              switch ($code) {
741                  case SPREADSHEET_EXCEL_READER_TYPE_DIMENSION:
742                      //echo 'Type_DIMENSION ';
743                      if (!isset($this->numRows)) {
744                          if (($length == 10) ||  ($version == SPREADSHEET_EXCEL_READER_BIFF7)){
745                              $this->sheets[$this->sn]['numRows'] = ord($this->data[$spos+2]) | ord($this->data[$spos+3]) << 8;
746                              $this->sheets[$this->sn]['numCols'] = ord($this->data[$spos+6]) | ord($this->data[$spos+7]) << 8;
747                          } else {
748                              $this->sheets[$this->sn]['numRows'] = ord($this->data[$spos+4]) | ord($this->data[$spos+5]) << 8;
749                              $this->sheets[$this->sn]['numCols'] = ord($this->data[$spos+10]) | ord($this->data[$spos+11]) << 8;
750                          }
751                      }
752                      //echo 'numRows '.$this->numRows.' '.$this->numCols."\n";
753                      break;
754                  case SPREADSHEET_EXCEL_READER_TYPE_MERGEDCELLS:
755                      $cellRanges = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8;
756                      for ($i = 0; $i < $cellRanges; $i++) {
757                          $fr ord($this->data[$spos + 8*$i + 2]) | ord($this->data[$spos + 8*$i + 3])<<8;
758                          $lr ord($this->data[$spos + 8*$i + 4]) | ord($this->data[$spos + 8*$i + 5])<<8;
759                          $fc ord($this->data[$spos + 8*$i + 6]) | ord($this->data[$spos + 8*$i + 7])<<8;
760                          $lc ord($this->data[$spos + 8*$i + 8]) | ord($this->data[$spos + 8*$i + 9])<<8;
761                          //$this->sheets[$this->sn]['mergedCells'][] = array($fr + 1, $fc + 1, $lr + 1, $lc + 1);
762                          if ($lr - $fr > 0) {
763                              $this->sheets[$this->sn]['cellsInfo'][$fr+1][$fc+1]['rowspan'] = $lr - $fr + 1;
764                          }
765                          if ($lc - $fc > 0) {
766                              $this->sheets[$this->sn]['cellsInfo'][$fr+1][$fc+1]['colspan'] = $lc - $fc + 1;
767                          }
768                      }
769                      //echo "Merged Cells $cellRanges $lr $fr $lc $fc\n";
770                      break;
771                  case SPREADSHEET_EXCEL_READER_TYPE_RK:
772                  case SPREADSHEET_EXCEL_READER_TYPE_RK2:
773                      //echo 'SPREADSHEET_EXCEL_READER_TYPE_RK'."\n";
774                      $row = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8;
775                      $column = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8;
776                      $rknum = $this->_GetInt4d($this->data, $spos + 6);
777                      $numValue = $this->_GetIEEE754($rknum);
778                      //echo $numValue." ";
779                      if ($this->isDate($spos)) {
780                          list($string, $raw) = $this->createDate($numValue);
781                      }else{
782                          $raw = $numValue;
783                          if (isset($this->_columnsFormat[$column + 1])){
784                                  $this->curformat = $this->_columnsFormat[$column + 1];
785                          }
786                          $string = sprintf($this->curformat, $numValue * $this->multiplier);
787                          //$this->addcell(RKRecord($r));
788                      }
789                      $this->addcell($row, $column, $string, $raw);
790                      //echo "Type_RK $row $column $string $raw {$this->curformat}\n";
791                      break;
792                  case SPREADSHEET_EXCEL_READER_TYPE_LABELSST:
793                          $row        = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8;
794                          $column     = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8;
795                          $xfindex    = ord($this->data[$spos+4]) | ord($this->data[$spos+5])<<8;
796                          $index  = $this->_GetInt4d($this->data, $spos + 6);
797              //var_dump($this->sst);
798                          $this->addcell($row, $column, $this->sst[$index]);
799                          //echo "LabelSST $row $column $string\n";
800                      break;
801                  case SPREADSHEET_EXCEL_READER_TYPE_MULRK:
802                      $row        = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8;
803                      $colFirst   = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8;
804                      $colLast    = ord($this->data[$spos + $length - 2]) | ord($this->data[$spos + $length - 1])<<8;
805                      $columns    = $colLast - $colFirst + 1;
806                      $tmppos = $spos+4;
807                      for ($i = 0; $i < $columns; $i++) {
808                          $numValue = $this->_GetIEEE754($this->_GetInt4d($this->data, $tmppos + 2));
809                          if ($this->isDate($tmppos-4)) {
810                              list($string, $raw) = $this->createDate($numValue);
811                          }else{
812                              $raw = $numValue;
813                              if (isset($this->_columnsFormat[$colFirst + $i + 1])){
814                                          $this->curformat = $this->_columnsFormat[$colFirst + $i + 1];
815                                  }
816                              $string = sprintf($this->curformat, $numValue * $this->multiplier);
817                          }
818                        //$rec['rknumbers'][$i]['xfindex'] = ord($rec['data'][$pos]) | ord($rec['data'][$pos+1]) << 8;
819                        $tmppos += 6;
820                        $this->addcell($row, $colFirst + $i, $string, $raw);
821                        //echo "MULRK $row ".($colFirst + $i)." $string\n";
822                      }
823                       //MulRKRecord($r);
824                      // Get the individual cell records from the multiple record
825                       //$num = ;
826 
827                      break;
828                  case SPREADSHEET_EXCEL_READER_TYPE_NUMBER:
829                      $row    = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8;
830                      $column = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8;
831                      $tmp = unpack("ddouble", substr($this->data, $spos + 6, 8)); // It machine machine dependent
832                      if ($this->isDate($spos)) {
833                          list($string, $raw) = $this->createDate($tmp['double']);
834                       //   $this->addcell(DateRecord($r, 1));
835                      }else{
836                          //$raw = $tmp[''];
837                          if (isset($this->_columnsFormat[$column + 1])){
838                                  $this->curformat = $this->_columnsFormat[$column + 1];
839                          }
840                          $raw = $this->createNumber($spos);
841                          $string = sprintf($this->curformat, $raw * $this->multiplier);
842 
843                       //   $this->addcell(NumberRecord($r));
844                      }
845                      $this->addcell($row, $column, $string, $raw);
846                      //echo "Number $row $column $string\n";
847                      break;
848                  case SPREADSHEET_EXCEL_READER_TYPE_FORMULA:
849                  case SPREADSHEET_EXCEL_READER_TYPE_FORMULA2:
850                      $row    = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8;
851                      $column = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8;
852                      if ((ord($this->data[$spos+6])==0) && (ord($this->data[$spos+12])==255) && (ord($this->data[$spos+13])==255)) {
853                          //String formula. Result follows in a STRING record
854                          //echo "FORMULA $row $column Formula with a string<br>\n";
855                      } elseif ((ord($this->data[$spos+6])==1) && (ord($this->data[$spos+12])==255) && (ord($this->data[$spos+13])==255)) {
856                          //Boolean formula. Result is in +2; 0=false,1=true
857                      } elseif ((ord($this->data[$spos+6])==2) && (ord($this->data[$spos+12])==255) && (ord($this->data[$spos+13])==255)) {
858                          //Error formula. Error code is in +2;
859                      } elseif ((ord($this->data[$spos+6])==3) && (ord($this->data[$spos+12])==255) && (ord($this->data[$spos+13])==255)) {
860                          //Formula result is a null string.
861                      } else {
862                          // result is a number, so first 14 bytes are just like a _NUMBER record
863                          $tmp = unpack("ddouble", substr($this->data, $spos + 6, 8)); // It machine machine dependent
864                          if ($this->isDate($spos)) {
865                              list($string, $raw) = $this->createDate($tmp['double']);
866                           //   $this->addcell(DateRecord($r, 1));
867                          }else{
868                              //$raw = $tmp[''];
869                              if (isset($this->_columnsFormat[$column + 1])){
870                                      $this->curformat = $this->_columnsFormat[$column + 1];
871                              }
872                              $raw = $this->createNumber($spos);
873                              $string = sprintf($this->curformat, $raw * $this->multiplier);
874 
875                           //   $this->addcell(NumberRecord($r));
876                          }
877                          $this->addcell($row, $column, $string, $raw);
878                          //echo "Number $row $column $string\n";
879                      }
880                      break;
881                  case SPREADSHEET_EXCEL_READER_TYPE_BOOLERR:
882                      $row    = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8;
883                      $column = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8;
884                      $string = ord($this->data[$spos+6]);
885                      $this->addcell($row, $column, $string);
886                      //echo 'Type_BOOLERR '."\n";
887                      break;
888                  case SPREADSHEET_EXCEL_READER_TYPE_ROW:
889                  case SPREADSHEET_EXCEL_READER_TYPE_DBCELL:
890                  case SPREADSHEET_EXCEL_READER_TYPE_MULBLANK:
891                      break;
892                  case SPREADSHEET_EXCEL_READER_TYPE_LABEL:
893                      $row    = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8;
894                      $column = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8;
895                      $this->addcell($row, $column, substr($this->data, $spos + 8, ord($this->data[$spos + 6]) | ord($this->data[$spos + 7])<<8));
896 
897                     // $this->addcell(LabelRecord($r));
898                      break;
899 
900                  case SPREADSHEET_EXCEL_READER_TYPE_EOF:
901                      $cont = false;
902                      break;
903                  default:
904                      //echo ' unknown :'.base_convert($r['code'],10,16)."\n";
905                      break;
906 
907              }
908              $spos += $length;
909          }
910 
911          if (!isset($this->sheets[$this->sn]['numRows']))
912               $this->sheets[$this->sn]['numRows'] = $this->sheets[$this->sn]['maxrow'];
913          if (!isset($this->sheets[$this->sn]['numCols']))
914               $this->sheets[$this->sn]['numCols'] = $this->sheets[$this->sn]['maxcol'];
915 
916      }
publicread ( sFileName )[ excel_reader ]
Parameters
requiredsFileName
Code
354      function read($sFileName)
355      {
356      /*
357          require_once 'OLE.php';
358          $ole = new OLE();
359          $ole->read($sFileName);
360 
361          foreach ($ole->_list as $i => $pps) {
362              if (($pps->Name == 'Workbook' || $pps->Name == 'Book') &&
363                  $pps->Size >= SMALL_BLOCK_THRESHOLD) {
364 
365                  $this->data = $ole->getData($i, 0, $ole->getDataLength($i));
366              } elseif ($pps->Name == 'Root Entry') {
367                  $this->data = $ole->getData($i, 0, $ole->getDataLength($i));
368              }
369              //var_dump(strlen($ole->getData($i, 0, $ole->getDataLength($i))), $pps->Name, md5($this->data), $ole->getDataLength($i));
370          }
371  //exit;
372          $this->_parse();
373 
374          return sizeof($this->sheets) > 0;
375      */
376 
377          $res = $this->_ole->read($sFileName);
378 
379          // oops, something goes wrong (Darko Miljanovic)
380          if($res === false) {
381              // check error code
382              if($this->_ole->error == 1) {
383              // bad file
384                  die('The filename ' . $sFileName . ' is not readable');
385              }
386              // check other error codes here (eg bad fileformat, etc...)
387          }
388 
389          $this->data = $this->_ole->getWorkBook();
390 
391 
392          /*
393          $res = $this->_ole->read($sFileName);
394 
395          if ($this->isError($res)) {
396  //        var_dump($res);
397              return $this->raiseError($res);
398          }
399 
400          $total = $this->_ole->ppsTotal();
401          for ($i = 0; $i < $total; $i++) {
402              if ($this->_ole->isFile($i)) {
403                  $type = unpack("v", $this->_ole->getData($i, 0, 2));
404                  if ($type[''] == 0x0809)  { // check if it's a BIFF stream
405                      $this->_index = $i;
406                      $this->data = $this->_ole->getData($i, 0, $this->_ole->getDataLength($i));
407                      break;
408                  }
409              }
410          }
411 
412          if ($this->_index === null) {
413              return $this->raiseError("$file doesn't seem to be an Excel file");
414          }
415 
416          */
417 
418      //echo "data =".$this->data;
419          //$this->readRecords();
420          $this->_parse();
421      }
publicsetColumnFormat ( column , sFormat )[ excel_reader ]
Parameters
requiredcolumn
requiredsFormat
Code
338      function setColumnFormat($column, $sFormat)
339      {
340          $this->_columnsFormat[$column] = $sFormat;
341      }
publicsetDefaultFormat ( sFormat )[ excel_reader ]
Parameters
requiredsFormat
Code
323      function setDefaultFormat($sFormat)
324      {
325          $this->_defaultFormat = $sFormat;
326      }
publicsetOutputEncoding ( encoding )[ excel_reader ]
Parameters
requiredencoding
Code
270      function setOutputEncoding($encoding)
271      {
272          $this->_defaultEncoding = $encoding;
273      }
publicsetRowColOffset ( iOffset )[ excel_reader ]
Parameters
requirediOffset
Code
308      function setRowColOffset($iOffset)
309      {
310          $this->_rowoffset = $iOffset;
311          $this->_coloffset = $iOffset;
312      }
publicsetUTFEncoder ( encoder ["iconv"] )[ excel_reader ]
Parameters
optionalencoder ["iconv"]
Code
286      function setUTFEncoder($encoder = 'iconv')
287      {
288          $this->_encoderFunction = '';
289 
290          if ($encoder == 'iconv') {
291              $this->_encoderFunction = function_exists('iconv') ? 'iconv' : '';
292          } elseif ($encoder == 'mb') {
293              $this->_encoderFunction = function_exists('mb_convert_encoding') ?
294                                        'mb_convert_encoding' :
295                                        '';
296          }
297      }
 
Accessors
Get Helix PHP Framework at SourceForge.net. Fast, secure and Free Open Source software downloads