PageRenderTime 59ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/Data/SimpleXLSX.php

https://bitbucket.org/spidgorny/nadlib
PHP | 687 lines | 477 code | 101 blank | 109 comment | 108 complexity | 615091a760fc526f4f854f4a09d62c6a MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /*
  3. SimpleXLSX php class v0.6.8
  4. MS Excel 2007 workbooks reader
  5. Example 1:
  6. $xlsx = new SimpleXLSX('book.xlsx');
  7. print_r( $xlsx->rows() );
  8. Example 2:
  9. $xlsx = new SimpleXLSX('book.xlsx');
  10. print_r( $xlsx->rowsEx() );
  11. Example 3:
  12. $xlsx = new SimpleXLSX('book.xlsx');
  13. print_r( $xlsx->rows(2) ); // second worksheet
  14. Example 4.1:
  15. $xlsx = new SimpleXLSX('book.xlsx');
  16. print_r( $xlsx->sheetNames() ); // array( 1 => 'Sheet 1', 3 => 'Catalog' );
  17. Example 4.2:
  18. $xlsx = new SimpleXLSX('book.xlsx');
  19. echo 'Sheet Name 2 = '.$xlsx->sheetName(2);
  20. Example 5:
  21. $xlsx = new SimpleXLSX('book.xlsx');
  22. if ($xslx->success())
  23. print_r( $xlsx->rows() );
  24. else
  25. echo 'xlsx error: '.$xslx->error();
  26. Example 6:
  27. $xslx = new SimpleXLSX( file_get_contents('http://www.example.com/example.xlsx'), true);
  28. list($num_cols, $num_rows) = $xlsx->dimension(2);
  29. echo $xlsx->sheetName(2).':'.$num_cols.'x'.$num_rows;
  30. v0.6.8 (2013-10-13) fixed dimension() where 1 row only, fixed rowsEx() empty cells indexes (Daniel Stastka)
  31. v0.6.7 (2013-08-10) fixed unzip (mac), added $debug param to _constructor to display errors
  32. v0.6.6 (2013-06-03) +entryExists(),
  33. v0.6.5 (2013-03-18) fixed sheetName()
  34. v0.6.4 (2013-03-13) rowsEx(), _parse(): fixed date column type & format detection
  35. v0.6.3 (2013-03-13) rowsEx(): fixed formulas, added date type 'd', added format 'format'
  36. dimension(): fixed empty sheet dimension
  37. + sheetNames() - returns array( sheet_id => sheet_name, sheet_id2 => sheet_name2 ...)
  38. v0.6.2 (2012-10-04) fixed empty cells, rowsEx() returns type and formulas now
  39. v0.6.1 (2012-09-14) removed "raise exception" and fixed _unzip
  40. v0.6 (2012-09-13) success(), error(), __constructor( $filename, $is_data = false )
  41. v0.5.1 (2012-09-13) sheetName() fixed
  42. v0.5 (2012-09-12) sheetName()
  43. v0.4 sheets(), sheetsCount(), unixstamp( $excelDateTime )
  44. v0.3 - fixed empty cells (Gonzo patch)
  45. */
  46. class SimpleXLSX {
  47. // Don't remove this string! Created by Sergey Schuchkin from http://www.sibvision.ru - professional php developers team 2010-2013
  48. private $workbook;
  49. private $sheets;
  50. private $styles;
  51. private $hyperlinks;
  52. private $package = array(
  53. 'filename' => '',
  54. 'mtime' => 0,
  55. 'size' => 0,
  56. 'comment' => '',
  57. 'entries' => array()
  58. );
  59. private $sharedstrings;
  60. private $error = false;
  61. private $debug = false;
  62. // scheme
  63. const SCHEMA_REL_OFFICEDOCUMENT = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument';
  64. const SCHEMA_REL_SHAREDSTRINGS = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings';
  65. const SCHEMA_REL_WORKSHEET = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet';
  66. const SCHEMA_REL_STYLES = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles';
  67. private $workbook_cell_formats = array();
  68. private $built_in_cell_formats = array(
  69. 0 => 'General',
  70. 1 => '0',
  71. 2 => '0.00',
  72. 3 => '#,##0',
  73. 4 => '#,##0.00',
  74. 9 => '0%',
  75. 10 => '0.00%',
  76. 11 => '0.00E+00',
  77. 12 => '# ?/?',
  78. 13 => '# ??/??',
  79. 14 => 'mm-dd-yy',
  80. 15 => 'd-mmm-yy',
  81. 16 => 'd-mmm',
  82. 17 => 'mmm-yy',
  83. 18 => 'h:mm AM/PM',
  84. 19 => 'h:mm:ss AM/PM',
  85. 20 => 'h:mm',
  86. 21 => 'h:mm:ss',
  87. 22 => 'm/d/yy h:mm',
  88. 37 => '#,##0 ;(#,##0)',
  89. 38 => '#,##0 ;[Red](#,##0)',
  90. 39 => '#,##0.00;(#,##0.00)',
  91. 40 => '#,##0.00;[Red](#,##0.00)',
  92. 44 => '_("$"* #,##0.00_);_("$"* \(#,##0.00\);_("$"* "-"??_);_(@_)',
  93. 45 => 'mm:ss',
  94. 46 => '[h]:mm:ss',
  95. 47 => 'mmss.0',
  96. 48 => '##0.0E+0',
  97. 49 => '@',
  98. 27 => '[$-404]e/m/d',
  99. 30 => 'm/d/yy',
  100. 36 => '[$-404]e/m/d',
  101. 50 => '[$-404]e/m/d',
  102. 57 => '[$-404]e/m/d',
  103. 59 => 't0',
  104. 60 => 't0.00',
  105. 61 => 't#,##0',
  106. 62 => 't#,##0.00',
  107. 67 => 't0%',
  108. 68 => 't0.00%',
  109. 69 => 't# ?/?',
  110. 70 => 't# ??/??',
  111. );
  112. function __construct( $filename, $is_data = false, $debug = false ) {
  113. $this->debug = $debug;
  114. $this->_unzip( $filename, $is_data );
  115. $this->_parse();
  116. }
  117. function sheets() {
  118. return $this->sheets;
  119. }
  120. function sheetsCount() {
  121. return count($this->sheets);
  122. }
  123. function sheetName( $worksheet_id) {
  124. foreach( $this->workbook->sheets->sheet as $s ) {
  125. if ( $s->attributes('r',true)->id == 'rId'.$worksheet_id)
  126. return (string) $s['name'];
  127. }
  128. return false;
  129. }
  130. function sheetNames() {
  131. $result = array();
  132. foreach( $this->workbook->sheets->sheet as $s ) {
  133. $result[ substr( $s->attributes('r',true)->id, 3) ] = (string) $s['name'];
  134. }
  135. return $result;
  136. }
  137. function worksheet( $worksheet_id ) {
  138. if ( isset( $this->sheets[ $worksheet_id ] ) ) {
  139. $ws = $this->sheets[ $worksheet_id ];
  140. if (isset($ws->hyperlinks)) {
  141. $this->hyperlinks = array();
  142. foreach( $ws->hyperlinks->hyperlink as $hyperlink ) {
  143. $this->hyperlinks[ (string) $hyperlink['ref'] ] = (string) $hyperlink['display'];
  144. }
  145. }
  146. return $ws;
  147. } else {
  148. $this->error( 'Worksheet '.$worksheet_id.' not found. Try $xlsx->rows('.implode(') or $xlsx->rows(', array_keys($this->sheets)).')' );
  149. return false;
  150. }
  151. }
  152. function dimension( $worksheet_id = 1 ) {
  153. if (($ws = $this->worksheet( $worksheet_id)) === false)
  154. return false;
  155. $ref = (string) $ws->dimension['ref'];
  156. if( strpos( $ref, ':') !== false ) {
  157. $d = explode(':', $ref);
  158. if(!isset($d[1]))
  159. return array(0,0);
  160. $index = $this->_columnIndex( $d[1] );
  161. return array( $index[0]+1, $index[1]+1);
  162. } else if ( strlen( $ref ) ) { // 0.6.8
  163. $index = $this->_columnIndex( $ref );
  164. return array( $index[0]+1, $index[1]+1);
  165. } else
  166. return array(0,0);
  167. }
  168. // sheets numeration: 1,2,3....
  169. function rows( $worksheet_id = 1 ) {
  170. if (($ws = $this->worksheet( $worksheet_id)) === false)
  171. return false;
  172. $rows = array();
  173. $curR = 0;
  174. list($cols,) = $this->dimension( $worksheet_id );
  175. foreach ($ws->sheetData->row as $row) {
  176. // echo 'row<br />';
  177. foreach ($row->c as $c) {
  178. list($curC,) = $this->_columnIndex((string) $c['r']);
  179. $rows[ $curR ][ $curC ] = $this->value($c);
  180. }
  181. for ($i = 0; $i < $cols; $i++)
  182. if (!isset($rows[$curR][$i]))
  183. $rows[ $curR ][ $i ] = '';
  184. ksort( $rows[ $curR ] );
  185. $curR++;
  186. }
  187. return $rows;
  188. }
  189. function rowsEx( $worksheet_id = 1 ) {
  190. if (($ws = $this->worksheet( $worksheet_id)) === false)
  191. return false;
  192. $rows = array();
  193. $curR = 0;
  194. list($cols,) = $this->dimension( $worksheet_id );
  195. foreach ($ws->sheetData->row as $row) {
  196. foreach ($row->c as $c) {
  197. list($curC,) = $this->_columnIndex((string) $c['r']);
  198. $t = (string)$c['t'];
  199. $s = (int)$c['s'];
  200. if ($s > 0 && isset($this->workbook_cell_formats[ $s ])) {
  201. $format = $this->workbook_cell_formats[ $s ]['format'];
  202. if ( strpos($format,'m') !== false )
  203. $t = 'd';
  204. } else
  205. $format = '';
  206. $rows[ $curR ][ $curC ] = array(
  207. 'type' => $t,
  208. 'name' => (string) $c['r'],
  209. 'value' => $this->value($c),
  210. 'href' => $this->href( $c ),
  211. 'f' => (string) $c->f,
  212. 'format' => $format
  213. );
  214. }
  215. for ($i = 0; $i < $cols; $i++) {
  216. if ( !isset($rows[$curR][$i]) ) {
  217. // 0.6.8
  218. for ($c = '', $j = $i; $j >= 0; $j = intval($j / 26) - 1)
  219. $c = chr( $j % 26 + 65 ) . $c;
  220. $rows[ $curR ][$i] = array(
  221. 'type' => '',
  222. // 'name' => chr($i + 65).($curR+1),
  223. 'name' => $c.($curR+1),
  224. 'value' => '',
  225. 'href' => '',
  226. 'f' => '',
  227. 'format' => ''
  228. );
  229. }
  230. }
  231. ksort( $rows[ $curR ] );
  232. $curR++;
  233. }
  234. return $rows;
  235. }
  236. // thx Gonzo
  237. private function _columnIndex( $cell = 'A1' ) {
  238. if (preg_match("/([A-Z]+)(\d+)/", $cell, $matches)) {
  239. $col = $matches[1];
  240. $row = $matches[2];
  241. $colLen = strlen($col);
  242. $index = 0;
  243. for ($i = $colLen-1; $i >= 0; $i--)
  244. $index += (ord($col{$i}) - 64) * pow(26, $colLen-$i-1);
  245. return array($index-1, $row-1);
  246. } else
  247. throw new Exception("Invalid cell index.");
  248. }
  249. function value( $cell ) {
  250. // Determine data type
  251. $dataType = (string) $cell['t'];
  252. switch ($dataType) {
  253. case "s":
  254. // Value is a shared string
  255. if ((string)$cell->v != '') {
  256. $value = $this->sharedstrings[intval($cell->v)];
  257. } else {
  258. $value = '';
  259. }
  260. break;
  261. case "b":
  262. // Value is boolean
  263. $value = (string)$cell->v;
  264. if ($value == '0') {
  265. $value = false;
  266. } else if ($value == '1') {
  267. $value = true;
  268. } else {
  269. $value = (bool)$cell->v;
  270. }
  271. break;
  272. case "inlineStr":
  273. // Value is rich text inline
  274. $value = $this->_parseRichText($cell->is);
  275. break;
  276. case "e":
  277. // Value is an error message
  278. if ((string)$cell->v != '') {
  279. $value = (string)$cell->v;
  280. } else {
  281. $value = '';
  282. }
  283. break;
  284. default:
  285. // Value is a string
  286. $value = (string)$cell->v;
  287. // Check for numeric values
  288. if (is_numeric($value) && $dataType != 's') {
  289. if ($value == (int)$value) $value = (int)$value;
  290. elseif ($value == (float)$value) $value = (float)$value;
  291. }
  292. }
  293. return $value;
  294. }
  295. function href( $cell ) {
  296. return isset( $this->hyperlinks[ (string) $cell['r'] ] ) ? $this->hyperlinks[ (string) $cell['r'] ] : '';
  297. }
  298. function styles() {
  299. return $this->styles;
  300. }
  301. function _unzip( $filename, $is_data = false ) {
  302. // Clear current file
  303. $this->datasec = array();
  304. if ($is_data) {
  305. $this->package['filename'] = 'default.xlsx';
  306. $this->package['mtime'] = time();
  307. $this->package['size'] = strlen( $filename );
  308. $vZ = $filename;
  309. } else {
  310. if (!is_readable($filename)) {
  311. $this->error( 'File not found' );
  312. return false;
  313. }
  314. // Package information
  315. $this->package['filename'] = $filename;
  316. $this->package['mtime'] = filemtime( $filename );
  317. $this->package['size'] = filesize( $filename );
  318. // Read file
  319. $oF = fopen($filename, 'rb');
  320. $vZ = fread($oF, $this->package['size']);
  321. fclose($oF);
  322. }
  323. // Cut end of central directory
  324. /* $aE = explode("\x50\x4b\x05\x06", $vZ);
  325. if (count($aE) == 1) {
  326. $this->error('Unknown format');
  327. return false;
  328. }
  329. */
  330. if ( ($pcd = strrpos( $vZ, "\x50\x4b\x05\x06" )) === false ) {
  331. $this->error('Unknown format');
  332. return false;
  333. }
  334. $aE = array(
  335. 0 => substr( $vZ, 0, $pcd ),
  336. 1 => substr( $vZ, $pcd + 3 )
  337. );
  338. // Normal way
  339. $aP = unpack('x16/v1CL', $aE[1]);
  340. $this->package['comment'] = substr($aE[1], 18, $aP['CL']);
  341. // Translates end of line from other operating systems
  342. $this->package['comment'] = strtr($this->package['comment'], array("\r\n" => "\n", "\r" => "\n"));
  343. // Cut the entries from the central directory
  344. $aE = explode("\x50\x4b\x01\x02", $vZ);
  345. // Explode to each part
  346. $aE = explode("\x50\x4b\x03\x04", $aE[0]);
  347. // Shift out spanning signature or empty entry
  348. array_shift($aE);
  349. // Loop through the entries
  350. foreach ($aE as $vZ) {
  351. $aI = array();
  352. $aI['E'] = 0;
  353. $aI['EM'] = '';
  354. // Retrieving local file header information
  355. // $aP = unpack('v1VN/v1GPF/v1CM/v1FT/v1FD/V1CRC/V1CS/V1UCS/v1FNL', $vZ);
  356. $aP = unpack('v1VN/v1GPF/v1CM/v1FT/v1FD/V1CRC/V1CS/V1UCS/v1FNL/v1EFL', $vZ);
  357. // Check if data is encrypted
  358. // $bE = ($aP['GPF'] && 0x0001) ? TRUE : FALSE;
  359. $bE = false;
  360. $nF = $aP['FNL'];
  361. $mF = $aP['EFL'];
  362. // Special case : value block after the compressed data
  363. if ($aP['GPF'] & 0x0008) {
  364. $aP1 = unpack('V1CRC/V1CS/V1UCS', substr($vZ, -12));
  365. $aP['CRC'] = $aP1['CRC'];
  366. $aP['CS'] = $aP1['CS'];
  367. $aP['UCS'] = $aP1['UCS'];
  368. // 2013-08-10
  369. $vZ = substr($vZ, 0, -12);
  370. if (substr($vZ,-4) === "\x50\x4b\x07\x08")
  371. $vZ = substr($vZ, 0, -4);
  372. }
  373. // Getting stored filename
  374. $aI['N'] = substr($vZ, 26, $nF);
  375. if (substr($aI['N'], -1) == '/') {
  376. // is a directory entry - will be skipped
  377. continue;
  378. }
  379. // Truncate full filename in path and filename
  380. $aI['P'] = dirname($aI['N']);
  381. $aI['P'] = $aI['P'] == '.' ? '' : $aI['P'];
  382. $aI['N'] = basename($aI['N']);
  383. $vZ = substr($vZ, 26 + $nF + $mF);
  384. if ( strlen($vZ) != $aP['CS'] ) { // check only if availabled
  385. $aI['E'] = 1;
  386. $aI['EM'] = 'Compressed size is not equal with the value in header information.';
  387. } else {
  388. if ($bE) {
  389. $aI['E'] = 5;
  390. $aI['EM'] = 'File is encrypted, which is not supported from this class.';
  391. } else {
  392. switch($aP['CM']) {
  393. case 0: // Stored
  394. // Here is nothing to do, the file ist flat.
  395. break;
  396. case 8: // Deflated
  397. $vZ = gzinflate($vZ);
  398. break;
  399. case 12: // BZIP2
  400. if (! extension_loaded('bz2')) {
  401. if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
  402. @dl('php_bz2.dll');
  403. } else {
  404. @dl('bz2.so');
  405. }
  406. }
  407. if (extension_loaded('bz2')) {
  408. $vZ = bzdecompress($vZ);
  409. } else {
  410. $aI['E'] = 7;
  411. $aI['EM'] = "PHP BZIP2 extension not available.";
  412. }
  413. break;
  414. default:
  415. $aI['E'] = 6;
  416. $aI['EM'] = "De-/Compression method {$aP['CM']} is not supported.";
  417. }
  418. if (! $aI['E']) {
  419. if ($vZ === FALSE) {
  420. $aI['E'] = 2;
  421. $aI['EM'] = 'Decompression of data failed.';
  422. } else {
  423. if (strlen($vZ) != $aP['UCS']) {
  424. $aI['E'] = 3;
  425. $aI['EM'] = 'Uncompressed size is not equal with the value in header information.';
  426. } else {
  427. if (crc32($vZ) != $aP['CRC']) {
  428. $aI['E'] = 4;
  429. $aI['EM'] = 'CRC32 checksum is not equal with the value in header information.';
  430. }
  431. }
  432. }
  433. }
  434. }
  435. }
  436. $aI['D'] = $vZ;
  437. // DOS to UNIX timestamp
  438. $aI['T'] = mktime(($aP['FT'] & 0xf800) >> 11,
  439. ($aP['FT'] & 0x07e0) >> 5,
  440. ($aP['FT'] & 0x001f) << 1,
  441. ($aP['FD'] & 0x01e0) >> 5,
  442. ($aP['FD'] & 0x001f),
  443. (($aP['FD'] & 0xfe00) >> 9) + 1980);
  444. //$this->Entries[] = &new SimpleUnzipEntry($aI);
  445. $this->package['entries'][] = array(
  446. 'data' => $aI['D'],
  447. 'error' => $aI['E'],
  448. 'error_msg' => $aI['EM'],
  449. 'name' => $aI['N'],
  450. 'path' => $aI['P'],
  451. 'time' => $aI['T']
  452. );
  453. } // end for each entries
  454. }
  455. function getPackage() {
  456. return $this->package;
  457. }
  458. function entryExists( $name ) { // 0.6.6
  459. $dir = dirname( $name );
  460. $name = basename( $name );
  461. foreach( $this->package['entries'] as $entry)
  462. if ( $entry['path'] == $dir && $entry['name'] == $name)
  463. return true;
  464. return false;
  465. }
  466. function getEntryData( $name ) {
  467. $dir = dirname( $name );
  468. $name = basename( $name );
  469. foreach( $this->package['entries'] as $entry)
  470. if ( $entry['path'] == $dir && $entry['name'] == $name)
  471. return $entry['data'];
  472. $this->error('Unknown format');
  473. return false;
  474. }
  475. function getEntryXML( $name ) {
  476. if ( ($entry_xml = $this->getEntryData( $name ))
  477. && ($entry_xmlobj = simplexml_load_string( $entry_xml )))
  478. return $entry_xmlobj;
  479. $this->error('Entry not found: '.$name );
  480. return false;
  481. }
  482. function unixstamp( $excelDateTime ) {
  483. $d = floor( $excelDateTime ); // seconds since 1900
  484. $t = $excelDateTime - $d;
  485. return ($d > 0) ? ( $d - 25569 ) * 86400 + $t * 86400 : $t * 86400;
  486. }
  487. function error( $set = false ) {
  488. if ($set) {
  489. $this->error = $set;
  490. if ($this->debug)
  491. trigger_error( __CLASS__.': '.$set, E_USER_WARNING );
  492. } else {
  493. return $this->error;
  494. }
  495. }
  496. function success() {
  497. return !$this->error;
  498. }
  499. function _parse() {
  500. // Document data holders
  501. $this->sharedstrings = array();
  502. $this->sheets = array();
  503. // $this->styles = array();
  504. // Read relations and search for officeDocument
  505. if ( $relations = $this->getEntryXML("_rels/.rels" ) ) {
  506. foreach ($relations->Relationship as $rel) {
  507. if ($rel["Type"] == SimpleXLSX::SCHEMA_REL_OFFICEDOCUMENT) {
  508. // echo 'workbook found<br />';
  509. // Found office document! Read workbook & relations...
  510. // Workbook
  511. if ( $this->workbook = $this->getEntryXML( $rel['Target'] )) {
  512. // echo 'workbook read<br />';
  513. if ( $workbookRelations = $this->getEntryXML( dirname($rel['Target']) . '/_rels/workbook.xml.rels' )) {
  514. // echo 'workbook relations<br />';
  515. // Loop relations for workbook and extract sheets...
  516. foreach ($workbookRelations->Relationship as $workbookRelation) {
  517. $path = dirname($rel['Target']) . '/' . $workbookRelation['Target'];
  518. if ($workbookRelation['Type'] == SimpleXLSX::SCHEMA_REL_WORKSHEET) { // Sheets
  519. // echo 'sheet<br />';
  520. if ( $sheet = $this->getEntryXML( $path ) ) {
  521. $this->sheets[ str_replace( 'rId', '', (string) $workbookRelation['Id']) ] = $sheet;
  522. // echo '<pre>'.htmlspecialchars( print_r( $sheet, true ) ).'</pre>';
  523. }
  524. } else if ($workbookRelation['Type'] == SimpleXLSX::SCHEMA_REL_SHAREDSTRINGS && $this->entryExists( $path )) { // 0.6.6
  525. // echo 'sharedstrings<br />';
  526. if ( $sharedStrings = $this->getEntryXML( $path ) ) {
  527. foreach ($sharedStrings->si as $val) {
  528. if (isset($val->t)) {
  529. $this->sharedstrings[] = (string)$val->t;
  530. } elseif (isset($val->r)) {
  531. $this->sharedstrings[] = $this->_parseRichText($val);
  532. }
  533. }
  534. }
  535. } else if ($workbookRelation['Type'] == SimpleXLSX::SCHEMA_REL_STYLES) {
  536. $this->styles = $this->getEntryXML( $path );
  537. $nf = array();
  538. if ( $this->styles->numFmts->numFmt != NULL )
  539. foreach( $this->styles->numFmts->numFmt as $v )
  540. $nf[ (int) $v['numFmtId'] ] = (string) $v['formatCode'];
  541. if ( $this->styles->cellXfs->xf != NULL )
  542. foreach( $this->styles->cellXfs->xf as $v ) {
  543. $v = (array) $v->attributes();
  544. $v = $v['@attributes'];
  545. if (isset($this->built_in_cell_formats[ $v['numFmtId'] ]) )
  546. $v['format'] = $this->built_in_cell_formats[ $v['numFmtId'] ];
  547. else if (isset($nf[ $v['numFmtId'] ]))
  548. $v['format'] = $nf[ $v['numFmtId'] ];
  549. else
  550. $v['format'] = '';
  551. $this->workbook_cell_formats[] = $v;
  552. }
  553. // print_r( $this->workbook_cell_formats );
  554. }
  555. }
  556. break;
  557. }
  558. }
  559. }
  560. }
  561. }
  562. // Sort sheets
  563. ksort($this->sheets);
  564. }
  565. private function _parseRichText($is = null) {
  566. $value = array();
  567. if (isset($is->t)) {
  568. $value[] = (string)$is->t;
  569. } else {
  570. foreach ($is->r as $run) {
  571. $value[] = (string)$run->t;
  572. }
  573. }
  574. return implode(' ', $value);
  575. }
  576. }
  577. ?>