心理咨询网
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

excelreader.php 45KB

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