PageRenderTime 62ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 1ms

/common/libraries/plugin/phpexcel/PHPExcel/Writer/Excel5/Worksheet.php

https://bitbucket.org/renaatdemuynck/chamilo
PHP | 3219 lines | 1809 code | 520 blank | 890 comment | 198 complexity | b35029b0d540da09107c2df163036e4d MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, LGPL-3.0, GPL-3.0, MIT, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2011 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_Writer_Excel5
  23. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version 1.7.6, 2011-02-27
  26. */
  27. // Original file header of PEAR::Spreadsheet_Excel_Writer_Worksheet (used as the base for this class):
  28. // -----------------------------------------------------------------------------------------
  29. // /*
  30. // * Module written/ported by Xavier Noguer <xnoguer@rezebra.com>
  31. // *
  32. // * The majority of this is _NOT_ my code. I simply ported it from the
  33. // * PERL Spreadsheet::WriteExcel module.
  34. // *
  35. // * The author of the Spreadsheet::WriteExcel module is John McNamara
  36. // * <jmcnamara@cpan.org>
  37. // *
  38. // * I _DO_ maintain this code, and John McNamara has nothing to do with the
  39. // * porting of this code to PHP. Any questions directly related to this
  40. // * class library should be directed to me.
  41. // *
  42. // * License Information:
  43. // *
  44. // * Spreadsheet_Excel_Writer: A library for generating Excel Spreadsheets
  45. // * Copyright (c) 2002-2003 Xavier Noguer xnoguer@rezebra.com
  46. // *
  47. // * This library is free software; you can redistribute it and/or
  48. // * modify it under the terms of the GNU Lesser General Public
  49. // * License as published by the Free Software Foundation; either
  50. // * version 2.1 of the License, or (at your option) any later version.
  51. // *
  52. // * This library is distributed in the hope that it will be useful,
  53. // * but WITHOUT ANY WARRANTY; without even the implied warranty of
  54. // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  55. // * Lesser General Public License for more details.
  56. // *
  57. // * You should have received a copy of the GNU Lesser General Public
  58. // * License along with this library; if not, write to the Free Software
  59. // * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  60. // */
  61. /**
  62. * PHPExcel_Writer_Excel5_Worksheet
  63. *
  64. * @category PHPExcel
  65. * @package PHPExcel_Writer_Excel5
  66. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  67. */
  68. class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
  69. {
  70. /**
  71. * Formula parser
  72. *
  73. * @var PHPExcel_Writer_Excel5_Parser
  74. */
  75. private $_parser;
  76. /**
  77. * Maximum number of characters for a string (LABEL record in BIFF5)
  78. * @var integer
  79. */
  80. public $_xls_strmax;
  81. /**
  82. * Array containing format information for columns
  83. * @var array
  84. */
  85. public $_colinfo;
  86. /**
  87. * Array containing the selected area for the worksheet
  88. * @var array
  89. */
  90. public $_selection;
  91. /**
  92. * The active pane for the worksheet
  93. * @var integer
  94. */
  95. public $_active_pane;
  96. /**
  97. * Whether to use outline.
  98. * @var integer
  99. */
  100. public $_outline_on;
  101. /**
  102. * Auto outline styles.
  103. * @var bool
  104. */
  105. public $_outline_style;
  106. /**
  107. * Whether to have outline summary below.
  108. * @var bool
  109. */
  110. public $_outline_below;
  111. /**
  112. * Whether to have outline summary at the right.
  113. * @var bool
  114. */
  115. public $_outline_right;
  116. /**
  117. * Reference to the total number of strings in the workbook
  118. * @var integer
  119. */
  120. public $_str_total;
  121. /**
  122. * Reference to the number of unique strings in the workbook
  123. * @var integer
  124. */
  125. public $_str_unique;
  126. /**
  127. * Reference to the array containing all the unique strings in the workbook
  128. * @var array
  129. */
  130. public $_str_table;
  131. /**
  132. * Color cache
  133. */
  134. private $_colors;
  135. /**
  136. * Index of first used row (at least 0)
  137. * @var int
  138. */
  139. private $_firstRowIndex;
  140. /**
  141. * Index of last used row. (no used rows means -1)
  142. * @var int
  143. */
  144. private $_lastRowIndex;
  145. /**
  146. * Index of first used column (at least 0)
  147. * @var int
  148. */
  149. private $_firstColumnIndex;
  150. /**
  151. * Index of last used column (no used columns means -1)
  152. * @var int
  153. */
  154. private $_lastColumnIndex;
  155. /**
  156. * Sheet object
  157. * @var PHPExcel_Worksheet
  158. */
  159. private $_phpSheet;
  160. /**
  161. * Count cell style Xfs
  162. *
  163. * @var int
  164. */
  165. private $_countCellStyleXfs;
  166. /**
  167. * Escher object corresponding to MSODRAWING
  168. *
  169. * @var PHPExcel_Shared_Escher
  170. */
  171. private $_escher;
  172. /**
  173. * Constructor
  174. *
  175. * @param int $BIFF_version BIFF version
  176. * @param int $str_total Total number of strings
  177. * @param int $str_unique Total number of unique strings
  178. * @param array $str_table
  179. * @param mixed $parser The formula parser created for the Workbook
  180. * @param string $tempDir The temporary directory to be used
  181. * @param PHPExcel_Worksheet $phpSheet
  182. */
  183. public function __construct($BIFF_version, &$str_total, &$str_unique, &$str_table, &$colors, $parser, $preCalculateFormulas, $phpSheet)
  184. {
  185. // It needs to call its parent's constructor explicitly
  186. parent :: __construct();
  187. $this->_BIFF_version = $BIFF_version;
  188. if ($BIFF_version == 0x0600)
  189. {
  190. // change BIFFwriter limit for CONTINUE records
  191. $this->_limit = 8224;
  192. }
  193. $this->_preCalculateFormulas = $preCalculateFormulas;
  194. $this->_str_total = &$str_total;
  195. $this->_str_unique = &$str_unique;
  196. $this->_str_table = &$str_table;
  197. $this->_colors = &$colors;
  198. $this->_parser = $parser;
  199. $this->_phpSheet = $phpSheet;
  200. //$this->ext_sheets = array();
  201. //$this->offset = 0;
  202. $this->_xls_strmax = 255;
  203. $this->_colinfo = array();
  204. $this->_selection = array(0, 0, 0, 0);
  205. $this->_active_pane = 3;
  206. $this->_print_headers = 0;
  207. $this->_outline_style = 0;
  208. $this->_outline_below = 1;
  209. $this->_outline_right = 1;
  210. $this->_outline_on = 1;
  211. // calculate values for DIMENSIONS record
  212. $col = $row = array();
  213. foreach ($this->_phpSheet->getCellCollection(false) as $cellID)
  214. {
  215. list($c, $r) = sscanf($cellID, '%[A-Z]%d');
  216. $row[$r] = $r;
  217. $col[$c] = strlen($c) . $c;
  218. }
  219. // Determine lowest and highest column and row
  220. $this->_firstRowIndex = (count($row) > 0) ? min($row) : 1;
  221. $this->_lastRowIndex = (count($row) > 0) ? max($row) : 1;
  222. if ($this->_firstRowIndex > 65535)
  223. $this->_firstRowIndex = 65535;
  224. if ($this->_lastRowIndex > 65535)
  225. $this->_lastRowIndex = 65535;
  226. $this->_firstColumnIndex = (count($col) > 0) ? PHPExcel_Cell :: columnIndexFromString(substr(min($col), 1)) : 1;
  227. $this->_lastColumnIndex = (count($col) > 0) ? PHPExcel_Cell :: columnIndexFromString(substr(max($col), 1)) : 1;
  228. if ($this->_firstColumnIndex > 255)
  229. $this->_firstColumnIndex = 255;
  230. if ($this->_lastColumnIndex > 255)
  231. $this->_lastColumnIndex = 255;
  232. $this->_countCellStyleXfs = count($phpSheet->getParent()->getCellStyleXfCollection());
  233. }
  234. /**
  235. * Add data to the beginning of the workbook (note the reverse order)
  236. * and to the end of the workbook.
  237. *
  238. * @access public
  239. * @see PHPExcel_Writer_Excel5_Workbook::storeWorkbook()
  240. */
  241. function close()
  242. {
  243. $num_sheets = $this->_phpSheet->getParent()->getSheetCount();
  244. // Write BOF record
  245. $this->_storeBof(0x0010);
  246. // Write PRINTHEADERS
  247. $this->_writePrintHeaders();
  248. // Write PRINTGRIDLINES
  249. $this->_writePrintGridlines();
  250. // Write GRIDSET
  251. $this->_writeGridset();
  252. // Calculate column widths
  253. $this->_phpSheet->calculateColumnWidths();
  254. // Column dimensions
  255. $maxCol = PHPExcel_Cell :: columnIndexFromString($this->_phpSheet->getHighestColumn()) - 1;
  256. $columnDimensions = $this->_phpSheet->getColumnDimensions();
  257. for($i = 0; $i <= $maxCol; ++ $i)
  258. {
  259. $hidden = 0;
  260. $level = 0;
  261. $xfIndex = 15; // there are 15 cell style Xfs
  262. if ($this->_phpSheet->getDefaultColumnDimension()->getWidth() >= 0)
  263. {
  264. $width = $this->_phpSheet->getDefaultColumnDimension()->getWidth();
  265. }
  266. else
  267. {
  268. $width = PHPExcel_Shared_Font :: getDefaultColumnWidthByFont($this->_phpSheet->getParent()->getDefaultStyle()->getFont());
  269. }
  270. $columnLetter = PHPExcel_Cell :: stringFromColumnIndex($i);
  271. if (isset($columnDimensions[$columnLetter]))
  272. {
  273. $columnDimension = $columnDimensions[$columnLetter];
  274. if ($columnDimension->getWidth() >= 0)
  275. {
  276. $width = $columnDimension->getWidth();
  277. }
  278. $hidden = $columnDimension->getVisible() ? 0 : 1;
  279. $level = $columnDimension->getOutlineLevel();
  280. $xfIndex = $columnDimension->getXfIndex() + 15; // there are 15 cell style Xfs
  281. }
  282. // Components of _colinfo:
  283. // $firstcol first column on the range
  284. // $lastcol last column on the range
  285. // $width width to set
  286. // $xfIndex The optional cell style Xf index to apply to the columns
  287. // $hidden The optional hidden atribute
  288. // $level The optional outline level
  289. $this->_colinfo[] = array(
  290. $i, $i, $width, $xfIndex, $hidden, $level);
  291. }
  292. // Write GUTS
  293. $this->_writeGuts();
  294. // Write DEFAULTROWHEIGHT
  295. if ($this->_BIFF_version == 0x0600)
  296. {
  297. $this->_writeDefaultRowHeight();
  298. }
  299. // Write WSBOOL
  300. $this->_writeWsbool();
  301. // Write horizontal and vertical page breaks
  302. $this->_writeBreaks();
  303. // Write page header
  304. $this->_writeHeader();
  305. // Write page footer
  306. $this->_writeFooter();
  307. // Write page horizontal centering
  308. $this->_writeHcenter();
  309. // Write page vertical centering
  310. $this->_writeVcenter();
  311. // Write left margin
  312. $this->_writeMarginLeft();
  313. // Write right margin
  314. $this->_writeMarginRight();
  315. // Write top margin
  316. $this->_writeMarginTop();
  317. // Write bottom margin
  318. $this->_writeMarginBottom();
  319. // Write page setup
  320. $this->_writeSetup();
  321. // Write sheet protection
  322. $this->_writeProtect();
  323. // Write SCENPROTECT
  324. $this->_writeScenProtect();
  325. // Write OBJECTPROTECT
  326. $this->_writeObjectProtect();
  327. // Write sheet password
  328. $this->_writePassword();
  329. // Write DEFCOLWIDTH record
  330. $this->_writeDefcol();
  331. // Write the COLINFO records if they exist
  332. if (! empty($this->_colinfo))
  333. {
  334. $colcount = count($this->_colinfo);
  335. for($i = 0; $i < $colcount; ++ $i)
  336. {
  337. $this->_writeColinfo($this->_colinfo[$i]);
  338. }
  339. }
  340. // Write EXTERNCOUNT of external references
  341. if ($this->_BIFF_version == 0x0500)
  342. {
  343. $this->_writeExterncount($num_sheets);
  344. }
  345. // Write EXTERNSHEET references
  346. if ($this->_BIFF_version == 0x0500)
  347. {
  348. for($i = 0; $i < $num_sheets; ++ $i)
  349. {
  350. $this->_writeExternsheet($this->_phpSheet->getParent()->getSheet($i)->getTitle());
  351. }
  352. }
  353. // Write sheet dimensions
  354. $this->_writeDimensions();
  355. // Row dimensions
  356. foreach ($this->_phpSheet->getRowDimensions() as $rowDimension)
  357. {
  358. $xfIndex = $rowDimension->getXfIndex() + 15; // there are 15 cellXfs
  359. $this->_writeRow($rowDimension->getRowIndex() - 1, $rowDimension->getRowHeight(), $xfIndex, ($rowDimension->getVisible() ? '0' : '1'), $rowDimension->getOutlineLevel());
  360. }
  361. // Write Cells
  362. foreach ($this->_phpSheet->getCellCollection() as $cellID)
  363. {
  364. $cell = $this->_phpSheet->getCell($cellID);
  365. $row = $cell->getRow() - 1;
  366. $column = PHPExcel_Cell :: columnIndexFromString($cell->getColumn()) - 1;
  367. // Don't break Excel!
  368. if ($row + 1 > 65536 or $column + 1 > 256)
  369. {
  370. break;
  371. }
  372. // Write cell value
  373. $xfIndex = $cell->getXfIndex() + 15; // there are 15 cell style Xfs
  374. if ($cell->getValue() instanceof PHPExcel_RichText)
  375. {
  376. $this->_writeString($row, $column, $cell->getValue()->getPlainText(), $xfIndex);
  377. }
  378. else
  379. {
  380. switch ($cell->getDatatype())
  381. {
  382. case PHPExcel_Cell_DataType :: TYPE_STRING :
  383. if ($cell->getValue() === '' or $cell->getValue() === null)
  384. {
  385. $this->_writeBlank($row, $column, $xfIndex);
  386. }
  387. else
  388. {
  389. $this->_writeString($row, $column, $cell->getValue(), $xfIndex);
  390. }
  391. break;
  392. case PHPExcel_Cell_DataType :: TYPE_FORMULA :
  393. $calculatedValue = $this->_preCalculateFormulas ? $cell->getCalculatedValue() : null;
  394. $this->_writeFormula($row, $column, $cell->getValue(), $xfIndex, $calculatedValue);
  395. break;
  396. case PHPExcel_Cell_DataType :: TYPE_BOOL :
  397. $this->_writeBoolErr($row, $column, $cell->getValue(), 0, $xfIndex);
  398. break;
  399. case PHPExcel_Cell_DataType :: TYPE_ERROR :
  400. $this->_writeBoolErr($row, $column, $this->_mapErrorCode($cell->getValue()), 1, $xfIndex);
  401. break;
  402. case PHPExcel_Cell_DataType :: TYPE_NUMERIC :
  403. $this->_writeNumber($row, $column, $cell->getValue(), $xfIndex);
  404. break;
  405. }
  406. }
  407. }
  408. // Append
  409. if ($this->_BIFF_version == 0x0600)
  410. {
  411. $this->_writeMsoDrawing();
  412. }
  413. $this->_writeWindow2();
  414. $this->_writeZoom();
  415. if ($this->_phpSheet->getFreezePane())
  416. {
  417. $this->_writePanes();
  418. }
  419. $this->_writeSelection();
  420. $this->_writeMergedCells();
  421. // Hyperlinks
  422. if ($this->_BIFF_version == 0x0600)
  423. {
  424. foreach ($this->_phpSheet->getHyperLinkCollection() as $coordinate => $hyperlink)
  425. {
  426. list($column, $row) = PHPExcel_Cell :: coordinateFromString($coordinate);
  427. $url = $hyperlink->getUrl();
  428. if (strpos($url, 'sheet://') !== false)
  429. {
  430. // internal to current workbook
  431. $url = str_replace('sheet://', 'internal:', $url);
  432. }
  433. else
  434. if (preg_match('/^(http:|https:|ftp:|mailto:)/', $url))
  435. {
  436. // URL
  437. // $url = $url;
  438. }
  439. else
  440. {
  441. // external (local file)
  442. $url = 'external:' . $url;
  443. }
  444. $this->_writeUrl($row - 1, PHPExcel_Cell :: columnIndexFromString($column) - 1, $url);
  445. }
  446. }
  447. if ($this->_BIFF_version == 0x0600)
  448. {
  449. $this->_writeDataValidity();
  450. $this->_writeSheetLayout();
  451. $this->_writeSheetProtection();
  452. $this->_writeRangeProtection();
  453. }
  454. $this->_storeEof();
  455. }
  456. /**
  457. * Write a cell range address in BIFF8
  458. * always fixed range
  459. * See section 2.5.14 in OpenOffice.org's Documentation of the Microsoft Excel File Format
  460. *
  461. * @param string $range E.g. 'A1' or 'A1:B6'
  462. * @return string Binary data
  463. */
  464. private function _writeBIFF8CellRangeAddressFixed($range = 'A1')
  465. {
  466. $explodes = explode(':', $range);
  467. // extract first cell, e.g. 'A1'
  468. $firstCell = $explodes[0];
  469. // extract last cell, e.g. 'B6'
  470. if (count($explodes) == 1)
  471. {
  472. $lastCell = $firstCell;
  473. }
  474. else
  475. {
  476. $lastCell = $explodes[1];
  477. }
  478. $firstCellCoordinates = PHPExcel_Cell :: coordinateFromString($firstCell); // e.g. array(0, 1)
  479. $lastCellCoordinates = PHPExcel_Cell :: coordinateFromString($lastCell); // e.g. array(1, 6)
  480. return (pack('vvvv', $firstCellCoordinates[1] - 1, $lastCellCoordinates[1] - 1, PHPExcel_Cell :: columnIndexFromString($firstCellCoordinates[0]) - 1, PHPExcel_Cell :: columnIndexFromString($lastCellCoordinates[0]) - 1));
  481. }
  482. /**
  483. * Retrieves data from memory in one chunk, or from disk in $buffer
  484. * sized chunks.
  485. *
  486. * @return string The data
  487. */
  488. function getData()
  489. {
  490. $buffer = 4096;
  491. // Return data stored in memory
  492. if (isset($this->_data))
  493. {
  494. $tmp = $this->_data;
  495. unset($this->_data);
  496. return $tmp;
  497. }
  498. // No data to return
  499. return false;
  500. }
  501. /**
  502. * Set the option to print the row and column headers on the printed page.
  503. *
  504. * @access public
  505. * @param integer $print Whether to print the headers or not. Defaults to 1 (print).
  506. */
  507. function printRowColHeaders($print = 1)
  508. {
  509. $this->_print_headers = $print;
  510. }
  511. /**
  512. * This method sets the properties for outlining and grouping. The defaults
  513. * correspond to Excel's defaults.
  514. *
  515. * @param bool $visible
  516. * @param bool $symbols_below
  517. * @param bool $symbols_right
  518. * @param bool $auto_style
  519. */
  520. function setOutline($visible = true, $symbols_below = true, $symbols_right = true, $auto_style = false)
  521. {
  522. $this->_outline_on = $visible;
  523. $this->_outline_below = $symbols_below;
  524. $this->_outline_right = $symbols_right;
  525. $this->_outline_style = $auto_style;
  526. // Ensure this is a boolean vale for Window2
  527. if ($this->_outline_on)
  528. {
  529. $this->_outline_on = 1;
  530. }
  531. }
  532. /**
  533. * Write a double to the specified row and column (zero indexed).
  534. * An integer can be written as a double. Excel will display an
  535. * integer. $format is optional.
  536. *
  537. * Returns 0 : normal termination
  538. * -2 : row or column out of range
  539. *
  540. * @param integer $row Zero indexed row
  541. * @param integer $col Zero indexed column
  542. * @param float $num The number to write
  543. * @param mixed $format The optional XF format
  544. * @return integer
  545. */
  546. private function _writeNumber($row, $col, $num, $xfIndex)
  547. {
  548. $record = 0x0203; // Record identifier
  549. $length = 0x000E; // Number of bytes to follow
  550. $header = pack("vv", $record, $length);
  551. $data = pack("vvv", $row, $col, $xfIndex);
  552. $xl_double = pack("d", $num);
  553. if (PHPExcel_Writer_Excel5_BIFFwriter :: getByteOrder())
  554. { // if it's Big Endian
  555. $xl_double = strrev($xl_double);
  556. }
  557. $this->_append($header . $data . $xl_double);
  558. return (0);
  559. }
  560. /**
  561. * Write a LABELSST record or a LABEL record. Which one depends on BIFF version
  562. *
  563. * @param int $row Row index (0-based)
  564. * @param int $col Column index (0-based)
  565. * @param string $str The string
  566. * @param int $xfIndex Index to XF record
  567. */
  568. private function _writeString($row, $col, $str, $xfIndex)
  569. {
  570. if ($this->_BIFF_version == 0x0600)
  571. {
  572. $this->_writeLabelSst($row, $col, $str, $xfIndex);
  573. }
  574. else
  575. {
  576. $this->_writeLabel($row, $col, $str, $xfIndex);
  577. }
  578. }
  579. /**
  580. * Write a string to the specified row and column (zero indexed).
  581. * NOTE: there is an Excel 5 defined limit of 255 characters.
  582. * $format is optional.
  583. * Returns 0 : normal termination
  584. * -2 : row or column out of range
  585. * -3 : long string truncated to 255 chars
  586. *
  587. * @access public
  588. * @param integer $row Zero indexed row
  589. * @param integer $col Zero indexed column
  590. * @param string $str The string to write
  591. * @param mixed $format The XF format for the cell
  592. * @return integer
  593. */
  594. private function _writeLabel($row, $col, $str, $xfIndex)
  595. {
  596. $strlen = strlen($str);
  597. $record = 0x0204; // Record identifier
  598. $length = 0x0008 + $strlen; // Bytes to follow
  599. $str_error = 0;
  600. if ($strlen > $this->_xls_strmax)
  601. { // LABEL must be < 255 chars
  602. $str = substr($str, 0, $this->_xls_strmax);
  603. $length = 0x0008 + $this->_xls_strmax;
  604. $strlen = $this->_xls_strmax;
  605. $str_error = - 3;
  606. }
  607. $header = pack("vv", $record, $length);
  608. $data = pack("vvvv", $row, $col, $xfIndex, $strlen);
  609. $this->_append($header . $data . $str);
  610. return ($str_error);
  611. }
  612. /**
  613. * Write a string to the specified row and column (zero indexed).
  614. * This is the BIFF8 version (no 255 chars limit).
  615. * $format is optional.
  616. * Returns 0 : normal termination
  617. * -2 : row or column out of range
  618. * -3 : long string truncated to 255 chars
  619. *
  620. * @access public
  621. * @param integer $row Zero indexed row
  622. * @param integer $col Zero indexed column
  623. * @param string $str The string to write
  624. * @param mixed $format The XF format for the cell
  625. * @return integer
  626. */
  627. private function _writeLabelSst($row, $col, $str, $xfIndex)
  628. {
  629. $record = 0x00FD; // Record identifier
  630. $length = 0x000A; // Bytes to follow
  631. $str = PHPExcel_Shared_String :: UTF8toBIFF8UnicodeLong($str);
  632. /* check if string is already present */
  633. if (! isset($this->_str_table[$str]))
  634. {
  635. $this->_str_table[$str] = $this->_str_unique ++;
  636. }
  637. $this->_str_total ++;
  638. $header = pack('vv', $record, $length);
  639. $data = pack('vvvV', $row, $col, $xfIndex, $this->_str_table[$str]);
  640. $this->_append($header . $data);
  641. }
  642. /**
  643. * Writes a note associated with the cell given by the row and column.
  644. * NOTE records don't have a length limit.
  645. *
  646. * @param integer $row Zero indexed row
  647. * @param integer $col Zero indexed column
  648. * @param string $note The note to write
  649. */
  650. private function _writeNote($row, $col, $note)
  651. {
  652. $note_length = strlen($note);
  653. $record = 0x001C; // Record identifier
  654. $max_length = 2048; // Maximun length for a NOTE record
  655. //$length = 0x0006 + $note_length; // Bytes to follow
  656. // Length for this record is no more than 2048 + 6
  657. $length = 0x0006 + min($note_length, 2048);
  658. $header = pack("vv", $record, $length);
  659. $data = pack("vvv", $row, $col, $note_length);
  660. $this->_append($header . $data . substr($note, 0, 2048));
  661. for($i = $max_length; $i < $note_length; $i += $max_length)
  662. {
  663. $chunk = substr($note, $i, $max_length);
  664. $length = 0x0006 + strlen($chunk);
  665. $header = pack("vv", $record, $length);
  666. $data = pack("vvv", - 1, 0, strlen($chunk));
  667. $this->_append($header . $data . $chunk);
  668. }
  669. return (0);
  670. }
  671. /**
  672. * Write a blank cell to the specified row and column (zero indexed).
  673. * A blank cell is used to specify formatting without adding a string
  674. * or a number.
  675. *
  676. * A blank cell without a format serves no purpose. Therefore, we don't write
  677. * a BLANK record unless a format is specified.
  678. *
  679. * Returns 0 : normal termination (including no format)
  680. * -1 : insufficient number of arguments
  681. * -2 : row or column out of range
  682. *
  683. * @param integer $row Zero indexed row
  684. * @param integer $col Zero indexed column
  685. * @param mixed $format The XF format
  686. */
  687. function _writeBlank($row, $col, $xfIndex)
  688. {
  689. $record = 0x0201; // Record identifier
  690. $length = 0x0006; // Number of bytes to follow
  691. $header = pack("vv", $record, $length);
  692. $data = pack("vvv", $row, $col, $xfIndex);
  693. $this->_append($header . $data);
  694. return 0;
  695. }
  696. /**
  697. * Write a boolean or an error type to the specified row and column (zero indexed)
  698. *
  699. * @param int $row Row index (0-based)
  700. * @param int $col Column index (0-based)
  701. * @param int $value
  702. * @param boolean $isError Error or Boolean?
  703. * @param int $xfIndex
  704. */
  705. private function _writeBoolErr($row, $col, $value, $isError, $xfIndex)
  706. {
  707. $record = 0x0205;
  708. $length = 8;
  709. $header = pack("vv", $record, $length);
  710. $data = pack("vvvCC", $row, $col, $xfIndex, $value, $isError);
  711. $this->_append($header . $data);
  712. return 0;
  713. }
  714. /**
  715. * Write a formula to the specified row and column (zero indexed).
  716. * The textual representation of the formula is passed to the parser in
  717. * Parser.php which returns a packed binary string.
  718. *
  719. * Returns 0 : normal termination
  720. * -1 : formula errors (bad formula)
  721. * -2 : row or column out of range
  722. *
  723. * @param integer $row Zero indexed row
  724. * @param integer $col Zero indexed column
  725. * @param string $formula The formula text string
  726. * @param mixed $format The optional XF format
  727. * @param mixed $calculatedValue Calculated value
  728. * @return integer
  729. */
  730. private function _writeFormula($row, $col, $formula, $xfIndex, $calculatedValue)
  731. {
  732. $record = 0x0006; // Record identifier
  733. // Initialize possible additional value for STRING record that should be written after the FORMULA record?
  734. $stringValue = null;
  735. // calculated value
  736. if (isset($calculatedValue))
  737. {
  738. // Since we can't yet get the data type of the calculated value,
  739. // we use best effort to determine data type
  740. if (is_bool($calculatedValue))
  741. {
  742. // Boolean value
  743. $num = pack('CCCvCv', 0x01, 0x00, (int) $calculatedValue, 0x00, 0x00, 0xFFFF);
  744. }
  745. elseif (is_int($calculatedValue) || is_float($calculatedValue))
  746. {
  747. // Numeric value
  748. $num = pack('d', $calculatedValue);
  749. }
  750. elseif (is_string($calculatedValue))
  751. {
  752. if (array_key_exists($calculatedValue, PHPExcel_Cell_DataType :: getErrorCodes()))
  753. {
  754. // Error value
  755. $num = pack('CCCvCv', 0x02, 0x00, $this->_mapErrorCode($calculatedValue), 0x00, 0x00, 0xFFFF);
  756. }
  757. elseif ($calculatedValue === '' && $this->_BIFF_version == 0x0600)
  758. {
  759. // Empty string (and BIFF8)
  760. $num = pack('CCCvCv', 0x03, 0x00, 0x00, 0x00, 0x00, 0xFFFF);
  761. }
  762. else
  763. {
  764. // Non-empty string value (or empty string BIFF5)
  765. $stringValue = $calculatedValue;
  766. $num = pack('CCCvCv', 0x00, 0x00, 0x00, 0x00, 0x00, 0xFFFF);
  767. }
  768. }
  769. else
  770. {
  771. // We are really not supposed to reach here
  772. $num = pack('d', 0x00);
  773. }
  774. }
  775. else
  776. {
  777. $num = pack('d', 0x00);
  778. }
  779. $grbit = 0x03; // Option flags
  780. $unknown = 0x0000; // Must be zero
  781. // Strip the '=' or '@' sign at the beginning of the formula string
  782. if ($formula{0} == '=')
  783. {
  784. $formula = substr($formula, 1);
  785. }
  786. else
  787. {
  788. // Error handling
  789. $this->_writeString($row, $col, 'Unrecognised character for formula');
  790. return - 1;
  791. }
  792. // Parse the formula using the parser in Parser.php
  793. try
  794. {
  795. $error = $this->_parser->parse($formula);
  796. $formula = $this->_parser->toReversePolish();
  797. $formlen = strlen($formula); // Length of the binary string
  798. $length = 0x16 + $formlen; // Length of the record data
  799. $header = pack("vv", $record, $length);
  800. $data = pack("vvv", $row, $col, $xfIndex) . $num . pack("vVv", $grbit, $unknown, $formlen);
  801. $this->_append($header . $data . $formula);
  802. // Append also a STRING record if necessary
  803. if ($stringValue !== null)
  804. {
  805. $this->_writeStringRecord($stringValue);
  806. }
  807. return 0;
  808. }
  809. catch (Exception $e)
  810. {
  811. // do nothing
  812. }
  813. }
  814. /**
  815. * Write a STRING record. This
  816. *
  817. * @param string $stringValue
  818. */
  819. private function _writeStringRecord($stringValue)
  820. {
  821. $record = 0x0207; // Record identifier
  822. $data = PHPExcel_Shared_String :: UTF8toBIFF8UnicodeLong($stringValue);
  823. $length = strlen($data);
  824. $header = pack('vv', $record, $length);
  825. $this->_append($header . $data);
  826. }
  827. /**
  828. * Write a hyperlink.
  829. * This is comprised of two elements: the visible label and
  830. * the invisible link. The visible label is the same as the link unless an
  831. * alternative string is specified. The label is written using the
  832. * _writeString() method. Therefore the 255 characters string limit applies.
  833. * $string and $format are optional.
  834. *
  835. * The hyperlink can be to a http, ftp, mail, internal sheet (not yet), or external
  836. * directory url.
  837. *
  838. * Returns 0 : normal termination
  839. * -2 : row or column out of range
  840. * -3 : long string truncated to 255 chars
  841. *
  842. * @param integer $row Row
  843. * @param integer $col Column
  844. * @param string $url URL string
  845. * @return integer
  846. */
  847. private function _writeUrl($row, $col, $url)
  848. {
  849. // Add start row and col to arg list
  850. return ($this->_writeUrlRange($row, $col, $row, $col, $url));
  851. }
  852. /**
  853. * This is the more general form of _writeUrl(). It allows a hyperlink to be
  854. * written to a range of cells. This function also decides the type of hyperlink
  855. * to be written. These are either, Web (http, ftp, mailto), Internal
  856. * (Sheet1!A1) or external ('c:\temp\foo.xls#Sheet1!A1').
  857. *
  858. * @access private
  859. * @see _writeUrl()
  860. * @param integer $row1 Start row
  861. * @param integer $col1 Start column
  862. * @param integer $row2 End row
  863. * @param integer $col2 End column
  864. * @param string $url URL string
  865. * @return integer
  866. */
  867. function _writeUrlRange($row1, $col1, $row2, $col2, $url)
  868. {
  869. // Check for internal/external sheet links or default to web link
  870. if (preg_match('[^internal:]', $url))
  871. {
  872. return ($this->_writeUrlInternal($row1, $col1, $row2, $col2, $url));
  873. }
  874. if (preg_match('[^external:]', $url))
  875. {
  876. return ($this->_writeUrlExternal($row1, $col1, $row2, $col2, $url));
  877. }
  878. return ($this->_writeUrlWeb($row1, $col1, $row2, $col2, $url));
  879. }
  880. /**
  881. * Used to write http, ftp and mailto hyperlinks.
  882. * The link type ($options) is 0x03 is the same as absolute dir ref without
  883. * sheet. However it is differentiated by the $unknown2 data stream.
  884. *
  885. * @access private
  886. * @see _writeUrl()
  887. * @param integer $row1 Start row
  888. * @param integer $col1 Start column
  889. * @param integer $row2 End row
  890. * @param integer $col2 End column
  891. * @param string $url URL string
  892. * @return integer
  893. */
  894. function _writeUrlWeb($row1, $col1, $row2, $col2, $url)
  895. {
  896. $record = 0x01B8; // Record identifier
  897. $length = 0x00000; // Bytes to follow
  898. // Pack the undocumented parts of the hyperlink stream
  899. $unknown1 = pack("H*", "D0C9EA79F9BACE118C8200AA004BA90B02000000");
  900. $unknown2 = pack("H*", "E0C9EA79F9BACE118C8200AA004BA90B");
  901. // Pack the option flags
  902. $options = pack("V", 0x03);
  903. // Convert URL to a null terminated wchar string
  904. $url = join("\0", preg_split("''", $url, - 1, PREG_SPLIT_NO_EMPTY));
  905. $url = $url . "\0\0\0";
  906. // Pack the length of the URL
  907. $url_len = pack("V", strlen($url));
  908. // Calculate the data length
  909. $length = 0x34 + strlen($url);
  910. // Pack the header data
  911. $header = pack("vv", $record, $length);
  912. $data = pack("vvvv", $row1, $row2, $col1, $col2);
  913. // Write the packed data
  914. $this->_append($header . $data . $unknown1 . $options . $unknown2 . $url_len . $url);
  915. return 0;
  916. }
  917. /**
  918. * Used to write internal reference hyperlinks such as "Sheet1!A1".
  919. *
  920. * @access private
  921. * @see _writeUrl()
  922. * @param integer $row1 Start row
  923. * @param integer $col1 Start column
  924. * @param integer $row2 End row
  925. * @param integer $col2 End column
  926. * @param string $url URL string
  927. * @return integer
  928. */
  929. function _writeUrlInternal($row1, $col1, $row2, $col2, $url)
  930. {
  931. $record = 0x01B8; // Record identifier
  932. $length = 0x00000; // Bytes to follow
  933. // Strip URL type
  934. $url = preg_replace('/^internal:/', '', $url);
  935. // Pack the undocumented parts of the hyperlink stream
  936. $unknown1 = pack("H*", "D0C9EA79F9BACE118C8200AA004BA90B02000000");
  937. // Pack the option flags
  938. $options = pack("V", 0x08);
  939. // Convert the URL type and to a null terminated wchar string
  940. $url .= "\0";
  941. // character count
  942. $url_len = PHPExcel_Shared_String :: CountCharacters($url);
  943. $url_len = pack('V', $url_len);
  944. $url = PHPExcel_Shared_String :: ConvertEncoding($url, 'UTF-16LE', 'UTF-8');
  945. // Calculate the data length
  946. $length = 0x24 + strlen($url);
  947. // Pack the header data
  948. $header = pack("vv", $record, $length);
  949. $data = pack("vvvv", $row1, $row2, $col1, $col2);
  950. // Write the packed data
  951. $this->_append($header . $data . $unknown1 . $options . $url_len . $url);
  952. return 0;
  953. }
  954. /**
  955. * Write links to external directory names such as 'c:\foo.xls',
  956. * c:\foo.xls#Sheet1!A1', '../../foo.xls'. and '../../foo.xls#Sheet1!A1'.
  957. *
  958. * Note: Excel writes some relative links with the $dir_long string. We ignore
  959. * these cases for the sake of simpler code.
  960. *
  961. * @access private
  962. * @see _writeUrl()
  963. * @param integer $row1 Start row
  964. * @param integer $col1 Start column
  965. * @param integer $row2 End row
  966. * @param integer $col2 End column
  967. * @param string $url URL string
  968. * @return integer
  969. */
  970. function _writeUrlExternal($row1, $col1, $row2, $col2, $url)
  971. {
  972. // Network drives are different. We will handle them separately
  973. // MS/Novell network drives and shares start with \\
  974. if (preg_match('[^external:\\\\]', $url))
  975. {
  976. return; //($this->_writeUrlExternal_net($row1, $col1, $row2, $col2, $url, $str, $format));
  977. }
  978. $record = 0x01B8; // Record identifier
  979. $length = 0x00000; // Bytes to follow
  980. // Strip URL type and change Unix dir separator to Dos style (if needed)
  981. //
  982. $url = preg_replace('/^external:/', '', $url);
  983. $url = preg_replace('/\//', "\\", $url);
  984. // Determine if the link is relative or absolute:
  985. // relative if link contains no dir separator, "somefile.xls"
  986. // relative if link starts with up-dir, "..\..\somefile.xls"
  987. // otherwise, absolute
  988. $absolute = 0x00; // relative path
  989. if (preg_match('/^[A-Z]:/', $url))
  990. {
  991. $absolute = 0x02; // absolute path on Windows, e.g. C:\...
  992. }
  993. $link_type = 0x01 | $absolute;
  994. // Determine if the link contains a sheet reference and change some of the
  995. // parameters accordingly.
  996. // Split the dir name and sheet name (if it exists)
  997. $dir_long = $url;
  998. if (preg_match("/\#/", $url))
  999. {
  1000. $link_type |= 0x08;
  1001. }
  1002. // Pack the link type
  1003. $link_type = pack("V", $link_type);
  1004. // Calculate the up-level dir count e.g.. (..\..\..\ == 3)
  1005. $up_count = preg_match_all("/\.\.\\\/", $dir_long, $useless);
  1006. $up_count = pack("v", $up_count);
  1007. // Store the short dos dir name (null terminated)
  1008. $dir_short = preg_replace("/\.\.\\\/", '', $dir_long) . "\0";
  1009. // Store the long dir name as a wchar string (non-null terminated)
  1010. $dir_long = $dir_long . "\0";
  1011. // Pack the lengths of the dir strings
  1012. $dir_short_len = pack("V", strlen($dir_short));
  1013. $dir_long_len = pack("V", strlen($dir_long));
  1014. $stream_len = pack("V", 0); //strlen($dir_long) + 0x06);
  1015. // Pack the undocumented parts of the hyperlink stream
  1016. $unknown1 = pack("H*", 'D0C9EA79F9BACE118C8200AA004BA90B02000000');
  1017. $unknown2 = pack("H*", '0303000000000000C000000000000046');
  1018. $unknown3 = pack("H*", 'FFFFADDE000000000000000000000000000000000000000');
  1019. $unknown4 = pack("v", 0x03);
  1020. // Pack the main data stream
  1021. $data = pack("vvvv", $row1, $row2, $col1, $col2) . $unknown1 . $link_type . $unknown2 . $up_count . $dir_short_len . $dir_short . $unknown3 . $stream_len; /*.
  1022. $dir_long_len .
  1023. $unknown4 .
  1024. $dir_long .
  1025. $sheet_len .
  1026. $sheet ;*/
  1027. // Pack the header data
  1028. $length = strlen($data);
  1029. $header = pack("vv", $record, $length);
  1030. // Write the packed data
  1031. $this->_append($header . $data);
  1032. return 0;
  1033. }
  1034. /**
  1035. * This method is used to set the height and format for a row.
  1036. *
  1037. * @param integer $row The row to set
  1038. * @param integer $height Height we are giving to the row.
  1039. * Use null to set XF without setting height
  1040. * @param integer $xfIndex The optional cell style Xf index to apply to the columns
  1041. * @param bool $hidden The optional hidden attribute
  1042. * @param integer $level The optional outline level for row, in range [0,7]
  1043. */
  1044. private function _writeRow($row, $height, $xfIndex, $hidden = false, $level = 0)
  1045. {
  1046. $record = 0x0208; // Record identifier
  1047. $length = 0x0010; // Number of bytes to follow
  1048. $colMic = 0x0000; // First defined column
  1049. $colMac = 0x0000; // Last defined column
  1050. $irwMac = 0x0000; // Used by Excel to optimise loading
  1051. $reserved = 0x0000; // Reserved
  1052. $grbit = 0x0000; // Option flags
  1053. $ixfe = $xfIndex;
  1054. if ($height < 0)
  1055. {
  1056. $height = null;
  1057. }
  1058. // Use _writeRow($row, null, $XF) to set XF format without setting height
  1059. if ($height != null)
  1060. {
  1061. $miyRw = $height * 20; // row height
  1062. }
  1063. else
  1064. {
  1065. $miyRw = 0xff; // default row height is 256
  1066. }
  1067. // Set the options flags. fUnsynced is used to show that the font and row
  1068. // heights are not compatible. This is usually the case for WriteExcel.
  1069. // The collapsed flag 0x10 doesn't seem to be used to indicate that a row
  1070. // is collapsed. Instead it is used to indicate that the previous row is
  1071. // collapsed. The zero height flag, 0x20, is used to collapse a row.
  1072. $grbit |= $level;
  1073. if ($hidden)
  1074. {
  1075. $grbit |= 0x0020;
  1076. }
  1077. if ($height !== null)
  1078. {
  1079. $grbit |= 0x0040; // fUnsynced
  1080. }
  1081. if ($xfIndex !== 0xF)
  1082. {
  1083. $grbit |= 0x0080;
  1084. }
  1085. $grbit |= 0x0100;
  1086. $header = pack("vv", $record, $length);
  1087. $data = pack("vvvvvvvv", $row, $colMic, $colMac, $miyRw, $irwMac, $reserved, $grbit, $ixfe);
  1088. $this->_append($header . $data);
  1089. }
  1090. /**
  1091. * Writes Excel DIMENSIONS to define the area in which there is data.
  1092. */
  1093. private function _writeDimensions()
  1094. {
  1095. $record = 0x0200; // Record identifier
  1096. if ($this->_BIFF_version == 0x0500)
  1097. {
  1098. $length = 0x000A; // Number of bytes to follow
  1099. $data = pack("vvvvv", $this->_firstRowIndex, $this->_lastRowIndex + 1, $this->_firstColumnIndex, $this->_lastColumnIndex + 1, 0x0000)// reserved
  1100. ;
  1101. }
  1102. elseif ($this->_BIFF_version == 0x0600)
  1103. {
  1104. $length = 0x000E;
  1105. $data = pack('VVvvv', $this->_firstRowIndex, $this->_lastRowIndex + 1, $this->_firstColumnIndex, $this->_lastColumnIndex + 1, 0x0000)// reserved
  1106. ;
  1107. }
  1108. $header = pack("vv", $record, $length);
  1109. $this->_append($header . $data);
  1110. }
  1111. /**
  1112. * Write BIFF record Window2.
  1113. */
  1114. private function _writeWindow2()
  1115. {
  1116. $record = 0x023E; // Record identifier
  1117. if ($this->_BIFF_version == 0x0500)
  1118. {
  1119. $length = 0x000A; // Number of bytes to follow
  1120. }
  1121. elseif ($this->_BIFF_version == 0x0600)
  1122. {
  1123. $length = 0x0012;
  1124. }
  1125. $grbit = 0x00B6; // Option flags
  1126. $rwTop = 0x0000; // Top row visible in window
  1127. $colLeft = 0x0000; // Leftmost column visible in window
  1128. // The options flags that comprise $grbit
  1129. $fDspFmla = 0; // 0 - bit
  1130. $fDspGrid = $this->_phpSheet->getShowGridlines() ? 1 : 0; // 1
  1131. $fDspRwCol = $this->_phpSheet->getShowRowColHeaders() ? 1 : 0; // 2
  1132. $fFrozen = $this->_phpSheet->getFreezePane() ? 1 : 0; // 3
  1133. $fDspZeros = 1; // 4
  1134. $fDefaultHdr = 1; // 5
  1135. $fArabic = $this->_phpSheet->getRightToLeft() ? 1 : 0; // 6
  1136. $fDspGuts = $this->_outline_on; // 7
  1137. $fFrozenNoSplit = 0; // 0 - bit
  1138. // no support in PHPExcel for selected sheet, therefore sheet is only selected if it is the active sheet
  1139. $fSelected = ($this->_phpSheet === $this->_phpSheet->getParent()->getActiveSheet()) ? 1 : 0;
  1140. $fPaged = 1; // 2
  1141. $grbit = $fDspFmla;
  1142. $grbit |= $fDspGrid << 1;
  1143. $grbit |= $fDspRwCol << 2;
  1144. $grbit |= $fFrozen << 3;
  1145. $grbit |= $fDspZeros << 4;
  1146. $grbit |= $fDefaultHdr << 5;
  1147. $grbit |= $fArabic << 6;
  1148. $grbit |= $fDspGuts << 7;
  1149. $grbit |= $fFrozenNoSplit << 8;
  1150. $grbit |= $fSelected << 9;
  1151. $grbit |= $fPaged << 10;
  1152. $header = pack("vv", $record, $length);
  1153. $data = pack("vvv", $grbit, $rwTop, $colLeft);
  1154. // FIXME !!!
  1155. if ($this->_BIFF_version == 0x0500)
  1156. {
  1157. $rgbHdr = 0x00000000; // Row/column heading and gridline color
  1158. $data .= pack("V", $rgbHdr);
  1159. }
  1160. elseif ($this->_BIFF_version == 0x0600)
  1161. {
  1162. $rgbHdr = 0x0040; // Row/column heading and gridline color index
  1163. $zoom_factor_page_break = 0x0000;
  1164. $zoom_factor_normal = 0x0000;
  1165. $data .= pack("vvvvV", $rgbHdr, 0x0000, $zoom_factor_page_break, $zoom_factor_normal, 0x00000000);
  1166. }
  1167. $this->_append($header . $data);
  1168. }
  1169. /**
  1170. * Write BIFF record DEFAULTROWHEIGHT.
  1171. */
  1172. private function _writeDefaultRowHeight()
  1173. {
  1174. $defaultRowHeight = $this->_phpSheet->getDefaultRowDimension()->getRowHeight();
  1175. if ($defaultRowHeight < 0)
  1176. {
  1177. return;
  1178. }
  1179. // convert to twips
  1180. $defaultRowHeight = (int) 20 * $defaultRowHeight;
  1181. $record = 0x0225; // Record identifier
  1182. $length = 0x0004; // Number of bytes to follow
  1183. $header = pack("vv", $record, $length);
  1184. $data = pack("vv", 1, $defaultRowHeight);
  1185. $this->_append($header . $data);
  1186. }
  1187. /**
  1188. * Write BIFF record DEFCOLWIDTH if COLINFO records are in use.
  1189. */
  1190. private function _writeDefcol()
  1191. {
  1192. $defaultColWidth = 8;
  1193. $record = 0x0055; // Record identifier
  1194. $length = 0x0002; // Number of bytes to follow
  1195. $header = pack("vv", $record, $length);
  1196. $data = pack("v", $defaultColWidth);
  1197. $this->_append($header . $data);
  1198. }
  1199. /**
  1200. * Write BIFF record COLINFO to define column widths
  1201. *
  1202. * Note: The SDK says the record length is 0x0B but Excel writes a 0x0C
  1203. * length record.
  1204. *
  1205. * @param array $col_array This is the only parameter received and is composed of the following:
  1206. * 0 => First formatted column,
  1207. * 1 => Last formatted column,
  1208. * 2 => Col width (8.43 is Excel default),
  1209. * 3 => The optional XF format of the column,
  1210. * 4 => Option flags.
  1211. * 5 => Optional outline level
  1212. */
  1213. private function _writeColinfo($col_array)
  1214. {
  1215. if (isset($col_array[0]))
  1216. {
  1217. $colFirst = $col_array[0];
  1218. }
  1219. if (isset($col_array[1]))
  1220. {
  1221. $colLast = $col_array[1];
  1222. }
  1223. if (isset($col_array[2]))
  1224. {
  1225. $coldx = $col_array[2];
  1226. }
  1227. else
  1228. {
  1229. $coldx = 8.43;
  1230. }
  1231. if (isset($col_array[3]))
  1232. {
  1233. $xfIndex = $col_array[3];
  1234. }
  1235. else
  1236. {
  1237. $xfIndex = 15;
  1238. }
  1239. if (isset($col_array[4]))
  1240. {
  1241. $grbit = $col_array[4];
  1242. }
  1243. else
  1244. {
  1245. $grbit = 0;
  1246. }
  1247. if (isset($col_array[5]))
  1248. {
  1249. $level = $col_array[5];
  1250. }
  1251. else
  1252. {
  1253. $level = 0;
  1254. }
  1255. $record = 0x007D; // Record identifier
  1256. $length = 0x000C; // Number of bytes to follow
  1257. $coldx *= 256; // Convert to units of 1/256 of a char
  1258. $ixfe = $xfIndex;
  1259. $reserved = 0x0000; // Reserved
  1260. $level = max(0, min($level, 7));
  1261. $grbit |= $level << 8;
  1262. $header = pack("vv", $record, $length);
  1263. $data = pack("vvvvvv", $colFirst, $colLast, $coldx, $ixfe, $grbit, $reserved);
  1264. $this->_append($header . $data);
  1265. }
  1266. /**
  1267. * Write BIFF record SELECTION.
  1268. */
  1269. private function _writeSelection()
  1270. {
  1271. // look up the selected cell range
  1272. $selected

Large files files are truncated, but you can click here to view the full file