PageRenderTime 72ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/Classes/PHPExcel/Reader/OOCalc.php

https://github.com/iGroup/PHPExcel
PHP | 618 lines | 420 code | 63 blank | 135 comment | 71 complexity | 2b173688e0a682137127572611276b21 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1
  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 ##VERSION##, ##DATE##
  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 extends PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
  43. {
  44. /**
  45. * Formats
  46. *
  47. * @var array
  48. */
  49. private $_styles = array();
  50. /**
  51. * Create a new PHPExcel_Reader_OOCalc
  52. */
  53. public function __construct() {
  54. $this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
  55. }
  56. /**
  57. * Can the current PHPExcel_Reader_IReader read the file?
  58. *
  59. * @param string $pFileName
  60. * @return boolean
  61. * @throws PHPExcel_Reader_Exception
  62. */
  63. public function canRead($pFilename)
  64. {
  65. // Check if file exists
  66. if (!file_exists($pFilename)) {
  67. throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
  68. }
  69. // Check if zip class exists
  70. if (!class_exists('ZipArchive',FALSE)) {
  71. throw new PHPExcel_Reader_Exception("ZipArchive library is not enabled");
  72. }
  73. // Load file
  74. $zip = new ZipArchive;
  75. if ($zip->open($pFilename) === true) {
  76. // check if it is an OOXML archive
  77. $stat = $zip->statName('mimetype');
  78. if ($stat && ($stat['size'] <= 255)) {
  79. $mimeType = $zip->getFromName($stat['name']);
  80. } else {
  81. $zip->close();
  82. return FALSE;
  83. }
  84. $zip->close();
  85. return ($mimeType === 'application/vnd.oasis.opendocument.spreadsheet');
  86. }
  87. return FALSE;
  88. }
  89. /**
  90. * Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object
  91. *
  92. * @param string $pFilename
  93. * @throws PHPExcel_Reader_Exception
  94. */
  95. public function listWorksheetNames($pFilename)
  96. {
  97. // Check if file exists
  98. if (!file_exists($pFilename)) {
  99. throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
  100. }
  101. $worksheetNames = array();
  102. $zip = new ZipArchive;
  103. if ($zip->open($pFilename) === true) {
  104. $xml = simplexml_load_string($zip->getFromName("content.xml"));
  105. $namespacesContent = $xml->getNamespaces(true);
  106. $workbook = $xml->children($namespacesContent['office']);
  107. foreach($workbook->body->spreadsheet as $workbookData) {
  108. $workbookData = $workbookData->children($namespacesContent['table']);
  109. foreach($workbookData->table as $worksheetDataSet) {
  110. $worksheetDataAttributes = $worksheetDataSet->attributes($namespacesContent['table']);
  111. $worksheetNames[] = $worksheetDataAttributes['name'];
  112. }
  113. }
  114. }
  115. return $worksheetNames;
  116. }
  117. /**
  118. * Loads PHPExcel from file
  119. *
  120. * @param string $pFilename
  121. * @return PHPExcel
  122. * @throws PHPExcel_Reader_Exception
  123. */
  124. public function load($pFilename)
  125. {
  126. // Create new PHPExcel
  127. $objPHPExcel = new PHPExcel();
  128. // Load into this instance
  129. return $this->loadIntoExisting($pFilename, $objPHPExcel);
  130. }
  131. private static function identifyFixedStyleValue($styleList,&$styleAttributeValue) {
  132. $styleAttributeValue = strtolower($styleAttributeValue);
  133. foreach($styleList as $style) {
  134. if ($styleAttributeValue == strtolower($style)) {
  135. $styleAttributeValue = $style;
  136. return true;
  137. }
  138. }
  139. return false;
  140. }
  141. /**
  142. * Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns)
  143. *
  144. * @param string $pFilename
  145. * @throws PHPExcel_Reader_Exception
  146. */
  147. public function listWorksheetInfo($pFilename)
  148. {
  149. // Check if file exists
  150. if (!file_exists($pFilename)) {
  151. throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
  152. }
  153. $worksheetInfo = array();
  154. $zip = new ZipArchive;
  155. if ($zip->open($pFilename) === true) {
  156. $xml = simplexml_load_string($zip->getFromName("content.xml"));
  157. $namespacesContent = $xml->getNamespaces(true);
  158. $workbook = $xml->children($namespacesContent['office']);
  159. foreach($workbook->body->spreadsheet as $workbookData) {
  160. $workbookData = $workbookData->children($namespacesContent['table']);
  161. foreach($workbookData->table as $worksheetDataSet) {
  162. $worksheetData = $worksheetDataSet->children($namespacesContent['table']);
  163. $worksheetDataAttributes = $worksheetDataSet->attributes($namespacesContent['table']);
  164. $tmpInfo = array();
  165. $tmpInfo['worksheetName'] = (string) $worksheetDataAttributes['name'];
  166. $tmpInfo['lastColumnLetter'] = 'A';
  167. $tmpInfo['lastColumnIndex'] = 0;
  168. $tmpInfo['totalRows'] = 0;
  169. $tmpInfo['totalColumns'] = 0;
  170. $rowIndex = 0;
  171. foreach ($worksheetData as $key => $rowData) {
  172. switch ($key) {
  173. case 'table-row' :
  174. $rowDataTableAttributes = $rowData->attributes($namespacesContent['table']);
  175. $rowRepeats = (isset($rowDataTableAttributes['number-rows-repeated'])) ?
  176. $rowDataTableAttributes['number-rows-repeated'] : 1;
  177. $columnIndex = 0;
  178. foreach ($rowData as $key => $cellData) {
  179. $cellDataTableAttributes = $cellData->attributes($namespacesContent['table']);
  180. $colRepeats = (isset($cellDataTableAttributes['number-columns-repeated'])) ?
  181. $cellDataTableAttributes['number-columns-repeated'] : 1;
  182. $cellDataOfficeAttributes = $cellData->attributes($namespacesContent['office']);
  183. if (isset($cellDataOfficeAttributes['value-type'])) {
  184. $tmpInfo['lastColumnIndex'] = max($tmpInfo['lastColumnIndex'], $columnIndex + $colRepeats - 1);
  185. $tmpInfo['totalRows'] = max($tmpInfo['totalRows'], $rowIndex + $rowRepeats);
  186. }
  187. $columnIndex += $colRepeats;
  188. }
  189. $rowIndex += $rowRepeats;
  190. break;
  191. }
  192. }
  193. $tmpInfo['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']);
  194. $tmpInfo['totalColumns'] = $tmpInfo['lastColumnIndex'] + 1;
  195. $worksheetInfo[] = $tmpInfo;
  196. }
  197. }
  198. }
  199. return $worksheetInfo;
  200. }
  201. /**
  202. * Loads PHPExcel from file into PHPExcel instance
  203. *
  204. * @param string $pFilename
  205. * @param PHPExcel $objPHPExcel
  206. * @return PHPExcel
  207. * @throws PHPExcel_Reader_Exception
  208. */
  209. public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
  210. {
  211. // Check if file exists
  212. if (!file_exists($pFilename)) {
  213. throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
  214. }
  215. $timezoneObj = new DateTimeZone('Europe/London');
  216. $GMT = new DateTimeZone('UTC');
  217. $zip = new ZipArchive;
  218. if ($zip->open($pFilename) === true) {
  219. // echo '<h1>Meta Information</h1>';
  220. $xml = simplexml_load_string($zip->getFromName("meta.xml"));
  221. $namespacesMeta = $xml->getNamespaces(true);
  222. // echo '<pre>';
  223. // print_r($namespacesMeta);
  224. // echo '</pre><hr />';
  225. $docProps = $objPHPExcel->getProperties();
  226. $officeProperty = $xml->children($namespacesMeta['office']);
  227. foreach($officeProperty as $officePropertyData) {
  228. $officePropertyDC = array();
  229. if (isset($namespacesMeta['dc'])) {
  230. $officePropertyDC = $officePropertyData->children($namespacesMeta['dc']);
  231. }
  232. foreach($officePropertyDC as $propertyName => $propertyValue) {
  233. switch ($propertyName) {
  234. case 'title' :
  235. $docProps->setTitle($propertyValue);
  236. break;
  237. case 'subject' :
  238. $docProps->setSubject($propertyValue);
  239. break;
  240. case 'creator' :
  241. $docProps->setCreator($propertyValue);
  242. $docProps->setLastModifiedBy($propertyValue);
  243. break;
  244. case 'date' :
  245. $creationDate = strtotime($propertyValue);
  246. $docProps->setCreated($creationDate);
  247. $docProps->setModified($creationDate);
  248. break;
  249. case 'description' :
  250. $docProps->setDescription($propertyValue);
  251. break;
  252. }
  253. }
  254. $officePropertyMeta = array();
  255. if (isset($namespacesMeta['dc'])) {
  256. $officePropertyMeta = $officePropertyData->children($namespacesMeta['meta']);
  257. }
  258. foreach($officePropertyMeta as $propertyName => $propertyValue) {
  259. $propertyValueAttributes = $propertyValue->attributes($namespacesMeta['meta']);
  260. switch ($propertyName) {
  261. case 'initial-creator' :
  262. $docProps->setCreator($propertyValue);
  263. break;
  264. case 'keyword' :
  265. $docProps->setKeywords($propertyValue);
  266. break;
  267. case 'creation-date' :
  268. $creationDate = strtotime($propertyValue);
  269. $docProps->setCreated($creationDate);
  270. break;
  271. case 'user-defined' :
  272. $propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_STRING;
  273. foreach ($propertyValueAttributes as $key => $value) {
  274. if ($key == 'name') {
  275. $propertyValueName = (string) $value;
  276. } elseif($key == 'value-type') {
  277. switch ($value) {
  278. case 'date' :
  279. $propertyValue = PHPExcel_DocumentProperties::convertProperty($propertyValue,'date');
  280. $propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_DATE;
  281. break;
  282. case 'boolean' :
  283. $propertyValue = PHPExcel_DocumentProperties::convertProperty($propertyValue,'bool');
  284. $propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_BOOLEAN;
  285. break;
  286. case 'float' :
  287. $propertyValue = PHPExcel_DocumentProperties::convertProperty($propertyValue,'r4');
  288. $propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_FLOAT;
  289. break;
  290. default :
  291. $propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_STRING;
  292. }
  293. }
  294. }
  295. $docProps->setCustomProperty($propertyValueName,$propertyValue,$propertyValueType);
  296. break;
  297. }
  298. }
  299. }
  300. // echo '<h1>Workbook Content</h1>';
  301. $xml = simplexml_load_string($zip->getFromName("content.xml"));
  302. $namespacesContent = $xml->getNamespaces(true);
  303. // echo '<pre>';
  304. // print_r($namespacesContent);
  305. // echo '</pre><hr />';
  306. $workbook = $xml->children($namespacesContent['office']);
  307. foreach($workbook->body->spreadsheet as $workbookData) {
  308. $workbookData = $workbookData->children($namespacesContent['table']);
  309. $worksheetID = 0;
  310. foreach($workbookData->table as $worksheetDataSet) {
  311. $worksheetData = $worksheetDataSet->children($namespacesContent['table']);
  312. // print_r($worksheetData);
  313. // echo '<br />';
  314. $worksheetDataAttributes = $worksheetDataSet->attributes($namespacesContent['table']);
  315. // print_r($worksheetDataAttributes);
  316. // echo '<br />';
  317. if ((isset($this->_loadSheetsOnly)) && (isset($worksheetDataAttributes['name'])) &&
  318. (!in_array($worksheetDataAttributes['name'], $this->_loadSheetsOnly))) {
  319. continue;
  320. }
  321. // echo '<h2>Worksheet '.$worksheetDataAttributes['name'].'</h2>';
  322. // Create new Worksheet
  323. $objPHPExcel->createSheet();
  324. $objPHPExcel->setActiveSheetIndex($worksheetID);
  325. if (isset($worksheetDataAttributes['name'])) {
  326. $worksheetName = (string) $worksheetDataAttributes['name'];
  327. // Use false for $updateFormulaCellReferences to prevent adjustment of worksheet references in
  328. // formula cells... during the load, all formulae should be correct, and we're simply
  329. // bringing the worksheet name in line with the formula, not the reverse
  330. $objPHPExcel->getActiveSheet()->setTitle($worksheetName,false);
  331. }
  332. $rowID = 1;
  333. foreach($worksheetData as $key => $rowData) {
  334. // echo '<b>'.$key.'</b><br />';
  335. switch ($key) {
  336. case 'table-header-rows':
  337. foreach ($rowData as $key=>$cellData) {
  338. $rowData = $cellData;
  339. break;
  340. }
  341. case 'table-row' :
  342. $rowDataTableAttributes = $rowData->attributes($namespacesContent['table']);
  343. $rowRepeats = (isset($rowDataTableAttributes['number-rows-repeated'])) ?
  344. $rowDataTableAttributes['number-rows-repeated'] : 1;
  345. $columnID = 'A';
  346. foreach($rowData as $key => $cellData) {
  347. if ($this->getReadFilter() !== NULL) {
  348. if (!$this->getReadFilter()->readCell($columnID, $rowID, $worksheetName)) {
  349. continue;
  350. }
  351. }
  352. // echo '<b>'.$columnID.$rowID.'</b><br />';
  353. $cellDataText = (isset($namespacesContent['text'])) ?
  354. $cellData->children($namespacesContent['text']) :
  355. '';
  356. $cellDataOffice = $cellData->children($namespacesContent['office']);
  357. $cellDataOfficeAttributes = $cellData->attributes($namespacesContent['office']);
  358. $cellDataTableAttributes = $cellData->attributes($namespacesContent['table']);
  359. // echo 'Office Attributes: ';
  360. // print_r($cellDataOfficeAttributes);
  361. // echo '<br />Table Attributes: ';
  362. // print_r($cellDataTableAttributes);
  363. // echo '<br />Cell Data Text';
  364. // print_r($cellDataText);
  365. // echo '<br />';
  366. //
  367. $type = $formatting = $hyperlink = null;
  368. $hasCalculatedValue = false;
  369. $cellDataFormula = '';
  370. if (isset($cellDataTableAttributes['formula'])) {
  371. $cellDataFormula = $cellDataTableAttributes['formula'];
  372. $hasCalculatedValue = true;
  373. }
  374. if (isset($cellDataOffice->annotation)) {
  375. // echo 'Cell has comment<br />';
  376. $annotationText = $cellDataOffice->annotation->children($namespacesContent['text']);
  377. $textArray = array();
  378. foreach($annotationText as $t) {
  379. foreach($t->span as $text) {
  380. $textArray[] = (string)$text;
  381. }
  382. }
  383. $text = implode("\n",$textArray);
  384. // echo $text,'<br />';
  385. $objPHPExcel->getActiveSheet()->getComment( $columnID.$rowID )
  386. // ->setAuthor( $author )
  387. ->setText($this->_parseRichText($text) );
  388. }
  389. if (isset($cellDataText->p)) {
  390. // Consolidate if there are multiple p records (maybe with spans as well)
  391. $dataArray = array();
  392. // Text can have multiple text:p and within those, multiple text:span.
  393. // text:p newlines, but text:span does not.
  394. // Also, here we assume there is no text data is span fields are specified, since
  395. // we have no way of knowing proper positioning anyway.
  396. foreach ($cellDataText->p as $pData) {
  397. if (isset($pData->span)) {
  398. // span sections do not newline, so we just create one large string here
  399. $spanSection = "";
  400. foreach ($pData->span as $spanData) {
  401. $spanSection .= $spanData;
  402. }
  403. array_push($dataArray, $spanSection);
  404. } else {
  405. array_push($dataArray, $pData);
  406. }
  407. }
  408. $allCellDataText = implode($dataArray, "\n");
  409. // echo 'Value Type is '.$cellDataOfficeAttributes['value-type'].'<br />';
  410. switch ($cellDataOfficeAttributes['value-type']) {
  411. case 'string' :
  412. $type = PHPExcel_Cell_DataType::TYPE_STRING;
  413. $dataValue = $allCellDataText;
  414. if (isset($dataValue->a)) {
  415. $dataValue = $dataValue->a;
  416. $cellXLinkAttributes = $dataValue->attributes($namespacesContent['xlink']);
  417. $hyperlink = $cellXLinkAttributes['href'];
  418. }
  419. break;
  420. case 'boolean' :
  421. $type = PHPExcel_Cell_DataType::TYPE_BOOL;
  422. $dataValue = ($allCellDataText == 'TRUE') ? True : False;
  423. break;
  424. case 'percentage' :
  425. $type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
  426. $dataValue = (float) $cellDataOfficeAttributes['value'];
  427. if (floor($dataValue) == $dataValue) {
  428. $dataValue = (integer) $dataValue;
  429. }
  430. $formatting = PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00;
  431. break;
  432. case 'currency' :
  433. $type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
  434. $dataValue = (float) $cellDataOfficeAttributes['value'];
  435. if (floor($dataValue) == $dataValue) {
  436. $dataValue = (integer) $dataValue;
  437. }
  438. $formatting = PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE;
  439. break;
  440. case 'float' :
  441. $type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
  442. $dataValue = (float) $cellDataOfficeAttributes['value'];
  443. if (floor($dataValue) == $dataValue) {
  444. if ($dataValue = (integer) $dataValue)
  445. $dataValue = (integer) $dataValue;
  446. else
  447. $dataValue = (float) $dataValue;
  448. }
  449. break;
  450. case 'date' :
  451. $type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
  452. $dateObj = new DateTime($cellDataOfficeAttributes['date-value'], $GMT);
  453. $dateObj->setTimeZone($timezoneObj);
  454. list($year,$month,$day,$hour,$minute,$second) = explode(' ',$dateObj->format('Y m d H i s'));
  455. $dataValue = PHPExcel_Shared_Date::FormattedPHPToExcel($year,$month,$day,$hour,$minute,$second);
  456. if ($dataValue != floor($dataValue)) {
  457. $formatting = PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15.' '.PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4;
  458. } else {
  459. $formatting = PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15;
  460. }
  461. break;
  462. case 'time' :
  463. $type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
  464. $dataValue = PHPExcel_Shared_Date::PHPToExcel(strtotime('01-01-1970 '.implode(':',sscanf($cellDataOfficeAttributes['time-value'],'PT%dH%dM%dS'))));
  465. $formatting = PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4;
  466. break;
  467. }
  468. // echo 'Data value is '.$dataValue.'<br />';
  469. // if ($hyperlink !== NULL) {
  470. // echo 'Hyperlink is '.$hyperlink.'<br />';
  471. // }
  472. } else {
  473. $type = PHPExcel_Cell_DataType::TYPE_NULL;
  474. $dataValue = NULL;
  475. }
  476. if ($hasCalculatedValue) {
  477. $type = PHPExcel_Cell_DataType::TYPE_FORMULA;
  478. // echo 'Formula: '.$cellDataFormula.'<br />';
  479. $cellDataFormula = substr($cellDataFormula,strpos($cellDataFormula,':=')+1);
  480. $temp = explode('"',$cellDataFormula);
  481. $tKey = false;
  482. foreach($temp as &$value) {
  483. // Only replace in alternate array entries (i.e. non-quoted blocks)
  484. if ($tKey = !$tKey) {
  485. $value = preg_replace('/\[\.(.*):\.(.*)\]/Ui','$1:$2',$value);
  486. $value = preg_replace('/\[\.(.*)\]/Ui','$1',$value);
  487. $value = PHPExcel_Calculation::_translateSeparator(';',',',$value,$inBraces);
  488. }
  489. }
  490. unset($value);
  491. // Then rebuild the formula string
  492. $cellDataFormula = implode('"',$temp);
  493. // echo 'Adjusted Formula: '.$cellDataFormula.'<br />';
  494. }
  495. $colRepeats = (isset($cellDataTableAttributes['number-columns-repeated'])) ?
  496. $cellDataTableAttributes['number-columns-repeated'] : 1;
  497. if ($type !== NULL) {
  498. for ($i = 0; $i < $colRepeats; ++$i) {
  499. if ($i > 0) {
  500. ++$columnID;
  501. }
  502. if ($type !== PHPExcel_Cell_DataType::TYPE_NULL) {
  503. for ($rowAdjust = 0; $rowAdjust < $rowRepeats; ++$rowAdjust) {
  504. $rID = $rowID + $rowAdjust;
  505. $objPHPExcel->getActiveSheet()->getCell($columnID.$rID)->setValueExplicit((($hasCalculatedValue) ? $cellDataFormula : $dataValue),$type);
  506. if ($hasCalculatedValue) {
  507. // echo 'Forumla result is '.$dataValue.'<br />';
  508. $objPHPExcel->getActiveSheet()->getCell($columnID.$rID)->setCalculatedValue($dataValue);
  509. }
  510. if ($formatting !== NULL) {
  511. $objPHPExcel->getActiveSheet()->getStyle($columnID.$rID)->getNumberFormat()->setFormatCode($formatting);
  512. } else {
  513. $objPHPExcel->getActiveSheet()->getStyle($columnID.$rID)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_GENERAL);
  514. }
  515. if ($hyperlink !== NULL) {
  516. $objPHPExcel->getActiveSheet()->getCell($columnID.$rID)->getHyperlink()->setUrl($hyperlink);
  517. }
  518. }
  519. }
  520. }
  521. }
  522. // Merged cells
  523. if ((isset($cellDataTableAttributes['number-columns-spanned'])) || (isset($cellDataTableAttributes['number-rows-spanned']))) {
  524. if (($type !== PHPExcel_Cell_DataType::TYPE_NULL) || (!$this->_readDataOnly)) {
  525. $columnTo = $columnID;
  526. if (isset($cellDataTableAttributes['number-columns-spanned'])) {
  527. $columnTo = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($columnID) + $cellDataTableAttributes['number-columns-spanned'] -2);
  528. }
  529. $rowTo = $rowID;
  530. if (isset($cellDataTableAttributes['number-rows-spanned'])) {
  531. $rowTo = $rowTo + $cellDataTableAttributes['number-rows-spanned'] - 1;
  532. }
  533. $cellRange = $columnID.$rowID.':'.$columnTo.$rowTo;
  534. $objPHPExcel->getActiveSheet()->mergeCells($cellRange);
  535. }
  536. }
  537. ++$columnID;
  538. }
  539. $rowID += $rowRepeats;
  540. break;
  541. }
  542. }
  543. ++$worksheetID;
  544. }
  545. }
  546. }
  547. // Return
  548. return $objPHPExcel;
  549. }
  550. private function _parseRichText($is = '') {
  551. $value = new PHPExcel_RichText();
  552. $value->createText($is);
  553. return $value;
  554. }
  555. }