Advertisement
Guest User

excel-reader

a guest
Jan 23rd, 2020
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 47.93 KB | None | 0 0
  1. <?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3.  
  4. /**
  5. * A class for reading Microsoft Excel Spreadsheets.
  6. *
  7. * Originally developed by Vadim Tkachenko under the name PHPExcelReader.
  8. * (http://sourceforge.net/projects/phpexcelreader)
  9. * Based on the Java version by Andy Khan (http://www.andykhan.com).  Now
  10. * maintained by David Sanders.  Reads only Biff 7 and Biff 8 formats.
  11. *
  12. * PHP versions 4 and 5
  13. *
  14. * LICENSE: This source file is subject to version 3.0 of the PHP license
  15. * that is available through the world-wide-web at the following URI:
  16. * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  17. * the PHP License and are unable to obtain it through the web, please
  18. * send a note to license@php.net so we can mail you a copy immediately.
  19. *
  20. * @category   Spreadsheet
  21. * @package    Spreadsheet_Excel_Reader
  22. * @author     Vadim Tkachenko <vt@apachephp.com>
  23. * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  24. * @version    CVS: $Id: reader.php 19 2007-03-13 12:42:41Z shangxiao $
  25. * @link       http://pear.php.net/package/Spreadsheet_Excel_Reader
  26. * @see        OLE, Spreadsheet_Excel_Writer
  27. */
  28.  
  29.  
  30. //require_once 'PEAR.php';
  31. require_once 'oleread.inc.php';
  32. //require_once 'OLE.php';
  33.  
  34. define('SPREADSHEET_EXCEL_READER_BIFF8',             0x600);
  35. define('SPREADSHEET_EXCEL_READER_BIFF7',             0x500);
  36. define('SPREADSHEET_EXCEL_READER_WORKBOOKGLOBALS',   0x5);
  37. define('SPREADSHEET_EXCEL_READER_WORKSHEET',         0x10);
  38.  
  39. define('SPREADSHEET_EXCEL_READER_TYPE_BOF',          0x809);
  40. define('SPREADSHEET_EXCEL_READER_TYPE_EOF',          0x0a);
  41. define('SPREADSHEET_EXCEL_READER_TYPE_BOUNDSHEET',   0x85);
  42. define('SPREADSHEET_EXCEL_READER_TYPE_DIMENSION',    0x200);
  43. define('SPREADSHEET_EXCEL_READER_TYPE_ROW',          0x208);
  44. define('SPREADSHEET_EXCEL_READER_TYPE_DBCELL',       0xd7);
  45. define('SPREADSHEET_EXCEL_READER_TYPE_FILEPASS',     0x2f);
  46. define('SPREADSHEET_EXCEL_READER_TYPE_NOTE',         0x1c);
  47. define('SPREADSHEET_EXCEL_READER_TYPE_TXO',          0x1b6);
  48. define('SPREADSHEET_EXCEL_READER_TYPE_RK',           0x7e);
  49. define('SPREADSHEET_EXCEL_READER_TYPE_RK2',          0x27e);
  50. define('SPREADSHEET_EXCEL_READER_TYPE_MULRK',        0xbd);
  51. define('SPREADSHEET_EXCEL_READER_TYPE_MULBLANK',     0xbe);
  52. define('SPREADSHEET_EXCEL_READER_TYPE_INDEX',        0x20b);
  53. define('SPREADSHEET_EXCEL_READER_TYPE_SST',          0xfc);
  54. define('SPREADSHEET_EXCEL_READER_TYPE_EXTSST',       0xff);
  55. define('SPREADSHEET_EXCEL_READER_TYPE_CONTINUE',     0x3c);
  56. define('SPREADSHEET_EXCEL_READER_TYPE_LABEL',        0x204);
  57. define('SPREADSHEET_EXCEL_READER_TYPE_LABELSST',     0xfd);
  58. define('SPREADSHEET_EXCEL_READER_TYPE_NUMBER',       0x203);
  59. define('SPREADSHEET_EXCEL_READER_TYPE_NAME',         0x18);
  60. define('SPREADSHEET_EXCEL_READER_TYPE_ARRAY',        0x221);
  61. define('SPREADSHEET_EXCEL_READER_TYPE_STRING',       0x207);
  62. define('SPREADSHEET_EXCEL_READER_TYPE_FORMULA',      0x406);
  63. define('SPREADSHEET_EXCEL_READER_TYPE_FORMULA2',     0x6);
  64. define('SPREADSHEET_EXCEL_READER_TYPE_FORMAT',       0x41e);
  65. define('SPREADSHEET_EXCEL_READER_TYPE_XF',           0xe0);
  66. define('SPREADSHEET_EXCEL_READER_TYPE_BOOLERR',      0x205);
  67. define('SPREADSHEET_EXCEL_READER_TYPE_UNKNOWN',      0xffff);
  68. define('SPREADSHEET_EXCEL_READER_TYPE_NINETEENFOUR', 0x22);
  69. define('SPREADSHEET_EXCEL_READER_TYPE_MERGEDCELLS',  0xE5);
  70.  
  71. define('SPREADSHEET_EXCEL_READER_UTCOFFSETDAYS' ,    25569);
  72. define('SPREADSHEET_EXCEL_READER_UTCOFFSETDAYS1904', 24107);
  73. define('SPREADSHEET_EXCEL_READER_MSINADAY',          86400);
  74. //define('SPREADSHEET_EXCEL_READER_MSINADAY', 24 * 60 * 60);
  75.  
  76. //define('SPREADSHEET_EXCEL_READER_DEF_NUM_FORMAT', "%.2f");
  77. define('SPREADSHEET_EXCEL_READER_DEF_NUM_FORMAT',    "%s");
  78.  
  79.  
  80. /*
  81. * Place includes, constant defines and $_GLOBAL settings here.
  82. * Make sure they have appropriate docblocks to avoid phpDocumentor
  83. * construing they are documented by the page-level docblock.
  84. */
  85.  
  86. /**
  87. * A class for reading Microsoft Excel Spreadsheets.
  88. *
  89. * Originally developed by Vadim Tkachenko under the name PHPExcelReader.
  90. * (http://sourceforge.net/projects/phpexcelreader)
  91. * Based on the Java version by Andy Khan (http://www.andykhan.com).  Now
  92. * maintained by David Sanders.  Reads only Biff 7 and Biff 8 formats.
  93. *
  94. * @category   Spreadsheet
  95. * @package    Spreadsheet_Excel_Reader
  96. * @author     Vadim Tkachenko <vt@phpapache.com>
  97. * @copyright  1997-2005 The PHP Group
  98. * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  99. * @version    Release: @package_version@
  100. * @link       http://pear.php.net/package/PackageName
  101. * @see        OLE, Spreadsheet_Excel_Writer
  102. */
  103. class Excel_reader
  104. {
  105.     /**
  106.      * Array of worksheets found
  107.      *
  108.      * @var array
  109.      * @access public
  110.      */
  111.     var $boundsheets = array();
  112.  
  113.     /**
  114.      * Array of format records found
  115.      *
  116.      * @var array
  117.      * @access public
  118.      */
  119.     var $formatRecords = array();
  120.  
  121.     /**
  122.      * todo
  123.      *
  124.      * @var array
  125.      * @access public
  126.      */
  127.     var $sst = array();
  128.  
  129.     /**
  130.      * Array of worksheets
  131.      *
  132.      * The data is stored in 'cells' and the meta-data is stored in an array
  133.      * called 'cellsInfo'
  134.      *
  135.      * Example:
  136.      *
  137.      * $sheets  -->  'cells'  -->  row --> column --> Interpreted value
  138.      *          -->  'cellsInfo' --> row --> column --> 'type' - Can be 'date', 'number', or 'unknown'
  139.      *                                            --> 'raw' - The raw data that Excel stores for that data cell
  140.      *
  141.      * @var array
  142.      * @access public
  143.      */
  144.     var $sheets = array();
  145.  
  146.     /**
  147.      * The data returned by OLE
  148.      *
  149.      * @var string
  150.      * @access public
  151.      */
  152.     var $data;
  153.  
  154.     /**
  155.      * OLE object for reading the file
  156.      *
  157.      * @var OLE object
  158.      * @access private
  159.      */
  160.     var $_ole;
  161.  
  162.     /**
  163.      * Default encoding
  164.      *
  165.      * @var string
  166.      * @access private
  167.      */
  168.     var $_defaultEncoding;
  169.  
  170.     /**
  171.      * Default number format
  172.      *
  173.      * @var integer
  174.      * @access private
  175.      */
  176.     var $_defaultFormat = SPREADSHEET_EXCEL_READER_DEF_NUM_FORMAT;
  177.  
  178.     /**
  179.      * todo
  180.      * List of formats to use for each column
  181.      *
  182.      * @var array
  183.      * @access private
  184.      */
  185.     var $_columnsFormat = array();
  186.  
  187.     /**
  188.      * todo
  189.      *
  190.      * @var integer
  191.      * @access private
  192.      */
  193.     var $_rowoffset = 1;
  194.  
  195.     /**
  196.      * todo
  197.      *
  198.      * @var integer
  199.      * @access private
  200.      */
  201.     var $_coloffset = 1;
  202.  
  203.     /**
  204.      * List of default date formats used by Excel
  205.      *
  206.      * @var array
  207.      * @access public
  208.      */
  209.     var $dateFormats = array (
  210.         0xe => "d/m/Y",
  211.         0xf => "d-M-Y",
  212.         0x10 => "d-M",
  213.         0x11 => "M-Y",
  214.         0x12 => "h:i a",
  215.         0x13 => "h:i:s a",
  216.         0x14 => "H:i",
  217.         0x15 => "H:i:s",
  218.         0x16 => "d/m/Y H:i",
  219.         0x2d => "i:s",
  220.         0x2e => "H:i:s",
  221.         0x2f => "i:s.S");
  222.  
  223.     /**
  224.      * Default number formats used by Excel
  225.      *
  226.      * @var array
  227.      * @access public
  228.      */
  229.     var $numberFormats = array(
  230.         0x1 => "%1.0f",     // "0"
  231.         0x2 => "%1.2f",     // "0.00",
  232.         0x3 => "%1.0f",     //"#,##0",
  233.         0x4 => "%1.2f",     //"#,##0.00",
  234.         0x5 => "%1.0f",     /*"$#,##0;($#,##0)",*/
  235.         0x6 => '$%1.0f',    /*"$#,##0;($#,##0)",*/
  236.         0x7 => '$%1.2f',    //"$#,##0.00;($#,##0.00)",
  237.         0x8 => '$%1.2f',    //"$#,##0.00;($#,##0.00)",
  238.         0x9 => '%1.0f%%',   // "0%"
  239.         0xa => '%1.2f%%',   // "0.00%"
  240.         0xb => '%1.2f',     // 0.00E00",
  241.         0x25 => '%1.0f',    // "#,##0;(#,##0)",
  242.         0x26 => '%1.0f',    //"#,##0;(#,##0)",
  243.         0x27 => '%1.2f',    //"#,##0.00;(#,##0.00)",
  244.         0x28 => '%1.2f',    //"#,##0.00;(#,##0.00)",
  245.         0x29 => '%1.0f',    //"#,##0;(#,##0)",
  246.         0x2a => '$%1.0f',   //"$#,##0;($#,##0)",
  247.         0x2b => '%1.2f',    //"#,##0.00;(#,##0.00)",
  248.         0x2c => '$%1.2f',   //"$#,##0.00;($#,##0.00)",
  249.         0x30 => '%1.0f');   //"##0.0E0";
  250.  
  251.     // }}}
  252.     // {{{ Spreadsheet_Excel_Reader()
  253.  
  254.     /**
  255.      * Constructor
  256.      *
  257.      * Some basic initialisation
  258.      */
  259.     function Excel_reader()
  260.     {
  261.         $this->_ole = new OLERead();
  262.         $this->setUTFEncoder('iconv');
  263.     }
  264.  
  265.     // }}}
  266.     // {{{ setOutputEncoding()
  267.  
  268.     /**
  269.      * Set the encoding method
  270.      *
  271.      * @param string Encoding to use
  272.      * @access public
  273.      */
  274.     function setOutputEncoding($encoding)
  275.     {
  276.         $this->_defaultEncoding = $encoding;
  277.     }
  278.  
  279.     // }}}
  280.     // {{{ setUTFEncoder()
  281.  
  282.     /**
  283.      *  $encoder = 'iconv' or 'mb'
  284.      *  set iconv if you would like use 'iconv' for encode UTF-16LE to your encoding
  285.      *  set mb if you would like use 'mb_convert_encoding' for encode UTF-16LE to your encoding
  286.      *
  287.      * @access public
  288.      * @param string Encoding type to use.  Either 'iconv' or 'mb'
  289.      */
  290.     function setUTFEncoder($encoder = 'iconv')
  291.     {
  292.         $this->_encoderFunction = '';
  293.  
  294.         if ($encoder == 'iconv') {
  295.             $this->_encoderFunction = function_exists('iconv') ? 'iconv' : '';
  296.         } elseif ($encoder == 'mb') {
  297.             $this->_encoderFunction = function_exists('mb_convert_encoding') ?
  298.                                       'mb_convert_encoding' :
  299.                                       '';
  300.         }
  301.     }
  302.  
  303.     // }}}
  304.     // {{{ setRowColOffset()
  305.  
  306.     /**
  307.      * todo
  308.      *
  309.      * @access public
  310.      * @param offset
  311.      */
  312.     function setRowColOffset($iOffset)
  313.     {
  314.         $this->_rowoffset = $iOffset;
  315.         $this->_coloffset = $iOffset;
  316.     }
  317.  
  318.     // }}}
  319.     // {{{ setDefaultFormat()
  320.  
  321.     /**
  322.      * Set the default number format
  323.      *
  324.      * @access public
  325.      * @param Default format
  326.      */
  327.     function setDefaultFormat($sFormat)
  328.     {
  329.         $this->_defaultFormat = $sFormat;
  330.     }
  331.  
  332.     // }}}
  333.     // {{{ setColumnFormat()
  334.  
  335.     /**
  336.      * Force a column to use a certain format
  337.      *
  338.      * @access public
  339.      * @param integer Column number
  340.      * @param string Format
  341.      */
  342.     function setColumnFormat($column, $sFormat)
  343.     {
  344.         $this->_columnsFormat[$column] = $sFormat;
  345.     }
  346.  
  347.  
  348.     // }}}
  349.     // {{{ read()
  350.  
  351.     /**
  352.      * Read the spreadsheet file using OLE, then parse
  353.      *
  354.      * @access public
  355.      * @param filename
  356.      * @todo return a valid value
  357.      */
  358.     function read($sFileName)
  359.     {
  360.     /*
  361.         require_once 'OLE.php';
  362.         $ole = new OLE();
  363.         $ole->read($sFileName);
  364.  
  365.         foreach ($ole->_list as $i => $pps) {
  366.             if (($pps->Name == 'Workbook' || $pps->Name == 'Book') &&
  367.                 $pps->Size >= SMALL_BLOCK_THRESHOLD) {
  368.  
  369.                 $this->data = $ole->getData($i, 0, $ole->getDataLength($i));
  370.             } elseif ($pps->Name == 'Root Entry') {
  371.                 $this->data = $ole->getData($i, 0, $ole->getDataLength($i));
  372.             }
  373.             //var_dump(strlen($ole->getData($i, 0, $ole->getDataLength($i))), $pps->Name, md5($this->data), $ole->getDataLength($i));
  374.         }
  375. //exit;
  376.         $this->_parse();
  377.  
  378.         return sizeof($this->sheets) > 0;
  379.     */
  380.  
  381.         $res = $this->_ole->read($sFileName);
  382.  
  383.         // oops, something goes wrong (Darko Miljanovic)
  384.         if($res === false) {
  385.             // check error code
  386.             if($this->_ole->error == 1) {
  387.             // bad file
  388.                 die('The filename ' . $sFileName . ' is not readable');
  389.             }
  390.             // check other error codes here (eg bad fileformat, etc...)
  391.         }
  392.  
  393.         $this->data = $this->_ole->getWorkBook();
  394.  
  395.  
  396.         /*
  397.         $res = $this->_ole->read($sFileName);
  398.  
  399.         if ($this->isError($res)) {
  400. //        var_dump($res);
  401.             return $this->raiseError($res);
  402.         }
  403.  
  404.         $total = $this->_ole->ppsTotal();
  405.         for ($i = 0; $i < $total; $i++) {
  406.             if ($this->_ole->isFile($i)) {
  407.                 $type = unpack("v", $this->_ole->getData($i, 0, 2));
  408.                 if ($type[''] == 0x0809)  { // check if it's a BIFF stream
  409.                     $this->_index = $i;
  410.                     $this->data = $this->_ole->getData($i, 0, $this->_ole->getDataLength($i));
  411.                     break;
  412.                 }
  413.             }
  414.         }
  415.  
  416.         if ($this->_index === null) {
  417.             return $this->raiseError("$file doesn't seem to be an Excel file");
  418.         }
  419.  
  420.         */
  421.  
  422.     //echo "data =".$this->data;
  423.         //$this->readRecords();
  424.         $this->_parse();
  425.     }
  426.  
  427.  
  428.     // }}}
  429.     // {{{ _parse()
  430.  
  431.     /**
  432.      * Parse a workbook
  433.      *
  434.      * @access private
  435.      * @return bool
  436.      */
  437.     function _parse()
  438.     {
  439.         $pos = 0;
  440.  
  441.         $code = ord($this->data[$pos]) | ord($this->data[$pos+1])<<8;
  442.         $length = ord($this->data[$pos+2]) | ord($this->data[$pos+3])<<8;
  443.  
  444.         $version = ord($this->data[$pos + 4]) | ord($this->data[$pos + 5])<<8;
  445.         $substreamType = ord($this->data[$pos + 6]) | ord($this->data[$pos + 7])<<8;
  446.         //echo "Start parse code=".base_convert($code,10,16)." version=".base_convert($version,10,16)." substreamType=".base_convert($substreamType,10,16).""."\n";
  447.  
  448.         if (($version != SPREADSHEET_EXCEL_READER_BIFF8) &&
  449.             ($version != SPREADSHEET_EXCEL_READER_BIFF7)) {
  450.             return false;
  451.         }
  452.  
  453.         if ($substreamType != SPREADSHEET_EXCEL_READER_WORKBOOKGLOBALS){
  454.             return false;
  455.         }
  456.  
  457.         //print_r($rec);
  458.         $pos += $length + 4;
  459.  
  460.         $code = ord($this->data[$pos]) | ord($this->data[$pos+1])<<8;
  461.         $length = ord($this->data[$pos+2]) | ord($this->data[$pos+3])<<8;
  462.  
  463.         while ($code != SPREADSHEET_EXCEL_READER_TYPE_EOF) {
  464.             switch ($code) {
  465.                 case SPREADSHEET_EXCEL_READER_TYPE_SST:
  466.                     //echo "Type_SST\n";
  467.                      $spos = $pos + 4;
  468.                      $limitpos = $spos + $length;
  469.                      $uniqueStrings = $this->_GetInt4d($this->data, $spos+4);
  470.                                                 $spos += 8;
  471.                                        for ($i = 0; $i < $uniqueStrings; $i++) {
  472.         // Read in the number of characters
  473.                                                 if ($spos == $limitpos) {
  474.                                                 $opcode = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8;
  475.                                                 $conlength = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8;
  476.                                                         if ($opcode != 0x3c) {
  477.                                                                 return -1;
  478.                                                         }
  479.                                                 $spos += 4;
  480.                                                 $limitpos = $spos + $conlength;
  481.                                                 }
  482.                                                 $numChars = ord($this->data[$spos]) | (ord($this->data[$spos+1]) << 8);
  483.                                                 //echo "i = $i pos = $pos numChars = $numChars ";
  484.                                                 $spos += 2;
  485.                                                 $optionFlags = ord($this->data[$spos]);
  486.                                                 $spos++;
  487.                                         $asciiEncoding = (($optionFlags & 0x01) == 0) ;
  488.                                                 $extendedString = ( ($optionFlags & 0x04) != 0);
  489.  
  490.                                                 // See if string contains formatting information
  491.                                                 $richString = ( ($optionFlags & 0x08) != 0);
  492.  
  493.                                                 if ($richString) {
  494.                                         // Read in the crun
  495.                                                         $formattingRuns = ord($this->data[$spos]) | (ord($this->data[$spos+1]) << 8);
  496.                                                         $spos += 2;
  497.                                                 }
  498.  
  499.                                                 if ($extendedString) {
  500.                                                   // Read in cchExtRst
  501.                                                   $extendedRunLength = $this->_GetInt4d($this->data, $spos);
  502.                                                   $spos += 4;
  503.                                                 }
  504.  
  505.                                                 $len = ($asciiEncoding)? $numChars : $numChars*2;
  506.                                                 if ($spos + $len < $limitpos) {
  507.                                                                 $retstr = substr($this->data, $spos, $len);
  508.                                                                 $spos += $len;
  509.                                                 }else{
  510.                                                         // found countinue
  511.                                                         $retstr = substr($this->data, $spos, $limitpos - $spos);
  512.                                                         $bytesRead = $limitpos - $spos;
  513.                                                         $charsLeft = $numChars - (($asciiEncoding) ? $bytesRead : ($bytesRead / 2));
  514.                                                         $spos = $limitpos;
  515.  
  516.                                                          while ($charsLeft > 0){
  517.                                                                 $opcode = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8;
  518.                                                                 $conlength = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8;
  519.                                                                         if ($opcode != 0x3c) {
  520.                                                                                 return -1;
  521.                                                                         }
  522.                                                                 $spos += 4;
  523.                                                                 $limitpos = $spos + $conlength;
  524.                                                                 $option = ord($this->data[$spos]);
  525.                                                                 $spos += 1;
  526.                                                                   if ($asciiEncoding && ($option == 0)) {
  527.                                                                                 $len = min($charsLeft, $limitpos - $spos); // min($charsLeft, $conlength);
  528.                                                                     $retstr .= substr($this->data, $spos, $len);
  529.                                                                     $charsLeft -= $len;
  530.                                                                     $asciiEncoding = true;
  531.                                                                   }elseif (!$asciiEncoding && ($option != 0)){
  532.                                                                                 $len = min($charsLeft * 2, $limitpos - $spos); // min($charsLeft, $conlength);
  533.                                                                     $retstr .= substr($this->data, $spos, $len);
  534.                                                                     $charsLeft -= $len/2;
  535.                                                                     $asciiEncoding = false;
  536.                                                                   }elseif (!$asciiEncoding && ($option == 0)) {
  537.                                                                 // Bummer - the string starts off as Unicode, but after the
  538.                                                                 // continuation it is in straightforward ASCII encoding
  539.                                                                                 $len = min($charsLeft, $limitpos - $spos); // min($charsLeft, $conlength);
  540.                                                                         for ($j = 0; $j < $len; $j++) {
  541.                                                                  $retstr .= $this->data[$spos + $j].chr(0);
  542.                                                                 }
  543.                                                             $charsLeft -= $len;
  544.                                                                 $asciiEncoding = false;
  545.                                                                   }else{
  546.                                                             $newstr = '';
  547.                                                                     for ($j = 0; $j < strlen($retstr); $j++) {
  548.                                                                       $newstr = $retstr[$j].chr(0);
  549.                                                                     }
  550.                                                                     $retstr = $newstr;
  551.                                                                                 $len = min($charsLeft * 2, $limitpos - $spos); // min($charsLeft, $conlength);
  552.                                                                     $retstr .= substr($this->data, $spos, $len);
  553.                                                                     $charsLeft -= $len/2;
  554.                                                                     $asciiEncoding = false;
  555.                                                                         //echo "Izavrat\n";
  556.                                                                   }
  557.                                                           $spos += $len;
  558.  
  559.                                                          }
  560.                                                 }
  561.                                                 $retstr = ($asciiEncoding) ? $retstr : $this->_encodeUTF16($retstr);
  562. //                                              echo "Str $i = $retstr\n";
  563.                                         if ($richString){
  564.                                                   $spos += 4 * $formattingRuns;
  565.                                                 }
  566.  
  567.                                                 // For extended strings, skip over the extended string data
  568.                                                 if ($extendedString) {
  569.                                                   $spos += $extendedRunLength;
  570.                                                 }
  571.                                                         //if ($retstr == 'Derby'){
  572.                                                         //      echo "bb\n";
  573.                                                         //}
  574.                                                 $this->sst[]=$retstr;
  575.                                        }
  576.                     /*$continueRecords = array();
  577.                     while ($this->getNextCode() == Type_CONTINUE) {
  578.                         $continueRecords[] = &$this->nextRecord();
  579.                     }
  580.                     //echo " 1 Type_SST\n";
  581.                     $this->shareStrings = new SSTRecord($r, $continueRecords);
  582.                     //print_r($this->shareStrings->strings);
  583.                      */
  584.                      // echo 'SST read: '.($time_end-$time_start)."\n";
  585.                     break;
  586.  
  587.                 case SPREADSHEET_EXCEL_READER_TYPE_FILEPASS:
  588.                     return false;
  589.                     break;
  590.                 case SPREADSHEET_EXCEL_READER_TYPE_NAME:
  591.                     //echo "Type_NAME\n";
  592.                     break;
  593.                 case SPREADSHEET_EXCEL_READER_TYPE_FORMAT:
  594.                         $indexCode = ord($this->data[$pos+4]) | ord($this->data[$pos+5]) << 8;
  595.  
  596.                         if ($version == SPREADSHEET_EXCEL_READER_BIFF8) {
  597.                             $numchars = ord($this->data[$pos+6]) | ord($this->data[$pos+7]) << 8;
  598.                             if (ord($this->data[$pos+8]) == 0){
  599.                                 $formatString = substr($this->data, $pos+9, $numchars);
  600.                             } else {
  601.                                 $formatString = substr($this->data, $pos+9, $numchars*2);
  602.                             }
  603.                         } else {
  604.                             $numchars = ord($this->data[$pos+6]);
  605.                             $formatString = substr($this->data, $pos+7, $numchars*2);
  606.                         }
  607.  
  608.                     $this->formatRecords[$indexCode] = $formatString;
  609.                    // echo "Type.FORMAT\n";
  610.                     break;
  611.                 case SPREADSHEET_EXCEL_READER_TYPE_XF:
  612.                         //global $dateFormats, $numberFormats;
  613.                         $indexCode = ord($this->data[$pos+6]) | ord($this->data[$pos+7]) << 8;
  614.                         //echo "\nType.XF ".count($this->formatRecords['xfrecords'])." $indexCode ";
  615.                         if (array_key_exists($indexCode, $this->dateFormats)) {
  616.                             //echo "isdate ".$dateFormats[$indexCode];
  617.                             $this->formatRecords['xfrecords'][] = array(
  618.                                     'type' => 'date',
  619.                                     'format' => $this->dateFormats[$indexCode]
  620.                                     );
  621.                         }elseif (array_key_exists($indexCode, $this->numberFormats)) {
  622.                         //echo "isnumber ".$this->numberFormats[$indexCode];
  623.                             $this->formatRecords['xfrecords'][] = array(
  624.                                     'type' => 'number',
  625.                                     'format' => $this->numberFormats[$indexCode]
  626.                                     );
  627.                         }else{
  628.                             $isdate = FALSE;
  629.                             if ($indexCode > 0){
  630.                                 if (isset($this->formatRecords[$indexCode]))
  631.                                     $formatstr = $this->formatRecords[$indexCode];
  632.                                 //echo '.other.';
  633.                                 //echo "\ndate-time=$formatstr=\n";
  634.                                 if ($formatstr)
  635.                                 if (preg_match("/[^hmsday\/\-:\s]/i", $formatstr) == 0) { // found day and time format
  636.                                     $isdate = TRUE;
  637.                                     $formatstr = str_replace('mm', 'i', $formatstr);
  638.                                     $formatstr = str_replace('h', 'H', $formatstr);
  639.                                     //echo "\ndate-time $formatstr \n";
  640.                                 }
  641.                             }
  642.  
  643.                             if ($isdate){
  644.                                 $this->formatRecords['xfrecords'][] = array(
  645.                                         'type' => 'date',
  646.                                         'format' => $formatstr,
  647.                                         );
  648.                             }else{
  649.                                 $this->formatRecords['xfrecords'][] = array(
  650.                                         'type' => 'other',
  651.                                         'format' => '',
  652.                                         'code' => $indexCode
  653.                                         );
  654.                             }
  655.                         }
  656.                         //echo "\n";
  657.                     break;
  658.                 case SPREADSHEET_EXCEL_READER_TYPE_NINETEENFOUR:
  659.                     //echo "Type.NINETEENFOUR\n";
  660.                     $this->nineteenFour = (ord($this->data[$pos+4]) == 1);
  661.                     break;
  662.                 case SPREADSHEET_EXCEL_READER_TYPE_BOUNDSHEET:
  663.                     //echo "Type.BOUNDSHEET\n";
  664.                         $rec_offset = $this->_GetInt4d($this->data, $pos+4);
  665.                         $rec_typeFlag = ord($this->data[$pos+8]);
  666.                         $rec_visibilityFlag = ord($this->data[$pos+9]);
  667.                         $rec_length = ord($this->data[$pos+10]);
  668.  
  669.                         if ($version == SPREADSHEET_EXCEL_READER_BIFF8){
  670.                             $chartype =  ord($this->data[$pos+11]);
  671.                             if ($chartype == 0){
  672.                                 $rec_name    = substr($this->data, $pos+12, $rec_length);
  673.                             } else {
  674.                                 $rec_name    = $this->_encodeUTF16(substr($this->data, $pos+12, $rec_length*2));
  675.                             }
  676.                         }elseif ($version == SPREADSHEET_EXCEL_READER_BIFF7){
  677.                                 $rec_name    = substr($this->data, $pos+11, $rec_length);
  678.                         }
  679.                     $this->boundsheets[] = array('name'=>$rec_name,
  680.                                                  'offset'=>$rec_offset);
  681.  
  682.                     break;
  683.  
  684.             }
  685.  
  686.             //echo "Code = ".base_convert($r['code'],10,16)."\n";
  687.             $pos += $length + 4;
  688.             $code = ord($this->data[$pos]) | ord($this->data[$pos+1])<<8;
  689.             $length = ord($this->data[$pos+2]) | ord($this->data[$pos+3])<<8;
  690.  
  691.             //$r = &$this->nextRecord();
  692.             //echo "1 Code = ".base_convert($r['code'],10,16)."\n";
  693.         }
  694.  
  695.         foreach ($this->boundsheets as $key=>$val){
  696.             $this->sn = $key;
  697.             $this->_parsesheet($val['offset']);
  698.         }
  699.         return true;
  700.  
  701.     }
  702.  
  703.     /**
  704.      * Parse a worksheet
  705.      *
  706.      * @access private
  707.      * @param todo
  708.      * @todo fix return codes
  709.      */
  710.     function _parsesheet($spos)
  711.     {
  712.         $cont = true;
  713.         // read BOF
  714.         $code = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8;
  715.         $length = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8;
  716.  
  717.         $version = ord($this->data[$spos + 4]) | ord($this->data[$spos + 5])<<8;
  718.         $substreamType = ord($this->data[$spos + 6]) | ord($this->data[$spos + 7])<<8;
  719.  
  720.         if (($version != SPREADSHEET_EXCEL_READER_BIFF8) && ($version != SPREADSHEET_EXCEL_READER_BIFF7)) {
  721.             return -1;
  722.         }
  723.  
  724.         if ($substreamType != SPREADSHEET_EXCEL_READER_WORKSHEET){
  725.             return -2;
  726.         }
  727.         //echo "Start parse code=".base_convert($code,10,16)." version=".base_convert($version,10,16)." substreamType=".base_convert($substreamType,10,16).""."\n";
  728.         $spos += $length + 4;
  729.         //var_dump($this->formatRecords);
  730.     //echo "code $code $length";
  731.         while($cont) {
  732.             //echo "mem= ".memory_get_usage()."\n";
  733. //            $r = &$this->file->nextRecord();
  734.             $lowcode = ord($this->data[$spos]);
  735.             if ($lowcode == SPREADSHEET_EXCEL_READER_TYPE_EOF) break;
  736.             $code = $lowcode | ord($this->data[$spos+1])<<8;
  737.             $length = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8;
  738.             $spos += 4;
  739.             $this->sheets[$this->sn]['maxrow'] = $this->_rowoffset - 1;
  740.             $this->sheets[$this->sn]['maxcol'] = $this->_coloffset - 1;
  741.             //echo "Code=".base_convert($code,10,16)." $code\n";
  742.             unset($this->rectype);
  743.             $this->multiplier = 1; // need for format with %
  744.             switch ($code) {
  745.                 case SPREADSHEET_EXCEL_READER_TYPE_DIMENSION:
  746.                     //echo 'Type_DIMENSION ';
  747.                     if (!isset($this->numRows)) {
  748.                         if (($length == 10) ||  ($version == SPREADSHEET_EXCEL_READER_BIFF7)){
  749.                             $this->sheets[$this->sn]['numRows'] = ord($this->data[$spos+2]) | ord($this->data[$spos+3]) << 8;
  750.                             $this->sheets[$this->sn]['numCols'] = ord($this->data[$spos+6]) | ord($this->data[$spos+7]) << 8;
  751.                         } else {
  752.                             $this->sheets[$this->sn]['numRows'] = ord($this->data[$spos+4]) | ord($this->data[$spos+5]) << 8;
  753.                             $this->sheets[$this->sn]['numCols'] = ord($this->data[$spos+10]) | ord($this->data[$spos+11]) << 8;
  754.                         }
  755.                     }
  756.                     //echo 'numRows '.$this->numRows.' '.$this->numCols."\n";
  757.                     break;
  758.                 case SPREADSHEET_EXCEL_READER_TYPE_MERGEDCELLS:
  759.                     $cellRanges = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8;
  760.                     for ($i = 0; $i < $cellRanges; $i++) {
  761.                         $fr =  ord($this->data[$spos + 8*$i + 2]) | ord($this->data[$spos + 8*$i + 3])<<8;
  762.                         $lr =  ord($this->data[$spos + 8*$i + 4]) | ord($this->data[$spos + 8*$i + 5])<<8;
  763.                         $fc =  ord($this->data[$spos + 8*$i + 6]) | ord($this->data[$spos + 8*$i + 7])<<8;
  764.                         $lc =  ord($this->data[$spos + 8*$i + 8]) | ord($this->data[$spos + 8*$i + 9])<<8;
  765.                         //$this->sheets[$this->sn]['mergedCells'][] = array($fr + 1, $fc + 1, $lr + 1, $lc + 1);
  766.                         if ($lr - $fr > 0) {
  767.                             $this->sheets[$this->sn]['cellsInfo'][$fr+1][$fc+1]['rowspan'] = $lr - $fr + 1;
  768.                         }
  769.                         if ($lc - $fc > 0) {
  770.                             $this->sheets[$this->sn]['cellsInfo'][$fr+1][$fc+1]['colspan'] = $lc - $fc + 1;
  771.                         }
  772.                     }
  773.                     //echo "Merged Cells $cellRanges $lr $fr $lc $fc\n";
  774.                     break;
  775.                 case SPREADSHEET_EXCEL_READER_TYPE_RK:
  776.                 case SPREADSHEET_EXCEL_READER_TYPE_RK2:
  777.                     //echo 'SPREADSHEET_EXCEL_READER_TYPE_RK'."\n";
  778.                     $row = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8;
  779.                     $column = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8;
  780.                     $rknum = $this->_GetInt4d($this->data, $spos + 6);
  781.                     $numValue = $this->_GetIEEE754($rknum);
  782.                     //echo $numValue." ";
  783.                     if ($this->isDate($spos)) {
  784.                         list($string, $raw) = $this->createDate($numValue);
  785.                     }else{
  786.                         $raw = $numValue;
  787.                         if (isset($this->_columnsFormat[$column + 1])){
  788.                                 $this->curformat = $this->_columnsFormat[$column + 1];
  789.                         }
  790.                         $string = sprintf($this->curformat, $numValue * $this->multiplier);
  791.                         //$this->addcell(RKRecord($r));
  792.                     }
  793.                     $this->addcell($row, $column, $string, $raw);
  794.                     //echo "Type_RK $row $column $string $raw {$this->curformat}\n";
  795.                     break;
  796.                 case SPREADSHEET_EXCEL_READER_TYPE_LABELSST:
  797.                         $row        = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8;
  798.                         $column     = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8;
  799.                         $xfindex    = ord($this->data[$spos+4]) | ord($this->data[$spos+5])<<8;
  800.                         $index  = $this->_GetInt4d($this->data, $spos + 6);
  801.             //var_dump($this->sst);
  802.                         $this->addcell($row, $column, $this->sst[$index]);
  803.                         //echo "LabelSST $row $column $string\n";
  804.                     break;
  805.                 case SPREADSHEET_EXCEL_READER_TYPE_MULRK:
  806.                     $row        = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8;
  807.                     $colFirst   = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8;
  808.                     $colLast    = ord($this->data[$spos + $length - 2]) | ord($this->data[$spos + $length - 1])<<8;
  809.                     $columns    = $colLast - $colFirst + 1;
  810.                     $tmppos = $spos+4;
  811.                     for ($i = 0; $i < $columns; $i++) {
  812.                         $numValue = $this->_GetIEEE754($this->_GetInt4d($this->data, $tmppos + 2));
  813.                         if ($this->isDate($tmppos-4)) {
  814.                             list($string, $raw) = $this->createDate($numValue);
  815.                         }else{
  816.                             $raw = $numValue;
  817.                             if (isset($this->_columnsFormat[$colFirst + $i + 1])){
  818.                                         $this->curformat = $this->_columnsFormat[$colFirst + $i + 1];
  819.                                 }
  820.                             $string = sprintf($this->curformat, $numValue * $this->multiplier);
  821.                         }
  822.                       //$rec['rknumbers'][$i]['xfindex'] = ord($rec['data'][$pos]) | ord($rec['data'][$pos+1]) << 8;
  823.                       $tmppos += 6;
  824.                       $this->addcell($row, $colFirst + $i, $string, $raw);
  825.                       //echo "MULRK $row ".($colFirst + $i)." $string\n";
  826.                     }
  827.                      //MulRKRecord($r);
  828.                     // Get the individual cell records from the multiple record
  829.                      //$num = ;
  830.  
  831.                     break;
  832.                 case SPREADSHEET_EXCEL_READER_TYPE_NUMBER:
  833.                     $row    = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8;
  834.                     $column = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8;
  835.                     $tmp = unpack("ddouble", substr($this->data, $spos + 6, 8)); // It machine machine dependent
  836.                     if ($this->isDate($spos)) {
  837.                         list($string, $raw) = $this->createDate($tmp['double']);
  838.                      //   $this->addcell(DateRecord($r, 1));
  839.                     }else{
  840.                         //$raw = $tmp[''];
  841.                         if (isset($this->_columnsFormat[$column + 1])){
  842.                                 $this->curformat = $this->_columnsFormat[$column + 1];
  843.                         }
  844.                         $raw = $this->createNumber($spos);
  845.                         $string = sprintf($this->curformat, $raw * $this->multiplier);
  846.  
  847.                      //   $this->addcell(NumberRecord($r));
  848.                     }
  849.                     $this->addcell($row, $column, $string, $raw);
  850.                     //echo "Number $row $column $string\n";
  851.                     break;
  852.                 case SPREADSHEET_EXCEL_READER_TYPE_FORMULA:
  853.                 case SPREADSHEET_EXCEL_READER_TYPE_FORMULA2:
  854.                     $row    = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8;
  855.                     $column = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8;
  856.                     if ((ord($this->data[$spos+6])==0) && (ord($this->data[$spos+12])==255) && (ord($this->data[$spos+13])==255)) {
  857.                         //String formula. Result follows in a STRING record
  858.                         //echo "FORMULA $row $column Formula with a string<br>\n";
  859.                     } elseif ((ord($this->data[$spos+6])==1) && (ord($this->data[$spos+12])==255) && (ord($this->data[$spos+13])==255)) {
  860.                         //Boolean formula. Result is in +2; 0=false,1=true
  861.                     } elseif ((ord($this->data[$spos+6])==2) && (ord($this->data[$spos+12])==255) && (ord($this->data[$spos+13])==255)) {
  862.                         //Error formula. Error code is in +2;
  863.                     } elseif ((ord($this->data[$spos+6])==3) && (ord($this->data[$spos+12])==255) && (ord($this->data[$spos+13])==255)) {
  864.                         //Formula result is a null string.
  865.                     } else {
  866.                         // result is a number, so first 14 bytes are just like a _NUMBER record
  867.                         $tmp = unpack("ddouble", substr($this->data, $spos + 6, 8)); // It machine machine dependent
  868.                         if ($this->isDate($spos)) {
  869.                             list($string, $raw) = $this->createDate($tmp['double']);
  870.                          //   $this->addcell(DateRecord($r, 1));
  871.                         }else{
  872.                             //$raw = $tmp[''];
  873.                             if (isset($this->_columnsFormat[$column + 1])){
  874.                                     $this->curformat = $this->_columnsFormat[$column + 1];
  875.                             }
  876.                             $raw = $this->createNumber($spos);
  877.                             $string = sprintf($this->curformat, $raw * $this->multiplier);
  878.  
  879.                          //   $this->addcell(NumberRecord($r));
  880.                         }
  881.                         $this->addcell($row, $column, $string, $raw);
  882.                         //echo "Number $row $column $string\n";
  883.                     }
  884.                     break;
  885.                 case SPREADSHEET_EXCEL_READER_TYPE_BOOLERR:
  886.                     $row    = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8;
  887.                     $column = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8;
  888.                     $string = ord($this->data[$spos+6]);
  889.                     $this->addcell($row, $column, $string);
  890.                     //echo 'Type_BOOLERR '."\n";
  891.                     break;
  892.                 case SPREADSHEET_EXCEL_READER_TYPE_ROW:
  893.                 case SPREADSHEET_EXCEL_READER_TYPE_DBCELL:
  894.                 case SPREADSHEET_EXCEL_READER_TYPE_MULBLANK:
  895.                     break;
  896.                 case SPREADSHEET_EXCEL_READER_TYPE_LABEL:
  897.                     $row    = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8;
  898.                     $column = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8;
  899.                     $this->addcell($row, $column, substr($this->data, $spos + 8, ord($this->data[$spos + 6]) | ord($this->data[$spos + 7])<<8));
  900.  
  901.                    // $this->addcell(LabelRecord($r));
  902.                     break;
  903.  
  904.                 case SPREADSHEET_EXCEL_READER_TYPE_EOF:
  905.                     $cont = false;
  906.                     break;
  907.                 default:
  908.                     //echo ' unknown :'.base_convert($r['code'],10,16)."\n";
  909.                     break;
  910.  
  911.             }
  912.             $spos += $length;
  913.         }
  914.  
  915.         if (!isset($this->sheets[$this->sn]['numRows']))
  916.              $this->sheets[$this->sn]['numRows'] = $this->sheets[$this->sn]['maxrow'];
  917.         if (!isset($this->sheets[$this->sn]['numCols']))
  918.              $this->sheets[$this->sn]['numCols'] = $this->sheets[$this->sn]['maxcol'];
  919.  
  920.     }
  921.  
  922.     /**
  923.      * Check whether the current record read is a date
  924.      *
  925.      * @param todo
  926.      * @return boolean True if date, false otherwise
  927.      */
  928.     function isDate($spos)
  929.     {
  930.         //$xfindex = GetInt2d(, 4);
  931.         $xfindex = ord($this->data[$spos+4]) | ord($this->data[$spos+5]) << 8;
  932.         //echo 'check is date '.$xfindex.' '.$this->formatRecords['xfrecords'][$xfindex]['type']."\n";
  933.         //var_dump($this->formatRecords['xfrecords'][$xfindex]);
  934.         if ($this->formatRecords['xfrecords'][$xfindex]['type'] == 'date') {
  935.             $this->curformat = $this->formatRecords['xfrecords'][$xfindex]['format'];
  936.             $this->rectype = 'date';
  937.             return true;
  938.         } else {
  939.             if ($this->formatRecords['xfrecords'][$xfindex]['type'] == 'number') {
  940.                 $this->curformat = $this->formatRecords['xfrecords'][$xfindex]['format'];
  941.                 $this->rectype = 'number';
  942.                 if (($xfindex == 0x9) || ($xfindex == 0xa)){
  943.                     $this->multiplier = 100;
  944.                 }
  945.             }else{
  946.                 $this->curformat = $this->_defaultFormat;
  947.                 $this->rectype = 'unknown';
  948.             }
  949.             return false;
  950.         }
  951.     }
  952.  
  953.     //}}}
  954.     //{{{ createDate()
  955.  
  956.     /**
  957.      * Convert the raw Excel date into a human readable format
  958.      *
  959.      * Dates in Excel are stored as number of seconds from an epoch.  On
  960.      * Windows, the epoch is 30/12/1899 and on Mac it's 01/01/1904
  961.      *
  962.      * @access private
  963.      * @param integer The raw Excel value to convert
  964.      * @return array First element is the converted date, the second element is number a unix timestamp
  965.      */
  966.     function createDate($numValue)
  967.     {
  968.         if ($numValue > 1) {
  969.             $utcDays = $numValue - ($this->nineteenFour ? SPREADSHEET_EXCEL_READER_UTCOFFSETDAYS1904 : SPREADSHEET_EXCEL_READER_UTCOFFSETDAYS);
  970.             $utcValue = round(($utcDays+1) * SPREADSHEET_EXCEL_READER_MSINADAY);
  971.             $string = date ($this->curformat, $utcValue);
  972.             $raw = $utcValue;
  973.         } else {
  974.             $raw = $numValue;
  975.             $hours = floor($numValue * 24);
  976.             $mins = floor($numValue * 24 * 60) - $hours * 60;
  977.             $secs = floor($numValue * SPREADSHEET_EXCEL_READER_MSINADAY) - $hours * 60 * 60 - $mins * 60;
  978.             $string = date ($this->curformat, mktime($hours, $mins, $secs));
  979.         }
  980.  
  981.         return array($string, $raw);
  982.     }
  983.  
  984.     function createNumber($spos)
  985.     {
  986.         $rknumhigh = $this->_GetInt4d($this->data, $spos + 10);
  987.         $rknumlow = $this->_GetInt4d($this->data, $spos + 6);
  988.         //for ($i=0; $i<8; $i++) { echo ord($this->data[$i+$spos+6]) . " "; } echo "<br>";
  989.         $sign = ($rknumhigh & 0x80000000) >> 31;
  990.         $exp =  ($rknumhigh & 0x7ff00000) >> 20;
  991.         $mantissa = (0x100000 | ($rknumhigh & 0x000fffff));
  992.         $mantissalow1 = ($rknumlow & 0x80000000) >> 31;
  993.         $mantissalow2 = ($rknumlow & 0x7fffffff);
  994.         $value = $mantissa / pow( 2 , (20- ($exp - 1023)));
  995.         if ($mantissalow1 != 0) $value += 1 / pow (2 , (21 - ($exp - 1023)));
  996.         $value += $mantissalow2 / pow (2 , (52 - ($exp - 1023)));
  997.         //echo "Sign = $sign, Exp = $exp, mantissahighx = $mantissa, mantissalow1 = $mantissalow1, mantissalow2 = $mantissalow2<br>\n";
  998.         if ($sign) {$value = -1 * $value;}
  999.         return  $value;
  1000.     }
  1001.  
  1002.     function addcell($row, $col, $string, $raw = '')
  1003.     {
  1004.         //echo "ADD cel $row-$col $string\n";
  1005.         $this->sheets[$this->sn]['maxrow'] = max($this->sheets[$this->sn]['maxrow'], $row + $this->_rowoffset);
  1006.         $this->sheets[$this->sn]['maxcol'] = max($this->sheets[$this->sn]['maxcol'], $col + $this->_coloffset);
  1007.         $this->sheets[$this->sn]['cells'][$row + $this->_rowoffset][$col + $this->_coloffset] = $string;
  1008.         if ($raw)
  1009.             $this->sheets[$this->sn]['cellsInfo'][$row + $this->_rowoffset][$col + $this->_coloffset]['raw'] = $raw;
  1010.         if (isset($this->rectype))
  1011.             $this->sheets[$this->sn]['cellsInfo'][$row + $this->_rowoffset][$col + $this->_coloffset]['type'] = $this->rectype;
  1012.  
  1013.     }
  1014.  
  1015.  
  1016.     function _GetIEEE754($rknum)
  1017.     {
  1018.         if (($rknum & 0x02) != 0) {
  1019.                 $value = $rknum >> 2;
  1020.         } else {
  1021. //mmp
  1022. // first comment out the previously existing 7 lines of code here
  1023. //                $tmp = unpack("d", pack("VV", 0, ($rknum & 0xfffffffc)));
  1024. //                //$value = $tmp[''];
  1025. //                if (array_key_exists(1, $tmp)) {
  1026. //                    $value = $tmp[1];
  1027. //                } else {
  1028. //                    $value = $tmp[''];
  1029. //                }
  1030. // I got my info on IEEE754 encoding from
  1031. // http://research.microsoft.com/~hollasch/cgindex/coding/ieeefloat.html
  1032. // The RK format calls for using only the most significant 30 bits of the
  1033. // 64 bit floating point value. The other 34 bits are assumed to be 0
  1034. // So, we use the upper 30 bits of $rknum as follows...
  1035.          $sign = ($rknum & 0x80000000) >> 31;
  1036.         $exp = ($rknum & 0x7ff00000) >> 20;
  1037.         $mantissa = (0x100000 | ($rknum & 0x000ffffc));
  1038.         $value = $mantissa / pow( 2 , (20- ($exp - 1023)));
  1039.         if ($sign) {$value = -1 * $value;}
  1040. //end of changes by mmp
  1041.  
  1042.         }
  1043.  
  1044.         if (($rknum & 0x01) != 0) {
  1045.             $value /= 100;
  1046.         }
  1047.         return $value;
  1048.     }
  1049.  
  1050.     function _encodeUTF16($string)
  1051.     {
  1052.         $result = $string;
  1053.         if ($this->_defaultEncoding){
  1054.             switch ($this->_encoderFunction){
  1055.                 case 'iconv' :     $result = iconv('UTF-16LE', $this->_defaultEncoding, $string);
  1056.                                 break;
  1057.                 case 'mb_convert_encoding' :     $result = mb_convert_encoding($string, $this->_defaultEncoding, 'UTF-16LE' );
  1058.                                 break;
  1059.             }
  1060.         }
  1061.         return $result;
  1062.     }
  1063.  
  1064.     function _GetInt4d($data, $pos)
  1065.     {
  1066.         $value = ord($data[$pos]) | (ord($data[$pos+1]) << 8) | (ord($data[$pos+2]) << 16) | (ord($data[$pos+3]) << 24);
  1067.         if ($value>=4294967294)
  1068.         {
  1069.             $value=-2;
  1070.         }
  1071.         return $value;
  1072.     }
  1073.  
  1074. }
  1075.  
  1076. /*
  1077.  * Local variables:
  1078.  * tab-width: 4
  1079.  * c-basic-offset: 4
  1080.  * c-hanging-comment-ender-p: nil
  1081.  * End:
  1082.  */
  1083.  
  1084. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement