PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/add-ons/PHPExcel/PHPExcel/Reader/Excel2003XML.php

https://github.com/jcplat/console-seolan
PHP | 630 lines | 400 code | 47 blank | 183 comment | 68 complexity | e15245ba7f261f965ab10882796dd47d MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, GPL-3.0, Apache-2.0, BSD-3-Clause
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2009 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 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version 1.7.1, 2009-11-02
  26. */
  27. /** PHPExcel root directory */
  28. if (!defined('PHPEXCEL_ROOT')) {
  29. /**
  30. * @ignore
  31. */
  32. define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
  33. }
  34. /** PHPExcel */
  35. require_once PHPEXCEL_ROOT . 'PHPExcel.php';
  36. /** PHPExcel_Reader_IReader */
  37. require_once PHPEXCEL_ROOT . 'PHPExcel/Reader/IReader.php';
  38. /** PHPExcel_Worksheet */
  39. require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet.php';
  40. /** PHPExcel_Cell */
  41. require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
  42. /** PHPExcel_Calculation */
  43. require_once PHPEXCEL_ROOT . 'PHPExcel/Calculation.php';
  44. /** PHPExcel_Reader_DefaultReadFilter */
  45. require_once PHPEXCEL_ROOT . 'PHPExcel/Reader/DefaultReadFilter.php';
  46. /**
  47. * PHPExcel_Reader_Excel2003XML
  48. *
  49. * @category PHPExcel
  50. * @package PHPExcel_Reader
  51. * @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  52. */
  53. class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
  54. {
  55. /**
  56. * Input encoding
  57. *
  58. * @var string
  59. */
  60. private $_inputEncoding;
  61. /**
  62. * Sheet index to read
  63. *
  64. * @var int
  65. */
  66. private $_sheetIndex;
  67. /**
  68. * Formats
  69. *
  70. * @var array
  71. */
  72. private $_styles = array();
  73. /**
  74. * PHPExcel_Reader_IReadFilter instance
  75. *
  76. * @var PHPExcel_Reader_IReadFilter
  77. */
  78. private $_readFilter = null;
  79. /**
  80. * Create a new PHPExcel_Reader_Excel2003XML
  81. */
  82. public function __construct() {
  83. $this->_sheetIndex = 0;
  84. $this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
  85. }
  86. /**
  87. * Can the current PHPExcel_Reader_IReader read the file?
  88. *
  89. * @param string $pFileName
  90. * @return boolean
  91. */
  92. public function canRead($pFilename)
  93. {
  94. // Office xmlns:o="urn:schemas-microsoft-com:office:office"
  95. // Excel xmlns:x="urn:schemas-microsoft-com:office:excel"
  96. // XML Spreadsheet xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
  97. // Spreadsheet component xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet"
  98. // XML schema xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
  99. // XML data type xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
  100. // MS-persist recordset xmlns:rs="urn:schemas-microsoft-com:rowset"
  101. // Rowset xmlns:z="#RowsetSchema"
  102. //
  103. $signature = array(
  104. '<?xml version="1.0"?>',
  105. '<?mso-application progid="Excel.Sheet"?>'
  106. );
  107. // Check if file exists
  108. if (!file_exists($pFilename)) {
  109. throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
  110. }
  111. // Read sample data (first 2 KB will do)
  112. $fh = fopen($pFilename, 'r');
  113. $data = fread($fh, 2048);
  114. fclose($fh);
  115. $headers = explode("\n",$data);
  116. $valid = true;
  117. foreach($signature as $key => $match) {
  118. if (isset($headers[$key])) {
  119. $line = trim(rtrim($headers[$key], "\r\n"));
  120. if ($line != $match) {
  121. $valid = false;
  122. break;
  123. }
  124. } else {
  125. $valid = false;
  126. break;
  127. }
  128. }
  129. return $valid;
  130. }
  131. /**
  132. * Loads PHPExcel from file
  133. *
  134. * @param string $pFilename
  135. * @throws Exception
  136. */
  137. public function load($pFilename)
  138. {
  139. // Create new PHPExcel
  140. $objPHPExcel = new PHPExcel();
  141. // Load into this instance
  142. return $this->loadIntoExisting($pFilename, $objPHPExcel);
  143. }
  144. /**
  145. * Read filter
  146. *
  147. * @return PHPExcel_Reader_IReadFilter
  148. */
  149. public function getReadFilter() {
  150. return $this->_readFilter;
  151. }
  152. /**
  153. * Set read filter
  154. *
  155. * @param PHPExcel_Reader_IReadFilter $pValue
  156. */
  157. public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue) {
  158. $this->_readFilter = $pValue;
  159. }
  160. private static function identifyFixedStyleValue($styleList,&$styleAttributeValue) {
  161. $styleAttributeValue = strtolower($styleAttributeValue);
  162. foreach($styleList as $style) {
  163. if ($styleAttributeValue == strtolower($style)) {
  164. $styleAttributeValue = $style;
  165. return true;
  166. }
  167. }
  168. return false;
  169. }
  170. /**
  171. * pixel units to excel width units(units of 1/256th of a character width)
  172. * @param pxs
  173. * @return
  174. */
  175. private static function _pixel2WidthUnits($pxs) {
  176. $UNIT_OFFSET_MAP = array(0, 36, 73, 109, 146, 182, 219);
  177. $widthUnits = 256 * ($pxs / 7);
  178. $widthUnits += $UNIT_OFFSET_MAP[($pxs % 7)];
  179. return $widthUnits;
  180. }
  181. /**
  182. * excel width units(units of 1/256th of a character width) to pixel units
  183. * @param widthUnits
  184. * @return
  185. */
  186. private static function _widthUnits2Pixel($widthUnits) {
  187. $pixels = ($widthUnits / 256) * 7;
  188. $offsetWidthUnits = $widthUnits % 256;
  189. $pixels += round($offsetWidthUnits / (256 / 7));
  190. return $pixels;
  191. }
  192. /**
  193. * Loads PHPExcel from file into PHPExcel instance
  194. *
  195. * @param string $pFilename
  196. * @param PHPExcel $objPHPExcel
  197. * @throws Exception
  198. */
  199. public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
  200. {
  201. $fromFormats = array('\-', '\ ');
  202. $toFormats = array('-', ' ');
  203. $underlineStyles = array (
  204. PHPExcel_Style_Font::UNDERLINE_NONE,
  205. PHPExcel_Style_Font::UNDERLINE_DOUBLE,
  206. PHPExcel_Style_Font::UNDERLINE_DOUBLEACCOUNTING,
  207. PHPExcel_Style_Font::UNDERLINE_SINGLE,
  208. PHPExcel_Style_Font::UNDERLINE_SINGLEACCOUNTING
  209. );
  210. $verticalAlignmentStyles = array (
  211. PHPExcel_Style_Alignment::VERTICAL_BOTTOM,
  212. PHPExcel_Style_Alignment::VERTICAL_TOP,
  213. PHPExcel_Style_Alignment::VERTICAL_CENTER,
  214. PHPExcel_Style_Alignment::VERTICAL_JUSTIFY
  215. );
  216. $horizontalAlignmentStyles = array (
  217. PHPExcel_Style_Alignment::HORIZONTAL_GENERAL,
  218. PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
  219. PHPExcel_Style_Alignment::HORIZONTAL_RIGHT,
  220. PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
  221. PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS,
  222. PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY
  223. );
  224. // Check if file exists
  225. if (!file_exists($pFilename)) {
  226. throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
  227. }
  228. $xml = simplexml_load_file($pFilename);
  229. $namespaces = $xml->getNamespaces(true);
  230. // echo '<pre>';
  231. // print_r($namespaces);
  232. // echo '</pre><hr />';
  233. //
  234. // echo '<pre>';
  235. // print_r($xml);
  236. // echo '</pre><hr />';
  237. //
  238. $docProps = $objPHPExcel->getProperties();
  239. foreach($xml->DocumentProperties[0] as $propertyName => $propertyValue) {
  240. switch ($propertyName) {
  241. case 'Title' :
  242. $docProps->setTitle($propertyValue);
  243. break;
  244. case 'Subject' :
  245. $docProps->setSubject($propertyValue);
  246. break;
  247. case 'Author' :
  248. $docProps->setCreator($propertyValue);
  249. break;
  250. case 'Created' :
  251. $creationDate = strtotime($propertyValue);
  252. $docProps->setCreated($creationDate);
  253. break;
  254. case 'LastAuthor' :
  255. $docProps->setLastModifiedBy($propertyValue);
  256. break;
  257. case 'Company' :
  258. $docProps->setCompany($propertyValue);
  259. break;
  260. case 'Category' :
  261. $docProps->setCategory($propertyValue);
  262. break;
  263. case 'Keywords' :
  264. $docProps->setKeywords($propertyValue);
  265. break;
  266. case 'Description' :
  267. $docProps->setDescription($propertyValue);
  268. break;
  269. }
  270. }
  271. foreach($xml->Styles[0] as $style) {
  272. $style_ss = $style->attributes($namespaces['ss']);
  273. $styleID = (string) $style_ss['ID'];
  274. // echo 'Style ID = '.$styleID.'<br />';
  275. if ($styleID == 'Default') {
  276. $this->_styles['Default'] = array();
  277. } else {
  278. $this->_styles[$styleID] = $this->_styles['Default'];
  279. }
  280. foreach ($style as $styleType => $styleData) {
  281. $styleAttributes = $styleData->attributes($namespaces['ss']);
  282. // echo $styleType.'<br />';
  283. switch ($styleType) {
  284. case 'Alignment' :
  285. foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
  286. // echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
  287. $styleAttributeValue = (string) $styleAttributeValue;
  288. switch ($styleAttributeKey) {
  289. case 'Vertical' :
  290. if (self::identifyFixedStyleValue($verticalAlignmentStyles,$styleAttributeValue)) {
  291. $this->_styles[$styleID]['alignment']['vertical'] = $styleAttributeValue;
  292. }
  293. break;
  294. case 'Horizontal' :
  295. if (self::identifyFixedStyleValue($horizontalAlignmentStyles,$styleAttributeValue)) {
  296. $this->_styles[$styleID]['alignment']['horizontal'] = $styleAttributeValue;
  297. }
  298. break;
  299. case 'WrapText' :
  300. $this->_styles[$styleID]['alignment']['wrap'] = true;
  301. break;
  302. }
  303. }
  304. break;
  305. case 'Borders' :
  306. foreach($styleData->Border as $borderStyle) {
  307. $borderAttributes = $borderStyle->attributes($namespaces['ss']);
  308. $thisBorder = array();
  309. foreach($borderAttributes as $borderStyleKey => $borderStyleValue) {
  310. // echo $borderStyleKey.' = '.$borderStyleValue.'<br />';
  311. switch ($borderStyleKey) {
  312. case 'LineStyle' :
  313. $thisBorder['style'] = PHPExcel_Style_Border::BORDER_MEDIUM;
  314. // $thisBorder['style'] = $borderStyleValue;
  315. break;
  316. case 'Weight' :
  317. // $thisBorder['style'] = $borderStyleValue;
  318. break;
  319. case 'Position' :
  320. $borderPosition = strtolower($borderStyleValue);
  321. break;
  322. case 'Color' :
  323. $borderColour = substr($borderStyleValue,1);
  324. $thisBorder['color']['rgb'] = $borderColour;
  325. break;
  326. }
  327. }
  328. if (count($thisBorder) > 0) {
  329. if (($borderPosition == 'left') || ($borderPosition == 'right') || ($borderPosition == 'top') || ($borderPosition == 'bottom')) {
  330. $this->_styles[$styleID]['borders'][$borderPosition] = $thisBorder;
  331. }
  332. }
  333. }
  334. break;
  335. case 'Font' :
  336. foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
  337. // echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
  338. $styleAttributeValue = (string) $styleAttributeValue;
  339. switch ($styleAttributeKey) {
  340. case 'FontName' :
  341. $this->_styles[$styleID]['font']['name'] = $styleAttributeValue;
  342. break;
  343. case 'Size' :
  344. $this->_styles[$styleID]['font']['size'] = $styleAttributeValue;
  345. break;
  346. case 'Color' :
  347. $this->_styles[$styleID]['font']['color']['rgb'] = substr($styleAttributeValue,1);
  348. break;
  349. case 'Bold' :
  350. $this->_styles[$styleID]['font']['bold'] = true;
  351. break;
  352. case 'Italic' :
  353. $this->_styles[$styleID]['font']['italic'] = true;
  354. break;
  355. case 'Underline' :
  356. if (self::identifyFixedStyleValue($underlineStyles,$styleAttributeValue)) {
  357. $this->_styles[$styleID]['font']['underline'] = $styleAttributeValue;
  358. }
  359. break;
  360. }
  361. }
  362. break;
  363. case 'Interior' :
  364. foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
  365. // echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
  366. switch ($styleAttributeKey) {
  367. case 'Color' :
  368. $this->_styles[$styleID]['fill']['color']['rgb'] = substr($styleAttributeValue,1);
  369. break;
  370. }
  371. }
  372. break;
  373. case 'NumberFormat' :
  374. foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
  375. // echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
  376. $styleAttributeValue = str_replace($fromFormats,$toFormats,$styleAttributeValue);
  377. switch ($styleAttributeValue) {
  378. case 'Short Date' :
  379. $styleAttributeValue = 'dd/mm/yyyy';
  380. break;
  381. }
  382. if ($styleAttributeValue > '') {
  383. $this->_styles[$styleID]['numberformat']['code'] = $styleAttributeValue;
  384. }
  385. }
  386. break;
  387. case 'Protection' :
  388. foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
  389. // echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
  390. }
  391. break;
  392. }
  393. }
  394. // print_r($this->_styles[$styleID]);
  395. // echo '<hr />';
  396. }
  397. // echo '<hr />';
  398. $worksheetID = 0;
  399. foreach($xml->Worksheet as $worksheet) {
  400. // Create new Worksheet
  401. $objPHPExcel->createSheet();
  402. $objPHPExcel->setActiveSheetIndex($worksheetID);
  403. $worksheet_ss = $worksheet->attributes($namespaces['ss']);
  404. if (isset($worksheet_ss['Name'])) {
  405. $worksheetName = $worksheet_ss['Name'];
  406. $objPHPExcel->getActiveSheet()->setTitle($worksheetName);
  407. }
  408. $columnID = 'A';
  409. foreach($worksheet->Table->Column as $columnData) {
  410. $columnData_ss = $columnData->attributes($namespaces['ss']);
  411. if (isset($columnData_ss['Index'])) {
  412. $columnID = PHPExcel_Cell::stringFromColumnIndex($columnData_ss['Index']-1);
  413. }
  414. if (isset($columnData_ss['Width'])) {
  415. $columnWidth = $columnData_ss['Width'];
  416. // echo '<b>Setting column width for '.$columnID.' to '.$columnWidth.'</b><br />';
  417. $objPHPExcel->getActiveSheet()->getColumnDimension($columnID)->setWidth($columnWidth / 5.4);
  418. }
  419. ++$columnID;
  420. }
  421. $rowID = 1;
  422. foreach($worksheet->Table->Row as $rowData) {
  423. $row_ss = $rowData->attributes($namespaces['ss']);
  424. if (isset($row_ss['Index'])) {
  425. $rowID = (integer) $row_ss['Index'];
  426. }
  427. // echo '<b>Row '.$rowID.'</b><br />';
  428. if (isset($row_ss['StyleID'])) {
  429. $rowStyle = $row_ss['StyleID'];
  430. }
  431. if (isset($row_ss['Height'])) {
  432. $rowHeight = $row_ss['Height'];
  433. // echo '<b>Setting row height to '.$rowHeight.'</b><br />';
  434. $objPHPExcel->getActiveSheet()->getRowDimension($rowID)->setRowHeight($rowHeight);
  435. }
  436. $columnID = 'A';
  437. foreach($rowData->Cell as $cell) {
  438. $cell_ss = $cell->attributes($namespaces['ss']);
  439. if (isset($cell_ss['Index'])) {
  440. $columnID = PHPExcel_Cell::stringFromColumnIndex($cell_ss['Index']-1);
  441. }
  442. $cellRange = $columnID.$rowID;
  443. if ((isset($cell_ss['MergeAcross'])) || (isset($cell_ss['MergeDown']))) {
  444. $columnTo = $columnID;
  445. if (isset($cell_ss['MergeAcross'])) {
  446. $columnTo = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($columnID) + $cell_ss['MergeAcross'] -1);
  447. }
  448. $rowTo = $rowID;
  449. if (isset($cell_ss['MergeDown'])) {
  450. $rowTo = $rowTo + $cell_ss['MergeDown'];
  451. }
  452. $cellRange .= ':'.$columnTo.$rowTo;
  453. $objPHPExcel->getActiveSheet()->mergeCells($cellRange);
  454. }
  455. $hasCalculatedValue = false;
  456. $cellDataFormula = '';
  457. if (isset($cell_ss['Formula'])) {
  458. $cellDataFormula = $cell_ss['Formula'];
  459. $hasCalculatedValue = true;
  460. }
  461. if (isset($cell->Data)) {
  462. $cellValue = $cellData = $cell->Data;
  463. $type = PHPExcel_Cell_DataType::TYPE_NULL;
  464. $cellData_ss = $cellData->attributes($namespaces['ss']);
  465. if (isset($cellData_ss['Type'])) {
  466. $cellDataType = $cellData_ss['Type'];
  467. switch ($cellDataType) {
  468. /*
  469. const TYPE_STRING = 's';
  470. const TYPE_FORMULA = 'f';
  471. const TYPE_NUMERIC = 'n';
  472. const TYPE_BOOL = 'b';
  473. const TYPE_NULL = 's';
  474. const TYPE_INLINE = 'inlineStr';
  475. const TYPE_ERROR = 'e';
  476. */
  477. case 'String' :
  478. $type = PHPExcel_Cell_DataType::TYPE_STRING;
  479. break;
  480. case 'Number' :
  481. $type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
  482. $cellValue = (float) $cellValue;
  483. if (floor($cellValue) == $cellValue) {
  484. $cellValue = (integer) $cellValue;
  485. }
  486. break;
  487. case 'Boolean' :
  488. $type = PHPExcel_Cell_DataType::TYPE_BOOL;
  489. $cellValue = ($cellValue != 0);
  490. break;
  491. case 'DateTime' :
  492. $type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
  493. $cellValue = PHPExcel_Shared_Date::PHPToExcel(strtotime($cellValue));
  494. break;
  495. case 'Error' :
  496. $type = PHPExcel_Cell_DataType::TYPE_ERROR;
  497. break;
  498. }
  499. }
  500. if ($hasCalculatedValue) {
  501. $type = PHPExcel_Cell_DataType::TYPE_FORMULA;
  502. $columnNumber = PHPExcel_Cell::columnIndexFromString($columnID);
  503. // Convert R1C1 style references to A1 style references (but only when not quoted)
  504. $temp = explode('"',$cellDataFormula);
  505. foreach($temp as $key => &$value) {
  506. // Only replace in alternate array entries (i.e. non-quoted blocks)
  507. if (($key % 2) == 0) {
  508. preg_match_all('/(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))/',$value, $cellReferences,PREG_SET_ORDER+PREG_OFFSET_CAPTURE);
  509. // Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way
  510. // through the formula from left to right. Reversing means that we work right to left.through
  511. // the formula
  512. $cellReferences = array_reverse($cellReferences);
  513. // Loop through each R1C1 style reference in turn, converting it to its A1 style equivalent,
  514. // then modify the formula to use that new reference
  515. foreach($cellReferences as $cellReference) {
  516. $rowReference = $cellReference[2][0];
  517. // Empty R reference is the current row
  518. if ($rowReference == '') $rowReference = $rowID;
  519. // Bracketed R references are relative to the current row
  520. if ($rowReference{0} == '[') $rowReference = $rowID + trim($rowReference,'[]');
  521. $columnReference = $cellReference[4][0];
  522. // Empty C reference is the current column
  523. if ($columnReference == '') $columnReference = $columnNumber;
  524. // Bracketed C references are relative to the current column
  525. if ($columnReference{0} == '[') $columnReference = $columnNumber + trim($columnReference,'[]');
  526. $A1CellReference = PHPExcel_Cell::stringFromColumnIndex($columnReference-1).$rowReference;
  527. $value = substr_replace($value,$A1CellReference,$cellReference[0][1],strlen($cellReference[0][0]));
  528. }
  529. }
  530. }
  531. unset($value);
  532. // Then rebuild the formula string
  533. $cellDataFormula = implode('"',$temp);
  534. }
  535. // echo 'Cell '.$columnID.$rowID.' is a '.$type.' with a value of '.(($hasCalculatedValue) ? $cellDataFormula : $cellValue).'<br />';
  536. //
  537. $objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setValueExplicit((($hasCalculatedValue) ? $cellDataFormula : $cellValue),$type);
  538. if ($hasCalculatedValue) {
  539. // echo 'Forumla result is '.$cellValue.'<br />';
  540. $objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setCalculatedValue($cellValue);
  541. }
  542. }
  543. if (isset($cell_ss['StyleID'])) {
  544. $style = (string) $cell_ss['StyleID'];
  545. // echo 'Cell style for '.$columnID.$rowID.' is '.$style.'<br />';
  546. if ((isset($this->_styles[$style])) && (count($this->_styles[$style]) > 0)) {
  547. // echo 'Cell '.$columnID.$rowID.'<br />';
  548. // print_r($this->_styles[$style]);
  549. // echo '<br />';
  550. if (!$objPHPExcel->getActiveSheet()->cellExists($columnID.$rowID)) {
  551. $objPHPExcel->getActiveSheet()->setCellValue($columnID.$rowID,NULL);
  552. }
  553. $objPHPExcel->getActiveSheet()->getStyle($cellRange)->applyFromArray($this->_styles[$style]);
  554. }
  555. }
  556. ++$columnID;
  557. }
  558. ++$rowID;
  559. }
  560. ++$worksheetID;
  561. }
  562. // Return
  563. return $objPHPExcel;
  564. }
  565. /**
  566. * Get sheet index
  567. *
  568. * @return int
  569. */
  570. public function getSheetIndex() {
  571. return $this->_sheetIndex;
  572. }
  573. /**
  574. * Set sheet index
  575. *
  576. * @param int $pValue Sheet index
  577. * @return PHPExcel_Reader_Excel2003XML
  578. */
  579. public function setSheetIndex($pValue = 0) {
  580. $this->_sheetIndex = $pValue;
  581. return $this;
  582. }
  583. }