PageRenderTime 60ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/protected/extensions/phpexcel/Classes/PHPExcel/Reader/OOCalc.php

https://bitbucket.org/nochallenge/exlarlistprice
PHP | 733 lines | 452 code | 80 blank | 201 comment | 71 complexity | a514c3a4ae33b23fb1d95d4693227f15 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, GPL-3.0
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2012 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel_Reader
  23. * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version 1.7.8, 2012-10-12
  26. */
  27. /** PHPExcel root directory */
  28. if (!defined('PHPEXCEL_ROOT')) {
  29. /**
  30. * @ignore
  31. */
  32. define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
  33. require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
  34. }
  35. /**
  36. * PHPExcel_Reader_OOCalc
  37. *
  38. * @category PHPExcel
  39. * @package PHPExcel_Reader
  40. * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
  41. */
  42. class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader
  43. {
  44. /**
  45. * Read data only?
  46. * Identifies whether the Reader should only read data values for cells, and ignore any formatting information;
  47. * or whether it should read both data and formatting
  48. *
  49. * @var boolean
  50. */
  51. private $_readDataOnly = false;
  52. /**
  53. * Restrict which sheets should be loaded?
  54. * This property holds an array of worksheet names to be loaded. If null, then all worksheets will be loaded.
  55. *
  56. * @var array of string
  57. */
  58. private $_loadSheetsOnly = null;
  59. /**
  60. * Formats
  61. *
  62. * @var array
  63. */
  64. private $_styles = array();
  65. /**
  66. * PHPExcel_Reader_IReadFilter instance
  67. *
  68. * @var PHPExcel_Reader_IReadFilter
  69. */
  70. private $_readFilter = null;
  71. /**
  72. * Create a new PHPExcel_Reader_OOCalc
  73. */
  74. public function __construct() {
  75. $this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
  76. }
  77. /**
  78. * Read data only?
  79. * If this is true, then the Reader will only read data values for cells, it will not read any formatting information.
  80. * If false (the default) it will read data and formatting.
  81. *
  82. * @return boolean
  83. */
  84. public function getReadDataOnly() {
  85. return $this->_readDataOnly;
  86. }
  87. /**
  88. * Set read data only
  89. * Set to true, to advise the Reader only to read data values for cells, and to ignore any formatting information.
  90. * Set to false (the default) to advise the Reader to read both data and formatting for cells.
  91. *
  92. * @param boolean $pValue
  93. * @return PHPExcel_Reader_OOCalc
  94. */
  95. public function setReadDataOnly($pValue = false) {
  96. $this->_readDataOnly = $pValue;
  97. return $this;
  98. }
  99. /**
  100. * Get which sheets to load
  101. * Returns either an array of worksheet names (the list of worksheets that should be loaded), or a null
  102. * indicating that all worksheets in the workbook should be loaded.
  103. *
  104. * @return mixed
  105. */
  106. public function getLoadSheetsOnly()
  107. {
  108. return $this->_loadSheetsOnly;
  109. }
  110. /**
  111. * Set which sheets to load
  112. *
  113. * @param mixed $value
  114. * This should be either an array of worksheet names to be loaded, or a string containing a single worksheet name.
  115. * If NULL, then it tells the Reader to read all worksheets in the workbook
  116. *
  117. * @return PHPExcel_Reader_OOCalc
  118. */
  119. public function setLoadSheetsOnly($value = null)
  120. {
  121. $this->_loadSheetsOnly = is_array($value) ?
  122. $value : array($value);
  123. return $this;
  124. }
  125. /**
  126. * Set all sheets to load
  127. * Tells the Reader to load all worksheets from the workbook.
  128. *
  129. * @return PHPExcel_Reader_OOCalc
  130. */
  131. public function setLoadAllSheets()
  132. {
  133. $this->_loadSheetsOnly = null;
  134. return $this;
  135. }
  136. /**
  137. * Read filter
  138. *
  139. * @return PHPExcel_Reader_IReadFilter
  140. */
  141. public function getReadFilter() {
  142. return $this->_readFilter;
  143. }
  144. /**
  145. * Set read filter
  146. *
  147. * @param PHPExcel_Reader_IReadFilter $pValue
  148. * @return PHPExcel_Reader_OOCalc
  149. */
  150. public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue) {
  151. $this->_readFilter = $pValue;
  152. return $this;
  153. }
  154. /**
  155. * Can the current PHPExcel_Reader_IReader read the file?
  156. *
  157. * @param string $pFileName
  158. * @return boolean
  159. * @throws Exception
  160. */
  161. public function canRead($pFilename)
  162. {
  163. // Check if file exists
  164. if (!file_exists($pFilename)) {
  165. throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
  166. }
  167. // Check if zip class exists
  168. if (!class_exists('ZipArchive',FALSE)) {
  169. throw new Exception("ZipArchive library is not enabled");
  170. }
  171. // Load file
  172. $zip = new ZipArchive;
  173. if ($zip->open($pFilename) === true) {
  174. // check if it is an OOXML archive
  175. $stat = $zip->statName('mimetype');
  176. if ($stat && ($stat['size'] <= 255)) {
  177. $mimeType = $zip->getFromName($stat['name']);
  178. } else {
  179. $zip->close();
  180. return FALSE;
  181. }
  182. $zip->close();
  183. return ($mimeType === 'application/vnd.oasis.opendocument.spreadsheet');
  184. }
  185. return FALSE;
  186. }
  187. /**
  188. * Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object
  189. *
  190. * @param string $pFilename
  191. * @throws Exception
  192. */
  193. public function listWorksheetNames($pFilename)
  194. {
  195. // Check if file exists
  196. if (!file_exists($pFilename)) {
  197. throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
  198. }
  199. $worksheetNames = array();
  200. $zip = new ZipArchive;
  201. if ($zip->open($pFilename) === true) {
  202. $xml = simplexml_load_string($zip->getFromName("content.xml"));
  203. $namespacesContent = $xml->getNamespaces(true);
  204. $workbook = $xml->children($namespacesContent['office']);
  205. foreach($workbook->body->spreadsheet as $workbookData) {
  206. $workbookData = $workbookData->children($namespacesContent['table']);
  207. foreach($workbookData->table as $worksheetDataSet) {
  208. $worksheetDataAttributes = $worksheetDataSet->attributes($namespacesContent['table']);
  209. $worksheetNames[] = $worksheetDataAttributes['name'];
  210. }
  211. }
  212. }
  213. return $worksheetNames;
  214. }
  215. /**
  216. * Loads PHPExcel from file
  217. *
  218. * @param string $pFilename
  219. * @return PHPExcel
  220. * @throws Exception
  221. */
  222. public function load($pFilename)
  223. {
  224. // Create new PHPExcel
  225. $objPHPExcel = new PHPExcel();
  226. // Load into this instance
  227. return $this->loadIntoExisting($pFilename, $objPHPExcel);
  228. }
  229. private static function identifyFixedStyleValue($styleList,&$styleAttributeValue) {
  230. $styleAttributeValue = strtolower($styleAttributeValue);
  231. foreach($styleList as $style) {
  232. if ($styleAttributeValue == strtolower($style)) {
  233. $styleAttributeValue = $style;
  234. return true;
  235. }
  236. }
  237. return false;
  238. }
  239. /**
  240. * Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns)
  241. *
  242. * @param string $pFilename
  243. * @throws Exception
  244. */
  245. public function listWorksheetInfo($pFilename)
  246. {
  247. // Check if file exists
  248. if (!file_exists($pFilename)) {
  249. throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
  250. }
  251. $worksheetInfo = array();
  252. $zip = new ZipArchive;
  253. if ($zip->open($pFilename) === true) {
  254. $xml = simplexml_load_string($zip->getFromName("content.xml"));
  255. $namespacesContent = $xml->getNamespaces(true);
  256. $workbook = $xml->children($namespacesContent['office']);
  257. foreach($workbook->body->spreadsheet as $workbookData) {
  258. $workbookData = $workbookData->children($namespacesContent['table']);
  259. foreach($workbookData->table as $worksheetDataSet) {
  260. $worksheetData = $worksheetDataSet->children($namespacesContent['table']);
  261. $worksheetDataAttributes = $worksheetDataSet->attributes($namespacesContent['table']);
  262. $tmpInfo = array();
  263. $tmpInfo['worksheetName'] = (string) $worksheetDataAttributes['name'];
  264. $tmpInfo['lastColumnLetter'] = 'A';
  265. $tmpInfo['lastColumnIndex'] = 0;
  266. $tmpInfo['totalRows'] = 0;
  267. $tmpInfo['totalColumns'] = 0;
  268. $rowIndex = 0;
  269. foreach ($worksheetData as $key => $rowData) {
  270. switch ($key) {
  271. case 'table-row' :
  272. $rowDataTableAttributes = $rowData->attributes($namespacesContent['table']);
  273. $rowRepeats = (isset($rowDataTableAttributes['number-rows-repeated'])) ?
  274. $rowDataTableAttributes['number-rows-repeated'] : 1;
  275. $columnIndex = 0;
  276. foreach ($rowData as $key => $cellData) {
  277. $cellDataTableAttributes = $cellData->attributes($namespacesContent['table']);
  278. $colRepeats = (isset($cellDataTableAttributes['number-columns-repeated'])) ?
  279. $cellDataTableAttributes['number-columns-repeated'] : 1;
  280. $cellDataOfficeAttributes = $cellData->attributes($namespacesContent['office']);
  281. if (isset($cellDataOfficeAttributes['value-type'])) {
  282. $tmpInfo['lastColumnIndex'] = max($tmpInfo['lastColumnIndex'], $columnIndex + $colRepeats - 1);
  283. $tmpInfo['totalRows'] = max($tmpInfo['totalRows'], $rowIndex + $rowRepeats);
  284. }
  285. $columnIndex += $colRepeats;
  286. }
  287. $rowIndex += $rowRepeats;
  288. break;
  289. }
  290. }
  291. $tmpInfo['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']);
  292. $tmpInfo['totalColumns'] = $tmpInfo['lastColumnIndex'] + 1;
  293. $worksheetInfo[] = $tmpInfo;
  294. }
  295. }
  296. }
  297. return $worksheetInfo;
  298. }
  299. /**
  300. * Loads PHPExcel from file into PHPExcel instance
  301. *
  302. * @param string $pFilename
  303. * @param PHPExcel $objPHPExcel
  304. * @return PHPExcel
  305. * @throws Exception
  306. */
  307. public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
  308. {
  309. // Check if file exists
  310. if (!file_exists($pFilename)) {
  311. throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
  312. }
  313. $timezoneObj = new DateTimeZone('Europe/London');
  314. $GMT = new DateTimeZone('UTC');
  315. $zip = new ZipArchive;
  316. if ($zip->open($pFilename) === true) {
  317. // echo '<h1>Meta Information</h1>';
  318. $xml = simplexml_load_string($zip->getFromName("meta.xml"));
  319. $namespacesMeta = $xml->getNamespaces(true);
  320. // echo '<pre>';
  321. // print_r($namespacesMeta);
  322. // echo '</pre><hr />';
  323. $docProps = $objPHPExcel->getProperties();
  324. $officeProperty = $xml->children($namespacesMeta['office']);
  325. foreach($officeProperty as $officePropertyData) {
  326. $officePropertyDC = array();
  327. if (isset($namespacesMeta['dc'])) {
  328. $officePropertyDC = $officePropertyData->children($namespacesMeta['dc']);
  329. }
  330. foreach($officePropertyDC as $propertyName => $propertyValue) {
  331. switch ($propertyName) {
  332. case 'title' :
  333. $docProps->setTitle($propertyValue);
  334. break;
  335. case 'subject' :
  336. $docProps->setSubject($propertyValue);
  337. break;
  338. case 'creator' :
  339. $docProps->setCreator($propertyValue);
  340. $docProps->setLastModifiedBy($propertyValue);
  341. break;
  342. case 'date' :
  343. $creationDate = strtotime($propertyValue);
  344. $docProps->setCreated($creationDate);
  345. $docProps->setModified($creationDate);
  346. break;
  347. case 'description' :
  348. $docProps->setDescription($propertyValue);
  349. break;
  350. }
  351. }
  352. $officePropertyMeta = array();
  353. if (isset($namespacesMeta['dc'])) {
  354. $officePropertyMeta = $officePropertyData->children($namespacesMeta['meta']);
  355. }
  356. foreach($officePropertyMeta as $propertyName => $propertyValue) {
  357. $propertyValueAttributes = $propertyValue->attributes($namespacesMeta['meta']);
  358. switch ($propertyName) {
  359. case 'initial-creator' :
  360. $docProps->setCreator($propertyValue);
  361. break;
  362. case 'keyword' :
  363. $docProps->setKeywords($propertyValue);
  364. break;
  365. case 'creation-date' :
  366. $creationDate = strtotime($propertyValue);
  367. $docProps->setCreated($creationDate);
  368. break;
  369. case 'user-defined' :
  370. $propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_STRING;
  371. foreach ($propertyValueAttributes as $key => $value) {
  372. if ($key == 'name') {
  373. $propertyValueName = (string) $value;
  374. } elseif($key == 'value-type') {
  375. switch ($value) {
  376. case 'date' :
  377. $propertyValue = PHPExcel_DocumentProperties::convertProperty($propertyValue,'date');
  378. $propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_DATE;
  379. break;
  380. case 'boolean' :
  381. $propertyValue = PHPExcel_DocumentProperties::convertProperty($propertyValue,'bool');
  382. $propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_BOOLEAN;
  383. break;
  384. case 'float' :
  385. $propertyValue = PHPExcel_DocumentProperties::convertProperty($propertyValue,'r4');
  386. $propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_FLOAT;
  387. break;
  388. default :
  389. $propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_STRING;
  390. }
  391. }
  392. }
  393. $docProps->setCustomProperty($propertyValueName,$propertyValue,$propertyValueType);
  394. break;
  395. }
  396. }
  397. }
  398. // echo '<h1>Workbook Content</h1>';
  399. $xml = simplexml_load_string($zip->getFromName("content.xml"));
  400. $namespacesContent = $xml->getNamespaces(true);
  401. // echo '<pre>';
  402. // print_r($namespacesContent);
  403. // echo '</pre><hr />';
  404. $workbook = $xml->children($namespacesContent['office']);
  405. foreach($workbook->body->spreadsheet as $workbookData) {
  406. $workbookData = $workbookData->children($namespacesContent['table']);
  407. $worksheetID = 0;
  408. foreach($workbookData->table as $worksheetDataSet) {
  409. $worksheetData = $worksheetDataSet->children($namespacesContent['table']);
  410. // print_r($worksheetData);
  411. // echo '<br />';
  412. $worksheetDataAttributes = $worksheetDataSet->attributes($namespacesContent['table']);
  413. // print_r($worksheetDataAttributes);
  414. // echo '<br />';
  415. if ((isset($this->_loadSheetsOnly)) && (isset($worksheetDataAttributes['name'])) &&
  416. (!in_array($worksheetDataAttributes['name'], $this->_loadSheetsOnly))) {
  417. continue;
  418. }
  419. // echo '<h2>Worksheet '.$worksheetDataAttributes['name'].'</h2>';
  420. // Create new Worksheet
  421. $objPHPExcel->createSheet();
  422. $objPHPExcel->setActiveSheetIndex($worksheetID);
  423. if (isset($worksheetDataAttributes['name'])) {
  424. $worksheetName = (string) $worksheetDataAttributes['name'];
  425. // Use false for $updateFormulaCellReferences to prevent adjustment of worksheet references in
  426. // formula cells... during the load, all formulae should be correct, and we're simply
  427. // bringing the worksheet name in line with the formula, not the reverse
  428. $objPHPExcel->getActiveSheet()->setTitle($worksheetName,false);
  429. }
  430. $rowID = 1;
  431. foreach($worksheetData as $key => $rowData) {
  432. // echo '<b>'.$key.'</b><br />';
  433. switch ($key) {
  434. case 'table-header-rows':
  435. foreach ($rowData as $key=>$cellData) {
  436. $rowData = $cellData;
  437. break;
  438. }
  439. case 'table-row' :
  440. $rowDataTableAttributes = $rowData->attributes($namespacesContent['table']);
  441. $rowRepeats = (isset($rowDataTableAttributes['number-rows-repeated'])) ?
  442. $rowDataTableAttributes['number-rows-repeated'] : 1;
  443. $columnID = 'A';
  444. foreach($rowData as $key => $cellData) {
  445. if ($this->getReadFilter() !== NULL) {
  446. if (!$this->getReadFilter()->readCell($columnID, $rowID, $worksheetName)) {
  447. continue;
  448. }
  449. }
  450. // echo '<b>'.$columnID.$rowID.'</b><br />';
  451. $cellDataText = (isset($namespacesContent['text'])) ?
  452. $cellData->children($namespacesContent['text']) :
  453. '';
  454. $cellDataOffice = $cellData->children($namespacesContent['office']);
  455. $cellDataOfficeAttributes = $cellData->attributes($namespacesContent['office']);
  456. $cellDataTableAttributes = $cellData->attributes($namespacesContent['table']);
  457. // echo 'Office Attributes: ';
  458. // print_r($cellDataOfficeAttributes);
  459. // echo '<br />Table Attributes: ';
  460. // print_r($cellDataTableAttributes);
  461. // echo '<br />Cell Data Text';
  462. // print_r($cellDataText);
  463. // echo '<br />';
  464. //
  465. $type = $formatting = $hyperlink = null;
  466. $hasCalculatedValue = false;
  467. $cellDataFormula = '';
  468. if (isset($cellDataTableAttributes['formula'])) {
  469. $cellDataFormula = $cellDataTableAttributes['formula'];
  470. $hasCalculatedValue = true;
  471. }
  472. if (isset($cellDataOffice->annotation)) {
  473. // echo 'Cell has comment<br />';
  474. $annotationText = $cellDataOffice->annotation->children($namespacesContent['text']);
  475. $textArray = array();
  476. foreach($annotationText as $t) {
  477. foreach($t->span as $text) {
  478. $textArray[] = (string)$text;
  479. }
  480. }
  481. $text = implode("\n",$textArray);
  482. // echo $text,'<br />';
  483. $objPHPExcel->getActiveSheet()->getComment( $columnID.$rowID )
  484. // ->setAuthor( $author )
  485. ->setText($this->_parseRichText($text) );
  486. }
  487. if (isset($cellDataText->p)) {
  488. // Consolidate if there are multiple p records (maybe with spans as well)
  489. $dataArray = array();
  490. // Text can have multiple text:p and within those, multiple text:span.
  491. // text:p newlines, but text:span does not.
  492. // Also, here we assume there is no text data is span fields are specified, since
  493. // we have no way of knowing proper positioning anyway.
  494. foreach ($cellDataText->p as $pData) {
  495. if (isset($pData->span)) {
  496. // span sections do not newline, so we just create one large string here
  497. $spanSection = "";
  498. foreach ($pData->span as $spanData) {
  499. $spanSection .= $spanData;
  500. }
  501. array_push($dataArray, $spanSection);
  502. } else {
  503. array_push($dataArray, $pData);
  504. }
  505. }
  506. $allCellDataText = implode($dataArray, "\n");
  507. // echo 'Value Type is '.$cellDataOfficeAttributes['value-type'].'<br />';
  508. switch ($cellDataOfficeAttributes['value-type']) {
  509. case 'string' :
  510. $type = PHPExcel_Cell_DataType::TYPE_STRING;
  511. $dataValue = $allCellDataText;
  512. if (isset($dataValue->a)) {
  513. $dataValue = $dataValue->a;
  514. $cellXLinkAttributes = $dataValue->attributes($namespacesContent['xlink']);
  515. $hyperlink = $cellXLinkAttributes['href'];
  516. }
  517. break;
  518. case 'boolean' :
  519. $type = PHPExcel_Cell_DataType::TYPE_BOOL;
  520. $dataValue = ($allCellDataText == 'TRUE') ? True : False;
  521. break;
  522. case 'percentage' :
  523. $type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
  524. $dataValue = (float) $cellDataOfficeAttributes['value'];
  525. if (floor($dataValue) == $dataValue) {
  526. $dataValue = (integer) $dataValue;
  527. }
  528. $formatting = PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00;
  529. break;
  530. case 'currency' :
  531. $type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
  532. $dataValue = (float) $cellDataOfficeAttributes['value'];
  533. if (floor($dataValue) == $dataValue) {
  534. $dataValue = (integer) $dataValue;
  535. }
  536. $formatting = PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE;
  537. break;
  538. case 'float' :
  539. $type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
  540. $dataValue = (float) $cellDataOfficeAttributes['value'];
  541. if (floor($dataValue) == $dataValue) {
  542. if ($dataValue = (integer) $dataValue)
  543. $dataValue = (integer) $dataValue;
  544. else
  545. $dataValue = (float) $dataValue;
  546. }
  547. break;
  548. case 'date' :
  549. $type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
  550. $dateObj = new DateTime($cellDataOfficeAttributes['date-value'], $GMT);
  551. $dateObj->setTimeZone($timezoneObj);
  552. list($year,$month,$day,$hour,$minute,$second) = explode(' ',$dateObj->format('Y m d H i s'));
  553. $dataValue = PHPExcel_Shared_Date::FormattedPHPToExcel($year,$month,$day,$hour,$minute,$second);
  554. if ($dataValue != floor($dataValue)) {
  555. $formatting = PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15.' '.PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4;
  556. } else {
  557. $formatting = PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15;
  558. }
  559. break;
  560. case 'time' :
  561. $type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
  562. $dataValue = PHPExcel_Shared_Date::PHPToExcel(strtotime('01-01-1970 '.implode(':',sscanf($cellDataOfficeAttributes['time-value'],'PT%dH%dM%dS'))));
  563. $formatting = PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4;
  564. break;
  565. }
  566. // echo 'Data value is '.$dataValue.'<br />';
  567. // if ($hyperlink !== NULL) {
  568. // echo 'Hyperlink is '.$hyperlink.'<br />';
  569. // }
  570. } else {
  571. $type = PHPExcel_Cell_DataType::TYPE_NULL;
  572. $dataValue = NULL;
  573. }
  574. if ($hasCalculatedValue) {
  575. $type = PHPExcel_Cell_DataType::TYPE_FORMULA;
  576. // echo 'Formula: '.$cellDataFormula.'<br />';
  577. $cellDataFormula = substr($cellDataFormula,strpos($cellDataFormula,':=')+1);
  578. $temp = explode('"',$cellDataFormula);
  579. $tKey = false;
  580. foreach($temp as &$value) {
  581. // Only replace in alternate array entries (i.e. non-quoted blocks)
  582. if ($tKey = !$tKey) {
  583. $value = preg_replace('/\[\.(.*):\.(.*)\]/Ui','$1:$2',$value);
  584. $value = preg_replace('/\[\.(.*)\]/Ui','$1',$value);
  585. $value = PHPExcel_Calculation::_translateSeparator(';',',',$value,$inBraces);
  586. }
  587. }
  588. unset($value);
  589. // Then rebuild the formula string
  590. $cellDataFormula = implode('"',$temp);
  591. // echo 'Adjusted Formula: '.$cellDataFormula.'<br />';
  592. }
  593. $colRepeats = (isset($cellDataTableAttributes['number-columns-repeated'])) ?
  594. $cellDataTableAttributes['number-columns-repeated'] : 1;
  595. if ($type !== NULL) {
  596. for ($i = 0; $i < $colRepeats; ++$i) {
  597. if ($i > 0) {
  598. ++$columnID;
  599. }
  600. if ($type !== PHPExcel_Cell_DataType::TYPE_NULL) {
  601. for ($rowAdjust = 0; $rowAdjust < $rowRepeats; ++$rowAdjust) {
  602. $rID = $rowID + $rowAdjust;
  603. $objPHPExcel->getActiveSheet()->getCell($columnID.$rID)->setValueExplicit((($hasCalculatedValue) ? $cellDataFormula : $dataValue),$type);
  604. if ($hasCalculatedValue) {
  605. // echo 'Forumla result is '.$dataValue.'<br />';
  606. $objPHPExcel->getActiveSheet()->getCell($columnID.$rID)->setCalculatedValue($dataValue);
  607. }
  608. if ($formatting !== NULL) {
  609. $objPHPExcel->getActiveSheet()->getStyle($columnID.$rID)->getNumberFormat()->setFormatCode($formatting);
  610. } else {
  611. $objPHPExcel->getActiveSheet()->getStyle($columnID.$rID)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_GENERAL);
  612. }
  613. if ($hyperlink !== NULL) {
  614. $objPHPExcel->getActiveSheet()->getCell($columnID.$rID)->getHyperlink()->setUrl($hyperlink);
  615. }
  616. }
  617. }
  618. }
  619. }
  620. // Merged cells
  621. if ((isset($cellDataTableAttributes['number-columns-spanned'])) || (isset($cellDataTableAttributes['number-rows-spanned']))) {
  622. if (($type !== PHPExcel_Cell_DataType::TYPE_NULL) || (!$this->_readDataOnly)) {
  623. $columnTo = $columnID;
  624. if (isset($cellDataTableAttributes['number-columns-spanned'])) {
  625. $columnTo = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($columnID) + $cellDataTableAttributes['number-columns-spanned'] -2);
  626. }
  627. $rowTo = $rowID;
  628. if (isset($cellDataTableAttributes['number-rows-spanned'])) {
  629. $rowTo = $rowTo + $cellDataTableAttributes['number-rows-spanned'] - 1;
  630. }
  631. $cellRange = $columnID.$rowID.':'.$columnTo.$rowTo;
  632. $objPHPExcel->getActiveSheet()->mergeCells($cellRange);
  633. }
  634. }
  635. ++$columnID;
  636. }
  637. $rowID += $rowRepeats;
  638. break;
  639. }
  640. }
  641. ++$worksheetID;
  642. }
  643. }
  644. }
  645. // Return
  646. return $objPHPExcel;
  647. }
  648. private function _parseRichText($is = '') {
  649. $value = new PHPExcel_RichText();
  650. $value->createText($is);
  651. return $value;
  652. }
  653. }