PageRenderTime 54ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/PHPExcel/PHPExcel/Reader/OOCalc.php

https://bitbucket.org/thomashii/vtigercrm-6-for-postgresql
PHP | 690 lines | 411 code | 84 blank | 195 comment | 60 complexity | 3eb62e14b5dbbed446977e96dbd4c0be MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0, LGPL-2.1, GPL-2.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.7, 2012-05-19
  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')) {
  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. $mimeType = $zip->getFromName("mimetype");
  176. $zip->close();
  177. return ($mimeType === 'application/vnd.oasis.opendocument.spreadsheet');
  178. }
  179. return false;
  180. }
  181. /**
  182. * Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object
  183. *
  184. * @param string $pFilename
  185. * @throws Exception
  186. */
  187. public function listWorksheetNames($pFilename)
  188. {
  189. // Check if file exists
  190. if (!file_exists($pFilename)) {
  191. throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
  192. }
  193. $worksheetNames = array();
  194. $zip = new ZipArchive;
  195. if ($zip->open($pFilename) === true) {
  196. $xml = simplexml_load_string($zip->getFromName("content.xml"));
  197. $namespacesContent = $xml->getNamespaces(true);
  198. $workbook = $xml->children($namespacesContent['office']);
  199. foreach($workbook->body->spreadsheet as $workbookData) {
  200. $workbookData = $workbookData->children($namespacesContent['table']);
  201. foreach($workbookData->table as $worksheetDataSet) {
  202. $worksheetDataAttributes = $worksheetDataSet->attributes($namespacesContent['table']);
  203. $worksheetNames[] = $worksheetDataAttributes['name'];
  204. }
  205. }
  206. }
  207. return $worksheetNames;
  208. }
  209. /**
  210. * Loads PHPExcel from file
  211. *
  212. * @param string $pFilename
  213. * @return PHPExcel
  214. * @throws Exception
  215. */
  216. public function load($pFilename)
  217. {
  218. // Create new PHPExcel
  219. $objPHPExcel = new PHPExcel();
  220. // Load into this instance
  221. return $this->loadIntoExisting($pFilename, $objPHPExcel);
  222. }
  223. private static function identifyFixedStyleValue($styleList,&$styleAttributeValue) {
  224. $styleAttributeValue = strtolower($styleAttributeValue);
  225. foreach($styleList as $style) {
  226. if ($styleAttributeValue == strtolower($style)) {
  227. $styleAttributeValue = $style;
  228. return true;
  229. }
  230. }
  231. return false;
  232. }
  233. /**
  234. * Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns)
  235. *
  236. * @param string $pFilename
  237. * @throws Exception
  238. */
  239. public function listWorksheetInfo($pFilename)
  240. {
  241. // Check if file exists
  242. if (!file_exists($pFilename)) {
  243. throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
  244. }
  245. $worksheetInfo = array();
  246. $zip = new ZipArchive;
  247. if ($zip->open($pFilename) === true) {
  248. $xml = simplexml_load_string($zip->getFromName("content.xml"));
  249. $namespacesContent = $xml->getNamespaces(true);
  250. $workbook = $xml->children($namespacesContent['office']);
  251. foreach($workbook->body->spreadsheet as $workbookData) {
  252. $workbookData = $workbookData->children($namespacesContent['table']);
  253. foreach($workbookData->table as $worksheetDataSet) {
  254. $worksheetData = $worksheetDataSet->children($namespacesContent['table']);
  255. $worksheetDataAttributes = $worksheetDataSet->attributes($namespacesContent['table']);
  256. $tmpInfo = array();
  257. $tmpInfo['worksheetName'] = $worksheetDataAttributes['name'];
  258. $tmpInfo['lastColumnLetter'] = 'A';
  259. $tmpInfo['lastColumnIndex'] = 0;
  260. $tmpInfo['totalRows'] = 0;
  261. $tmpInfo['totalColumns'] = 0;
  262. $rowIndex = 0;
  263. foreach ($worksheetData as $key => $rowData) {
  264. $rowHasData = false;
  265. switch ($key) {
  266. case 'table-row' :
  267. $columnIndex = 0;
  268. foreach ($rowData as $key => $cellData) {
  269. $cellHasData = false;
  270. $cellDataText = $cellData->children($namespacesContent['text']);
  271. $cellDataOfficeAttributes = $cellData->attributes($namespacesContent['office']);
  272. if (isset($cellDataText->p)) {
  273. switch ($cellDataOfficeAttributes['value-type']) {
  274. case 'string' :
  275. case 'boolean' :
  276. case 'float' :
  277. case 'date' :
  278. case 'time' :
  279. $cellHasData = true;
  280. break;
  281. }
  282. }
  283. $cellDataText = null;
  284. $cellDataOfficeAttributes = null;
  285. if ($cellHasData) {
  286. $tmpInfo['lastColumnIndex'] = max($tmpInfo['lastColumnIndex'], $columnIndex);
  287. $rowHasData = true;
  288. }
  289. ++$columnIndex;
  290. }
  291. ++$rowIndex;
  292. if ($rowHasData) {
  293. $tmpInfo['totalRows'] = max($tmpInfo['totalRows'], $rowIndex);
  294. }
  295. break;
  296. }
  297. }
  298. $tmpInfo['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']);
  299. $tmpInfo['totalColumns'] = $tmpInfo['lastColumnIndex'] + 1;
  300. $worksheetInfo[] = $tmpInfo;
  301. }
  302. }
  303. }
  304. return $worksheetInfo;
  305. }
  306. /**
  307. * Loads PHPExcel from file into PHPExcel instance
  308. *
  309. * @param string $pFilename
  310. * @param PHPExcel $objPHPExcel
  311. * @return PHPExcel
  312. * @throws Exception
  313. */
  314. public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
  315. {
  316. // Check if file exists
  317. if (!file_exists($pFilename)) {
  318. throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
  319. }
  320. $timezoneObj = new DateTimeZone('Europe/London');
  321. $GMT = new DateTimeZone('UTC');
  322. $zip = new ZipArchive;
  323. if ($zip->open($pFilename) === true) {
  324. // echo '<h1>Meta Information</h1>';
  325. $xml = simplexml_load_string($zip->getFromName("meta.xml"));
  326. $namespacesMeta = $xml->getNamespaces(true);
  327. // echo '<pre>';
  328. // print_r($namespacesMeta);
  329. // echo '</pre><hr />';
  330. $docProps = $objPHPExcel->getProperties();
  331. $officeProperty = $xml->children($namespacesMeta['office']);
  332. foreach($officeProperty as $officePropertyData) {
  333. $officePropertyDC = array();
  334. if (isset($namespacesMeta['dc'])) {
  335. $officePropertyDC = $officePropertyData->children($namespacesMeta['dc']);
  336. }
  337. foreach($officePropertyDC as $propertyName => $propertyValue) {
  338. switch ($propertyName) {
  339. case 'title' :
  340. $docProps->setTitle($propertyValue);
  341. break;
  342. case 'subject' :
  343. $docProps->setSubject($propertyValue);
  344. break;
  345. case 'creator' :
  346. $docProps->setCreator($propertyValue);
  347. $docProps->setLastModifiedBy($propertyValue);
  348. break;
  349. case 'date' :
  350. $creationDate = strtotime($propertyValue);
  351. $docProps->setCreated($creationDate);
  352. $docProps->setModified($creationDate);
  353. break;
  354. case 'description' :
  355. $docProps->setDescription($propertyValue);
  356. break;
  357. }
  358. }
  359. $officePropertyMeta = array();
  360. if (isset($namespacesMeta['dc'])) {
  361. $officePropertyMeta = $officePropertyData->children($namespacesMeta['meta']);
  362. }
  363. foreach($officePropertyMeta as $propertyName => $propertyValue) {
  364. $propertyValueAttributes = $propertyValue->attributes($namespacesMeta['meta']);
  365. switch ($propertyName) {
  366. case 'initial-creator' :
  367. $docProps->setCreator($propertyValue);
  368. break;
  369. case 'keyword' :
  370. $docProps->setKeywords($propertyValue);
  371. break;
  372. case 'creation-date' :
  373. $creationDate = strtotime($propertyValue);
  374. $docProps->setCreated($creationDate);
  375. break;
  376. case 'user-defined' :
  377. $propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_STRING;
  378. foreach ($propertyValueAttributes as $key => $value) {
  379. if ($key == 'name') {
  380. $propertyValueName = (string) $value;
  381. } elseif($key == 'value-type') {
  382. switch ($value) {
  383. case 'date' :
  384. $propertyValue = PHPExcel_DocumentProperties::convertProperty($propertyValue,'date');
  385. $propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_DATE;
  386. break;
  387. case 'boolean' :
  388. $propertyValue = PHPExcel_DocumentProperties::convertProperty($propertyValue,'bool');
  389. $propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_BOOLEAN;
  390. break;
  391. case 'float' :
  392. $propertyValue = PHPExcel_DocumentProperties::convertProperty($propertyValue,'r4');
  393. $propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_FLOAT;
  394. break;
  395. default :
  396. $propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_STRING;
  397. }
  398. }
  399. }
  400. $docProps->setCustomProperty($propertyValueName,$propertyValue,$propertyValueType);
  401. break;
  402. }
  403. }
  404. }
  405. // echo '<h1>Workbook Content</h1>';
  406. $xml = simplexml_load_string($zip->getFromName("content.xml"));
  407. $namespacesContent = $xml->getNamespaces(true);
  408. // echo '<pre>';
  409. // print_r($namespacesContent);
  410. // echo '</pre><hr />';
  411. $workbook = $xml->children($namespacesContent['office']);
  412. foreach($workbook->body->spreadsheet as $workbookData) {
  413. $workbookData = $workbookData->children($namespacesContent['table']);
  414. $worksheetID = 0;
  415. foreach($workbookData->table as $worksheetDataSet) {
  416. $worksheetData = $worksheetDataSet->children($namespacesContent['table']);
  417. // print_r($worksheetData);
  418. // echo '<br />';
  419. $worksheetDataAttributes = $worksheetDataSet->attributes($namespacesContent['table']);
  420. // print_r($worksheetDataAttributes);
  421. // echo '<br />';
  422. if ((isset($this->_loadSheetsOnly)) && (isset($worksheetDataAttributes['name'])) &&
  423. (!in_array($worksheetDataAttributes['name'], $this->_loadSheetsOnly))) {
  424. continue;
  425. }
  426. // echo '<h2>Worksheet '.$worksheetDataAttributes['name'].'</h2>';
  427. // Create new Worksheet
  428. $objPHPExcel->createSheet();
  429. $objPHPExcel->setActiveSheetIndex($worksheetID);
  430. if (isset($worksheetDataAttributes['name'])) {
  431. $worksheetName = (string) $worksheetDataAttributes['name'];
  432. // Use false for $updateFormulaCellReferences to prevent adjustment of worksheet references in
  433. // formula cells... during the load, all formulae should be correct, and we're simply
  434. // bringing the worksheet name in line with the formula, not the reverse
  435. $objPHPExcel->getActiveSheet()->setTitle($worksheetName,false);
  436. }
  437. $rowID = 1;
  438. foreach($worksheetData as $key => $rowData) {
  439. // echo '<b>'.$key.'</b><br />';
  440. switch ($key) {
  441. case 'table-header-rows':
  442. foreach ($rowData as $key=>$cellData) {
  443. $rowData = $cellData;
  444. break;
  445. }
  446. case 'table-row' :
  447. $columnID = 'A';
  448. foreach($rowData as $key => $cellData) {
  449. if ($this->getReadFilter() !== NULL) {
  450. if (!$this->getReadFilter()->readCell($columnID, $rowID, $worksheetName)) {
  451. continue;
  452. }
  453. }
  454. // echo '<b>'.$columnID.$rowID.'</b><br />';
  455. $cellDataText = $cellData->children($namespacesContent['text']);
  456. $cellDataOffice = $cellData->children($namespacesContent['office']);
  457. $cellDataOfficeAttributes = $cellData->attributes($namespacesContent['office']);
  458. $cellDataTableAttributes = $cellData->attributes($namespacesContent['table']);
  459. // echo 'Office Attributes: ';
  460. // print_r($cellDataOfficeAttributes);
  461. // echo '<br />Table Attributes: ';
  462. // print_r($cellDataTableAttributes);
  463. // echo '<br />Cell Data Text';
  464. // print_r($cellDataText);
  465. // echo '<br />';
  466. //
  467. $type = $formatting = $hyperlink = null;
  468. $hasCalculatedValue = false;
  469. $cellDataFormula = '';
  470. if (isset($cellDataTableAttributes['formula'])) {
  471. $cellDataFormula = $cellDataTableAttributes['formula'];
  472. $hasCalculatedValue = true;
  473. }
  474. if (isset($cellDataOffice->annotation)) {
  475. // echo 'Cell has comment<br />';
  476. $annotationText = $cellDataOffice->annotation->children($namespacesContent['text']);
  477. $textArray = array();
  478. foreach($annotationText as $t) {
  479. foreach($t->span as $text) {
  480. $textArray[] = (string)$text;
  481. }
  482. }
  483. $text = implode("\n",$textArray);
  484. // echo $text,'<br />';
  485. $objPHPExcel->getActiveSheet()->getComment( $columnID.$rowID )
  486. // ->setAuthor( $author )
  487. ->setText($this->_parseRichText($text) );
  488. }
  489. if (isset($cellDataText->p)) {
  490. // echo 'Value Type is '.$cellDataOfficeAttributes['value-type'].'<br />';
  491. switch ($cellDataOfficeAttributes['value-type']) {
  492. case 'string' :
  493. $type = PHPExcel_Cell_DataType::TYPE_STRING;
  494. $dataValue = $cellDataText->p;
  495. if (isset($dataValue->a)) {
  496. $dataValue = $dataValue->a;
  497. $cellXLinkAttributes = $dataValue->attributes($namespacesContent['xlink']);
  498. $hyperlink = $cellXLinkAttributes['href'];
  499. }
  500. break;
  501. case 'boolean' :
  502. $type = PHPExcel_Cell_DataType::TYPE_BOOL;
  503. $dataValue = ($cellDataText->p == 'TRUE') ? True : False;
  504. break;
  505. case 'float' :
  506. $type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
  507. $dataValue = (float) $cellDataOfficeAttributes['value'];
  508. if (floor($dataValue) == $dataValue) {
  509. $dataValue = (integer) $dataValue;
  510. }
  511. break;
  512. case 'date' :
  513. $type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
  514. $dateObj = new DateTime($cellDataOfficeAttributes['date-value'], $GMT);
  515. $dateObj->setTimeZone($timezoneObj);
  516. list($year,$month,$day,$hour,$minute,$second) = explode(' ',$dateObj->format('Y m d H i s'));
  517. $dataValue = PHPExcel_Shared_Date::FormattedPHPToExcel($year,$month,$day,$hour,$minute,$second);
  518. if ($dataValue != floor($dataValue)) {
  519. $formatting = PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15.' '.PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4;
  520. } else {
  521. $formatting = PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15;
  522. }
  523. break;
  524. case 'time' :
  525. $type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
  526. $dataValue = PHPExcel_Shared_Date::PHPToExcel(strtotime('01-01-1970 '.implode(':',sscanf($cellDataOfficeAttributes['time-value'],'PT%dH%dM%dS'))));
  527. $formatting = PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4;
  528. break;
  529. }
  530. // echo 'Data value is '.$dataValue.'<br />';
  531. // if ($hyperlink !== NULL) {
  532. // echo 'Hyperlink is '.$hyperlink.'<br />';
  533. // }
  534. }
  535. if ($hasCalculatedValue) {
  536. $type = PHPExcel_Cell_DataType::TYPE_FORMULA;
  537. // echo 'Formula: '.$cellDataFormula.'<br />';
  538. $cellDataFormula = substr($cellDataFormula,strpos($cellDataFormula,':=')+1);
  539. $temp = explode('"',$cellDataFormula);
  540. $tKey = false;
  541. foreach($temp as &$value) {
  542. // Only replace in alternate array entries (i.e. non-quoted blocks)
  543. if ($tKey = !$tKey) {
  544. $value = preg_replace('/\[\.(.*):\.(.*)\]/Ui','$1:$2',$value);
  545. $value = preg_replace('/\[\.(.*)\]/Ui','$1',$value);
  546. $value = PHPExcel_Calculation::_translateSeparator(';',',',$value,$inBraces);
  547. }
  548. }
  549. unset($value);
  550. // Then rebuild the formula string
  551. $cellDataFormula = implode('"',$temp);
  552. // echo 'Adjusted Formula: '.$cellDataFormula.'<br />';
  553. }
  554. $repeats = (isset($cellDataTableAttributes['number-columns-repeated'])) ?
  555. $cellDataTableAttributes['number-columns-repeated'] : 1;
  556. if ($type !== NULL) {
  557. for ($i = 0; $i < $repeats; ++$i) {
  558. if ($i > 0) {
  559. ++$columnID;
  560. }
  561. $objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setValueExplicit((($hasCalculatedValue) ? $cellDataFormula : $dataValue),$type);
  562. if ($hasCalculatedValue) {
  563. // echo 'Forumla result is '.$dataValue.'<br />';
  564. $objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setCalculatedValue($dataValue);
  565. }
  566. if (($cellDataOfficeAttributes['value-type'] == 'date') ||
  567. ($cellDataOfficeAttributes['value-type'] == 'time')) {
  568. $objPHPExcel->getActiveSheet()->getStyle($columnID.$rowID)->getNumberFormat()->setFormatCode($formatting);
  569. }
  570. if ($hyperlink !== NULL) {
  571. $objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->getHyperlink()->setUrl($hyperlink);
  572. }
  573. }
  574. }
  575. // Merged cells
  576. if ((isset($cellDataTableAttributes['number-columns-spanned'])) || (isset($cellDataTableAttributes['number-rows-spanned']))) {
  577. $columnTo = $columnID;
  578. if (isset($cellDataTableAttributes['number-columns-spanned'])) {
  579. $columnTo = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($columnID) + $cellDataTableAttributes['number-columns-spanned'] -2);
  580. }
  581. $rowTo = $rowID;
  582. if (isset($cellDataTableAttributes['number-rows-spanned'])) {
  583. $rowTo = $rowTo + $cellDataTableAttributes['number-rows-spanned'] - 1;
  584. }
  585. $cellRange = $columnID.$rowID.':'.$columnTo.$rowTo;
  586. $objPHPExcel->getActiveSheet()->mergeCells($cellRange);
  587. }
  588. ++$columnID;
  589. }
  590. ++$rowID;
  591. break;
  592. }
  593. }
  594. ++$worksheetID;
  595. }
  596. }
  597. }
  598. // Return
  599. return $objPHPExcel;
  600. }
  601. private function _parseRichText($is = '') {
  602. $value = new PHPExcel_RichText();
  603. $value->createText($is);
  604. return $value;
  605. }
  606. }