PageRenderTime 57ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/functions/PEAR/Spreadsheet/Excel/Writer/Worksheet.php

https://bitbucket.org/bertramtruong/phpipam
PHP | 3521 lines | 1750 code | 427 blank | 1344 comment | 273 complexity | 2d6ffdc56dfaf8a395e00765e5b918e4 MD5 | raw file

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

  1. <?php
  2. /*
  3. * Module written/ported by Xavier Noguer <xnoguer@rezebra.com>
  4. *
  5. * The majority of this is _NOT_ my code. I simply ported it from the
  6. * PERL Spreadsheet::WriteExcel module.
  7. *
  8. * The author of the Spreadsheet::WriteExcel module is John McNamara
  9. * <jmcnamara@cpan.org>
  10. *
  11. * I _DO_ maintain this code, and John McNamara has nothing to do with the
  12. * porting of this code to PHP. Any questions directly related to this
  13. * class library should be directed to me.
  14. *
  15. * License Information:
  16. *
  17. * Spreadsheet_Excel_Writer: A library for generating Excel Spreadsheets
  18. * Copyright (c) 2002-2003 Xavier Noguer xnoguer@rezebra.com
  19. *
  20. * This library is free software; you can redistribute it and/or
  21. * modify it under the terms of the GNU Lesser General Public
  22. * License as published by the Free Software Foundation; either
  23. * version 2.1 of the License, or (at your option) any later version.
  24. *
  25. * This library is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  28. * Lesser General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU Lesser General Public
  31. * License along with this library; if not, write to the Free Software
  32. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  33. */
  34. require_once '../../functions/PEAR/Spreadsheet/Excel/Writer/Parser.php';
  35. require_once '../../functions/PEAR/Spreadsheet/Excel/Writer/BIFFwriter.php';
  36. /**
  37. * Class for generating Excel Spreadsheets
  38. *
  39. * @author Xavier Noguer <xnoguer@rezebra.com>
  40. * @category FileFormats
  41. * @package Spreadsheet_Excel_Writer
  42. */
  43. class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwriter
  44. {
  45. /**
  46. * Name of the Worksheet
  47. * @var string
  48. */
  49. var $name;
  50. /**
  51. * Index for the Worksheet
  52. * @var integer
  53. */
  54. var $index;
  55. /**
  56. * Reference to the (default) Format object for URLs
  57. * @var object Format
  58. */
  59. var $_url_format;
  60. /**
  61. * Reference to the parser used for parsing formulas
  62. * @var object Format
  63. */
  64. var $_parser;
  65. /**
  66. * Filehandle to the temporary file for storing data
  67. * @var resource
  68. */
  69. var $_filehandle;
  70. /**
  71. * Boolean indicating if we are using a temporary file for storing data
  72. * @var bool
  73. */
  74. var $_using_tmpfile;
  75. /**
  76. * Maximum number of rows for an Excel spreadsheet (BIFF5)
  77. * @var integer
  78. */
  79. var $_xls_rowmax;
  80. /**
  81. * Maximum number of columns for an Excel spreadsheet (BIFF5)
  82. * @var integer
  83. */
  84. var $_xls_colmax;
  85. /**
  86. * Maximum number of characters for a string (LABEL record in BIFF5)
  87. * @var integer
  88. */
  89. var $_xls_strmax;
  90. /**
  91. * First row for the DIMENSIONS record
  92. * @var integer
  93. * @see _storeDimensions()
  94. */
  95. var $_dim_rowmin;
  96. /**
  97. * Last row for the DIMENSIONS record
  98. * @var integer
  99. * @see _storeDimensions()
  100. */
  101. var $_dim_rowmax;
  102. /**
  103. * First column for the DIMENSIONS record
  104. * @var integer
  105. * @see _storeDimensions()
  106. */
  107. var $_dim_colmin;
  108. /**
  109. * Last column for the DIMENSIONS record
  110. * @var integer
  111. * @see _storeDimensions()
  112. */
  113. var $_dim_colmax;
  114. /**
  115. * Array containing format information for columns
  116. * @var array
  117. */
  118. var $_colinfo;
  119. /**
  120. * Array containing the selected area for the worksheet
  121. * @var array
  122. */
  123. var $_selection;
  124. /**
  125. * Array containing the panes for the worksheet
  126. * @var array
  127. */
  128. var $_panes;
  129. /**
  130. * The active pane for the worksheet
  131. * @var integer
  132. */
  133. var $_active_pane;
  134. /**
  135. * Bit specifying if panes are frozen
  136. * @var integer
  137. */
  138. var $_frozen;
  139. /**
  140. * Bit specifying if the worksheet is selected
  141. * @var integer
  142. */
  143. var $selected;
  144. /**
  145. * The paper size (for printing) (DOCUMENT!!!)
  146. * @var integer
  147. */
  148. var $_paper_size;
  149. /**
  150. * Bit specifying paper orientation (for printing). 0 => landscape, 1 => portrait
  151. * @var integer
  152. */
  153. var $_orientation;
  154. /**
  155. * The page header caption
  156. * @var string
  157. */
  158. var $_header;
  159. /**
  160. * The page footer caption
  161. * @var string
  162. */
  163. var $_footer;
  164. /**
  165. * The horizontal centering value for the page
  166. * @var integer
  167. */
  168. var $_hcenter;
  169. /**
  170. * The vertical centering value for the page
  171. * @var integer
  172. */
  173. var $_vcenter;
  174. /**
  175. * The margin for the header
  176. * @var float
  177. */
  178. var $_margin_head;
  179. /**
  180. * The margin for the footer
  181. * @var float
  182. */
  183. var $_margin_foot;
  184. /**
  185. * The left margin for the worksheet in inches
  186. * @var float
  187. */
  188. var $_margin_left;
  189. /**
  190. * The right margin for the worksheet in inches
  191. * @var float
  192. */
  193. var $_margin_right;
  194. /**
  195. * The top margin for the worksheet in inches
  196. * @var float
  197. */
  198. var $_margin_top;
  199. /**
  200. * The bottom margin for the worksheet in inches
  201. * @var float
  202. */
  203. var $_margin_bottom;
  204. /**
  205. * First row to reapeat on each printed page
  206. * @var integer
  207. */
  208. var $title_rowmin;
  209. /**
  210. * Last row to reapeat on each printed page
  211. * @var integer
  212. */
  213. var $title_rowmax;
  214. /**
  215. * First column to reapeat on each printed page
  216. * @var integer
  217. */
  218. var $title_colmin;
  219. /**
  220. * First row of the area to print
  221. * @var integer
  222. */
  223. var $print_rowmin;
  224. /**
  225. * Last row to of the area to print
  226. * @var integer
  227. */
  228. var $print_rowmax;
  229. /**
  230. * First column of the area to print
  231. * @var integer
  232. */
  233. var $print_colmin;
  234. /**
  235. * Last column of the area to print
  236. * @var integer
  237. */
  238. var $print_colmax;
  239. /**
  240. * Whether to use outline.
  241. * @var integer
  242. */
  243. var $_outline_on;
  244. /**
  245. * Auto outline styles.
  246. * @var bool
  247. */
  248. var $_outline_style;
  249. /**
  250. * Whether to have outline summary below.
  251. * @var bool
  252. */
  253. var $_outline_below;
  254. /**
  255. * Whether to have outline summary at the right.
  256. * @var bool
  257. */
  258. var $_outline_right;
  259. /**
  260. * Outline row level.
  261. * @var integer
  262. */
  263. var $_outline_row_level;
  264. /**
  265. * Whether to fit to page when printing or not.
  266. * @var bool
  267. */
  268. var $_fit_page;
  269. /**
  270. * Number of pages to fit wide
  271. * @var integer
  272. */
  273. var $_fit_width;
  274. /**
  275. * Number of pages to fit high
  276. * @var integer
  277. */
  278. var $_fit_height;
  279. /**
  280. * Reference to the total number of strings in the workbook
  281. * @var integer
  282. */
  283. var $_str_total;
  284. /**
  285. * Reference to the number of unique strings in the workbook
  286. * @var integer
  287. */
  288. var $_str_unique;
  289. /**
  290. * Reference to the array containing all the unique strings in the workbook
  291. * @var array
  292. */
  293. var $_str_table;
  294. /**
  295. * Merged cell ranges
  296. * @var array
  297. */
  298. var $_merged_ranges;
  299. /**
  300. * Charset encoding currently used when calling writeString()
  301. * @var string
  302. */
  303. var $_input_encoding;
  304. /**
  305. * Constructor
  306. *
  307. * @param string $name The name of the new worksheet
  308. * @param integer $index The index of the new worksheet
  309. * @param mixed &$activesheet The current activesheet of the workbook we belong to
  310. * @param mixed &$firstsheet The first worksheet in the workbook we belong to
  311. * @param mixed &$url_format The default format for hyperlinks
  312. * @param mixed &$parser The formula parser created for the Workbook
  313. * @param string $tmp_dir The path to the directory for temporary files
  314. * @access private
  315. */
  316. function Spreadsheet_Excel_Writer_Worksheet($BIFF_version, $name,
  317. $index, &$activesheet,
  318. &$firstsheet, &$str_total,
  319. &$str_unique, &$str_table,
  320. &$url_format, &$parser,
  321. $tmp_dir)
  322. {
  323. // It needs to call its parent's constructor explicitly
  324. $this->Spreadsheet_Excel_Writer_BIFFwriter();
  325. $this->_BIFF_version = $BIFF_version;
  326. $rowmax = 65536; // 16384 in Excel 5
  327. $colmax = 256;
  328. $this->name = $name;
  329. $this->index = $index;
  330. $this->activesheet = &$activesheet;
  331. $this->firstsheet = &$firstsheet;
  332. $this->_str_total = &$str_total;
  333. $this->_str_unique = &$str_unique;
  334. $this->_str_table = &$str_table;
  335. $this->_url_format = &$url_format;
  336. $this->_parser = &$parser;
  337. //$this->ext_sheets = array();
  338. $this->_filehandle = '';
  339. $this->_using_tmpfile = true;
  340. //$this->fileclosed = 0;
  341. //$this->offset = 0;
  342. $this->_xls_rowmax = $rowmax;
  343. $this->_xls_colmax = $colmax;
  344. $this->_xls_strmax = 255;
  345. $this->_dim_rowmin = $rowmax + 1;
  346. $this->_dim_rowmax = 0;
  347. $this->_dim_colmin = $colmax + 1;
  348. $this->_dim_colmax = 0;
  349. $this->_colinfo = array();
  350. $this->_selection = array(0,0,0,0);
  351. $this->_panes = array();
  352. $this->_active_pane = 3;
  353. $this->_frozen = 0;
  354. $this->selected = 0;
  355. $this->_paper_size = 0x0;
  356. $this->_orientation = 0x1;
  357. $this->_header = '';
  358. $this->_footer = '';
  359. $this->_hcenter = 0;
  360. $this->_vcenter = 0;
  361. $this->_margin_head = 0.50;
  362. $this->_margin_foot = 0.50;
  363. $this->_margin_left = 0.75;
  364. $this->_margin_right = 0.75;
  365. $this->_margin_top = 1.00;
  366. $this->_margin_bottom = 1.00;
  367. $this->title_rowmin = null;
  368. $this->title_rowmax = null;
  369. $this->title_colmin = null;
  370. $this->title_colmax = null;
  371. $this->print_rowmin = null;
  372. $this->print_rowmax = null;
  373. $this->print_colmin = null;
  374. $this->print_colmax = null;
  375. $this->_print_gridlines = 1;
  376. $this->_screen_gridlines = 1;
  377. $this->_print_headers = 0;
  378. $this->_fit_page = 0;
  379. $this->_fit_width = 0;
  380. $this->_fit_height = 0;
  381. $this->_hbreaks = array();
  382. $this->_vbreaks = array();
  383. $this->_protect = 0;
  384. $this->_password = null;
  385. $this->col_sizes = array();
  386. $this->_row_sizes = array();
  387. $this->_zoom = 100;
  388. $this->_print_scale = 100;
  389. $this->_outline_row_level = 0;
  390. $this->_outline_style = 0;
  391. $this->_outline_below = 1;
  392. $this->_outline_right = 1;
  393. $this->_outline_on = 1;
  394. $this->_merged_ranges = array();
  395. $this->_input_encoding = '';
  396. $this->_dv = array();
  397. $this->_tmp_dir = $tmp_dir;
  398. $this->_initialize();
  399. }
  400. /**
  401. * Open a tmp file to store the majority of the Worksheet data. If this fails,
  402. * for example due to write permissions, store the data in memory. This can be
  403. * slow for large files.
  404. *
  405. * @access private
  406. */
  407. function _initialize()
  408. {
  409. if ($this->_using_tmpfile == false) {
  410. return;
  411. }
  412. if ($this->_tmp_dir === '' && ini_get('open_basedir') === false) {
  413. // open_basedir restriction in effect - store data in memory
  414. // ToDo: Let the error actually have an effect somewhere
  415. $this->_using_tmpfile = false;
  416. return new PEAR_Error('Temp file could not be opened since open_basedir restriction in effect - please use setTmpDir() - using memory storage instead');
  417. }
  418. // Open tmp file for storing Worksheet data
  419. if ($this->_tmp_dir === '') {
  420. $fh = tmpfile();
  421. } else {
  422. // For people with open base dir restriction
  423. $tmpfilename = tempnam($this->_tmp_dir, "Spreadsheet_Excel_Writer");
  424. $fh = @fopen($tmpfilename, "w+b");
  425. }
  426. if ($fh === false) {
  427. // If tmpfile() fails store data in memory
  428. $this->_using_tmpfile = false;
  429. } else {
  430. // Store filehandle
  431. $this->_filehandle = $fh;
  432. }
  433. }
  434. /**
  435. * Add data to the beginning of the workbook (note the reverse order)
  436. * and to the end of the workbook.
  437. *
  438. * @access public
  439. * @see Spreadsheet_Excel_Writer_Workbook::storeWorkbook()
  440. * @param array $sheetnames The array of sheetnames from the Workbook this
  441. * worksheet belongs to
  442. */
  443. function close($sheetnames)
  444. {
  445. $num_sheets = count($sheetnames);
  446. /***********************************************
  447. * Prepend in reverse order!!
  448. */
  449. // Prepend the sheet dimensions
  450. $this->_storeDimensions();
  451. // Prepend the sheet password
  452. $this->_storePassword();
  453. // Prepend the sheet protection
  454. $this->_storeProtect();
  455. // Prepend the page setup
  456. $this->_storeSetup();
  457. /* FIXME: margins are actually appended */
  458. // Prepend the bottom margin
  459. $this->_storeMarginBottom();
  460. // Prepend the top margin
  461. $this->_storeMarginTop();
  462. // Prepend the right margin
  463. $this->_storeMarginRight();
  464. // Prepend the left margin
  465. $this->_storeMarginLeft();
  466. // Prepend the page vertical centering
  467. $this->_storeVcenter();
  468. // Prepend the page horizontal centering
  469. $this->_storeHcenter();
  470. // Prepend the page footer
  471. $this->_storeFooter();
  472. // Prepend the page header
  473. $this->_storeHeader();
  474. // Prepend the vertical page breaks
  475. $this->_storeVbreak();
  476. // Prepend the horizontal page breaks
  477. $this->_storeHbreak();
  478. // Prepend WSBOOL
  479. $this->_storeWsbool();
  480. // Prepend GRIDSET
  481. $this->_storeGridset();
  482. // Prepend GUTS
  483. if ($this->_BIFF_version == 0x0500) {
  484. $this->_storeGuts();
  485. }
  486. // Prepend PRINTGRIDLINES
  487. $this->_storePrintGridlines();
  488. // Prepend PRINTHEADERS
  489. $this->_storePrintHeaders();
  490. // Prepend EXTERNSHEET references
  491. if ($this->_BIFF_version == 0x0500) {
  492. for ($i = $num_sheets; $i > 0; $i--) {
  493. $sheetname = $sheetnames[$i-1];
  494. $this->_storeExternsheet($sheetname);
  495. }
  496. }
  497. // Prepend the EXTERNCOUNT of external references.
  498. if ($this->_BIFF_version == 0x0500) {
  499. $this->_storeExterncount($num_sheets);
  500. }
  501. // Prepend the COLINFO records if they exist
  502. if (!empty($this->_colinfo)) {
  503. $colcount = count($this->_colinfo);
  504. for ($i = 0; $i < $colcount; $i++) {
  505. $this->_storeColinfo($this->_colinfo[$i]);
  506. }
  507. $this->_storeDefcol();
  508. }
  509. // Prepend the BOF record
  510. $this->_storeBof(0x0010);
  511. /*
  512. * End of prepend. Read upwards from here.
  513. ***********************************************/
  514. // Append
  515. $this->_storeWindow2();
  516. $this->_storeZoom();
  517. if (!empty($this->_panes)) {
  518. $this->_storePanes($this->_panes);
  519. }
  520. $this->_storeSelection($this->_selection);
  521. $this->_storeMergedCells();
  522. /* TODO: add data validity */
  523. /*if ($this->_BIFF_version == 0x0600) {
  524. $this->_storeDataValidity();
  525. }*/
  526. $this->_storeEof();
  527. }
  528. /**
  529. * Retrieve the worksheet name.
  530. * This is usefull when creating worksheets without a name.
  531. *
  532. * @access public
  533. * @return string The worksheet's name
  534. */
  535. function getName()
  536. {
  537. return $this->name;
  538. }
  539. /**
  540. * Retrieves data from memory in one chunk, or from disk in $buffer
  541. * sized chunks.
  542. *
  543. * @return string The data
  544. */
  545. function getData()
  546. {
  547. $buffer = 4096;
  548. // Return data stored in memory
  549. if (isset($this->_data)) {
  550. $tmp = $this->_data;
  551. unset($this->_data);
  552. $fh = $this->_filehandle;
  553. if ($this->_using_tmpfile) {
  554. fseek($fh, 0);
  555. }
  556. return $tmp;
  557. }
  558. // Return data stored on disk
  559. if ($this->_using_tmpfile) {
  560. if ($tmp = fread($this->_filehandle, $buffer)) {
  561. return $tmp;
  562. }
  563. }
  564. // No data to return
  565. return '';
  566. }
  567. /**
  568. * Sets a merged cell range
  569. *
  570. * @access public
  571. * @param integer $first_row First row of the area to merge
  572. * @param integer $first_col First column of the area to merge
  573. * @param integer $last_row Last row of the area to merge
  574. * @param integer $last_col Last column of the area to merge
  575. */
  576. function setMerge($first_row, $first_col, $last_row, $last_col)
  577. {
  578. if (($last_row < $first_row) || ($last_col < $first_col)) {
  579. return;
  580. }
  581. // don't check rowmin, rowmax, etc... because we don't know when this
  582. // is going to be called
  583. $this->_merged_ranges[] = array($first_row, $first_col, $last_row, $last_col);
  584. }
  585. /**
  586. * Set this worksheet as a selected worksheet,
  587. * i.e. the worksheet has its tab highlighted.
  588. *
  589. * @access public
  590. */
  591. function select()
  592. {
  593. $this->selected = 1;
  594. }
  595. /**
  596. * Set this worksheet as the active worksheet,
  597. * i.e. the worksheet that is displayed when the workbook is opened.
  598. * Also set it as selected.
  599. *
  600. * @access public
  601. */
  602. function activate()
  603. {
  604. $this->selected = 1;
  605. $this->activesheet = $this->index;
  606. }
  607. /**
  608. * Set this worksheet as the first visible sheet.
  609. * This is necessary when there are a large number of worksheets and the
  610. * activated worksheet is not visible on the screen.
  611. *
  612. * @access public
  613. */
  614. function setFirstSheet()
  615. {
  616. $this->firstsheet = $this->index;
  617. }
  618. /**
  619. * Set the worksheet protection flag
  620. * to prevent accidental modification and to
  621. * hide formulas if the locked and hidden format properties have been set.
  622. *
  623. * @access public
  624. * @param string $password The password to use for protecting the sheet.
  625. */
  626. function protect($password)
  627. {
  628. $this->_protect = 1;
  629. $this->_password = $this->_encodePassword($password);
  630. }
  631. /**
  632. * Set the width of a single column or a range of columns.
  633. *
  634. * @access public
  635. * @param integer $firstcol first column on the range
  636. * @param integer $lastcol last column on the range
  637. * @param integer $width width to set
  638. * @param mixed $format The optional XF format to apply to the columns
  639. * @param integer $hidden The optional hidden atribute
  640. * @param integer $level The optional outline level
  641. */
  642. function setColumn($firstcol, $lastcol, $width, $format = null, $hidden = 0, $level = 0)
  643. {
  644. $this->_colinfo[] = array($firstcol, $lastcol, $width, &$format, $hidden, $level);
  645. // Set width to zero if column is hidden
  646. $width = ($hidden) ? 0 : $width;
  647. for ($col = $firstcol; $col <= $lastcol; $col++) {
  648. $this->col_sizes[$col] = $width;
  649. }
  650. }
  651. /**
  652. * Set which cell or cells are selected in a worksheet
  653. *
  654. * @access public
  655. * @param integer $first_row first row in the selected quadrant
  656. * @param integer $first_column first column in the selected quadrant
  657. * @param integer $last_row last row in the selected quadrant
  658. * @param integer $last_column last column in the selected quadrant
  659. */
  660. function setSelection($first_row,$first_column,$last_row,$last_column)
  661. {
  662. $this->_selection = array($first_row,$first_column,$last_row,$last_column);
  663. }
  664. /**
  665. * Set panes and mark them as frozen.
  666. *
  667. * @access public
  668. * @param array $panes This is the only parameter received and is composed of the following:
  669. * 0 => Vertical split position,
  670. * 1 => Horizontal split position
  671. * 2 => Top row visible
  672. * 3 => Leftmost column visible
  673. * 4 => Active pane
  674. */
  675. function freezePanes($panes)
  676. {
  677. $this->_frozen = 1;
  678. $this->_panes = $panes;
  679. }
  680. /**
  681. * Set panes and mark them as unfrozen.
  682. *
  683. * @access public
  684. * @param array $panes This is the only parameter received and is composed of the following:
  685. * 0 => Vertical split position,
  686. * 1 => Horizontal split position
  687. * 2 => Top row visible
  688. * 3 => Leftmost column visible
  689. * 4 => Active pane
  690. */
  691. function thawPanes($panes)
  692. {
  693. $this->_frozen = 0;
  694. $this->_panes = $panes;
  695. }
  696. /**
  697. * Set the page orientation as portrait.
  698. *
  699. * @access public
  700. */
  701. function setPortrait()
  702. {
  703. $this->_orientation = 1;
  704. }
  705. /**
  706. * Set the page orientation as landscape.
  707. *
  708. * @access public
  709. */
  710. function setLandscape()
  711. {
  712. $this->_orientation = 0;
  713. }
  714. /**
  715. * Set the paper type. Ex. 1 = US Letter, 9 = A4
  716. *
  717. * @access public
  718. * @param integer $size The type of paper size to use
  719. */
  720. function setPaper($size = 0)
  721. {
  722. $this->_paper_size = $size;
  723. }
  724. /**
  725. * Set the page header caption and optional margin.
  726. *
  727. * @access public
  728. * @param string $string The header text
  729. * @param float $margin optional head margin in inches.
  730. */
  731. function setHeader($string,$margin = 0.50)
  732. {
  733. if (strlen($string) >= 255) {
  734. //carp 'Header string must be less than 255 characters';
  735. return;
  736. }
  737. $this->_header = $string;
  738. $this->_margin_head = $margin;
  739. }
  740. /**
  741. * Set the page footer caption and optional margin.
  742. *
  743. * @access public
  744. * @param string $string The footer text
  745. * @param float $margin optional foot margin in inches.
  746. */
  747. function setFooter($string,$margin = 0.50)
  748. {
  749. if (strlen($string) >= 255) {
  750. //carp 'Footer string must be less than 255 characters';
  751. return;
  752. }
  753. $this->_footer = $string;
  754. $this->_margin_foot = $margin;
  755. }
  756. /**
  757. * Center the page horinzontally.
  758. *
  759. * @access public
  760. * @param integer $center the optional value for centering. Defaults to 1 (center).
  761. */
  762. function centerHorizontally($center = 1)
  763. {
  764. $this->_hcenter = $center;
  765. }
  766. /**
  767. * Center the page vertically.
  768. *
  769. * @access public
  770. * @param integer $center the optional value for centering. Defaults to 1 (center).
  771. */
  772. function centerVertically($center = 1)
  773. {
  774. $this->_vcenter = $center;
  775. }
  776. /**
  777. * Set all the page margins to the same value in inches.
  778. *
  779. * @access public
  780. * @param float $margin The margin to set in inches
  781. */
  782. function setMargins($margin)
  783. {
  784. $this->setMarginLeft($margin);
  785. $this->setMarginRight($margin);
  786. $this->setMarginTop($margin);
  787. $this->setMarginBottom($margin);
  788. }
  789. /**
  790. * Set the left and right margins to the same value in inches.
  791. *
  792. * @access public
  793. * @param float $margin The margin to set in inches
  794. */
  795. function setMargins_LR($margin)
  796. {
  797. $this->setMarginLeft($margin);
  798. $this->setMarginRight($margin);
  799. }
  800. /**
  801. * Set the top and bottom margins to the same value in inches.
  802. *
  803. * @access public
  804. * @param float $margin The margin to set in inches
  805. */
  806. function setMargins_TB($margin)
  807. {
  808. $this->setMarginTop($margin);
  809. $this->setMarginBottom($margin);
  810. }
  811. /**
  812. * Set the left margin in inches.
  813. *
  814. * @access public
  815. * @param float $margin The margin to set in inches
  816. */
  817. function setMarginLeft($margin = 0.75)
  818. {
  819. $this->_margin_left = $margin;
  820. }
  821. /**
  822. * Set the right margin in inches.
  823. *
  824. * @access public
  825. * @param float $margin The margin to set in inches
  826. */
  827. function setMarginRight($margin = 0.75)
  828. {
  829. $this->_margin_right = $margin;
  830. }
  831. /**
  832. * Set the top margin in inches.
  833. *
  834. * @access public
  835. * @param float $margin The margin to set in inches
  836. */
  837. function setMarginTop($margin = 1.00)
  838. {
  839. $this->_margin_top = $margin;
  840. }
  841. /**
  842. * Set the bottom margin in inches.
  843. *
  844. * @access public
  845. * @param float $margin The margin to set in inches
  846. */
  847. function setMarginBottom($margin = 1.00)
  848. {
  849. $this->_margin_bottom = $margin;
  850. }
  851. /**
  852. * Set the rows to repeat at the top of each printed page.
  853. *
  854. * @access public
  855. * @param integer $first_row First row to repeat
  856. * @param integer $last_row Last row to repeat. Optional.
  857. */
  858. function repeatRows($first_row, $last_row = null)
  859. {
  860. $this->title_rowmin = $first_row;
  861. if (isset($last_row)) { //Second row is optional
  862. $this->title_rowmax = $last_row;
  863. } else {
  864. $this->title_rowmax = $first_row;
  865. }
  866. }
  867. /**
  868. * Set the columns to repeat at the left hand side of each printed page.
  869. *
  870. * @access public
  871. * @param integer $first_col First column to repeat
  872. * @param integer $last_col Last column to repeat. Optional.
  873. */
  874. function repeatColumns($first_col, $last_col = null)
  875. {
  876. $this->title_colmin = $first_col;
  877. if (isset($last_col)) { // Second col is optional
  878. $this->title_colmax = $last_col;
  879. } else {
  880. $this->title_colmax = $first_col;
  881. }
  882. }
  883. /**
  884. * Set the area of each worksheet that will be printed.
  885. *
  886. * @access public
  887. * @param integer $first_row First row of the area to print
  888. * @param integer $first_col First column of the area to print
  889. * @param integer $last_row Last row of the area to print
  890. * @param integer $last_col Last column of the area to print
  891. */
  892. function printArea($first_row, $first_col, $last_row, $last_col)
  893. {
  894. $this->print_rowmin = $first_row;
  895. $this->print_colmin = $first_col;
  896. $this->print_rowmax = $last_row;
  897. $this->print_colmax = $last_col;
  898. }
  899. /**
  900. * Set the option to hide gridlines on the printed page.
  901. *
  902. * @access public
  903. */
  904. function hideGridlines()
  905. {
  906. $this->_print_gridlines = 0;
  907. }
  908. /**
  909. * Set the option to hide gridlines on the worksheet (as seen on the screen).
  910. *
  911. * @access public
  912. */
  913. function hideScreenGridlines()
  914. {
  915. $this->_screen_gridlines = 0;
  916. }
  917. /**
  918. * Set the option to print the row and column headers on the printed page.
  919. *
  920. * @access public
  921. * @param integer $print Whether to print the headers or not. Defaults to 1 (print).
  922. */
  923. function printRowColHeaders($print = 1)
  924. {
  925. $this->_print_headers = $print;
  926. }
  927. /**
  928. * Set the vertical and horizontal number of pages that will define the maximum area printed.
  929. * It doesn't seem to work with OpenOffice.
  930. *
  931. * @access public
  932. * @param integer $width Maximun width of printed area in pages
  933. * @param integer $height Maximun heigth of printed area in pages
  934. * @see setPrintScale()
  935. */
  936. function fitToPages($width, $height)
  937. {
  938. $this->_fit_page = 1;
  939. $this->_fit_width = $width;
  940. $this->_fit_height = $height;
  941. }
  942. /**
  943. * Store the horizontal page breaks on a worksheet (for printing).
  944. * The breaks represent the row after which the break is inserted.
  945. *
  946. * @access public
  947. * @param array $breaks Array containing the horizontal page breaks
  948. */
  949. function setHPagebreaks($breaks)
  950. {
  951. foreach ($breaks as $break) {
  952. array_push($this->_hbreaks, $break);
  953. }
  954. }
  955. /**
  956. * Store the vertical page breaks on a worksheet (for printing).
  957. * The breaks represent the column after which the break is inserted.
  958. *
  959. * @access public
  960. * @param array $breaks Array containing the vertical page breaks
  961. */
  962. function setVPagebreaks($breaks)
  963. {
  964. foreach ($breaks as $break) {
  965. array_push($this->_vbreaks, $break);
  966. }
  967. }
  968. /**
  969. * Set the worksheet zoom factor.
  970. *
  971. * @access public
  972. * @param integer $scale The zoom factor
  973. */
  974. function setZoom($scale = 100)
  975. {
  976. // Confine the scale to Excel's range
  977. if ($scale < 10 || $scale > 400) {
  978. $this->raiseError("Zoom factor $scale outside range: 10 <= zoom <= 400");
  979. $scale = 100;
  980. }
  981. $this->_zoom = floor($scale);
  982. }
  983. /**
  984. * Set the scale factor for the printed page.
  985. * It turns off the "fit to page" option
  986. *
  987. * @access public
  988. * @param integer $scale The optional scale factor. Defaults to 100
  989. */
  990. function setPrintScale($scale = 100)
  991. {
  992. // Confine the scale to Excel's range
  993. if ($scale < 10 || $scale > 400) {
  994. $this->raiseError("Print scale $scale outside range: 10 <= zoom <= 400");
  995. $scale = 100;
  996. }
  997. // Turn off "fit to page" option
  998. $this->_fit_page = 0;
  999. $this->_print_scale = floor($scale);
  1000. }
  1001. /**
  1002. * Map to the appropriate write method acording to the token recieved.
  1003. *
  1004. * @access public
  1005. * @param integer $row The row of the cell we are writing to
  1006. * @param integer $col The column of the cell we are writing to
  1007. * @param mixed $token What we are writing
  1008. * @param mixed $format The optional format to apply to the cell
  1009. */
  1010. function write($row, $col, $token, $format = null)
  1011. {
  1012. // Check for a cell reference in A1 notation and substitute row and column
  1013. /*if ($_[0] =~ /^\D/) {
  1014. @_ = $this->_substituteCellref(@_);
  1015. }*/
  1016. if (preg_match("/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/", $token)) {
  1017. // Match number
  1018. return $this->writeNumber($row, $col, $token, $format);
  1019. } elseif (preg_match("/^[fh]tt?p:\/\//", $token)) {
  1020. // Match http or ftp URL
  1021. return $this->writeUrl($row, $col, $token, '', $format);
  1022. } elseif (preg_match("/^mailto:/", $token)) {
  1023. // Match mailto:
  1024. return $this->writeUrl($row, $col, $token, '', $format);
  1025. } elseif (preg_match("/^(?:in|ex)ternal:/", $token)) {
  1026. // Match internal or external sheet link
  1027. return $this->writeUrl($row, $col, $token, '', $format);
  1028. } elseif (preg_match("/^=/", $token)) {
  1029. // Match formula
  1030. return $this->writeFormula($row, $col, $token, $format);
  1031. } elseif ($token == '') {
  1032. // Match blank
  1033. return $this->writeBlank($row, $col, $format);
  1034. } else {
  1035. // Default: match string
  1036. return $this->writeString($row, $col, $token, $format);
  1037. }
  1038. }
  1039. /**
  1040. * Write an array of values as a row
  1041. *
  1042. * @access public
  1043. * @param integer $row The row we are writing to
  1044. * @param integer $col The first col (leftmost col) we are writing to
  1045. * @param array $val The array of values to write
  1046. * @param mixed $format The optional format to apply to the cell
  1047. * @return mixed PEAR_Error on failure
  1048. */
  1049. function writeRow($row, $col, $val, $format = null)
  1050. {
  1051. $retval = '';
  1052. if (is_array($val)) {
  1053. foreach ($val as $v) {
  1054. if (is_array($v)) {
  1055. $this->writeCol($row, $col, $v, $format);
  1056. } else {
  1057. $this->write($row, $col, $v, $format);
  1058. }
  1059. $col++;
  1060. }
  1061. } else {
  1062. $retval = new PEAR_Error('$val needs to be an array');
  1063. }
  1064. return($retval);
  1065. }
  1066. /**
  1067. * Write an array of values as a column
  1068. *
  1069. * @access public
  1070. * @param integer $row The first row (uppermost row) we are writing to
  1071. * @param integer $col The col we are writing to
  1072. * @param array $val The array of values to write
  1073. * @param mixed $format The optional format to apply to the cell
  1074. * @return mixed PEAR_Error on failure
  1075. */
  1076. function writeCol($row, $col, $val, $format = null)
  1077. {
  1078. $retval = '';
  1079. if (is_array($val)) {
  1080. foreach ($val as $v) {
  1081. $this->write($row, $col, $v, $format);
  1082. $row++;
  1083. }
  1084. } else {
  1085. $retval = new PEAR_Error('$val needs to be an array');
  1086. }
  1087. return($retval);
  1088. }
  1089. /**
  1090. * Returns an index to the XF record in the workbook
  1091. *
  1092. * @access private
  1093. * @param mixed &$format The optional XF format
  1094. * @return integer The XF record index
  1095. */
  1096. function _XF(&$format)
  1097. {
  1098. if ($format) {
  1099. return($format->getXfIndex());
  1100. } else {
  1101. return(0x0F);
  1102. }
  1103. }
  1104. /******************************************************************************
  1105. *******************************************************************************
  1106. *
  1107. * Internal methods
  1108. */
  1109. /**
  1110. * Store Worksheet data in memory using the parent's class append() or to a
  1111. * temporary file, the default.
  1112. *
  1113. * @access private
  1114. * @param string $data The binary data to append
  1115. */
  1116. function _append($data)
  1117. {
  1118. if ($this->_using_tmpfile) {
  1119. // Add CONTINUE records if necessary
  1120. if (strlen($data) > $this->_limit) {
  1121. $data = $this->_addContinue($data);
  1122. }
  1123. fwrite($this->_filehandle, $data);
  1124. $this->_datasize += strlen($data);
  1125. } else {
  1126. parent::_append($data);
  1127. }
  1128. }
  1129. /**
  1130. * Substitute an Excel cell reference in A1 notation for zero based row and
  1131. * column values in an argument list.
  1132. *
  1133. * Ex: ("A4", "Hello") is converted to (3, 0, "Hello").
  1134. *
  1135. * @access private
  1136. * @param string $cell The cell reference. Or range of cells.
  1137. * @return array
  1138. */
  1139. function _substituteCellref($cell)
  1140. {
  1141. $cell = strtoupper($cell);
  1142. // Convert a column range: 'A:A' or 'B:G'
  1143. if (preg_match("/([A-I]?[A-Z]):([A-I]?[A-Z])/", $cell, $match)) {
  1144. list($no_use, $col1) = $this->_cellToRowcol($match[1] .'1'); // Add a dummy row
  1145. list($no_use, $col2) = $this->_cellToRowcol($match[2] .'1'); // Add a dummy row
  1146. return(array($col1, $col2));
  1147. }
  1148. // Convert a cell range: 'A1:B7'
  1149. if (preg_match("/\$?([A-I]?[A-Z]\$?\d+):\$?([A-I]?[A-Z]\$?\d+)/", $cell, $match)) {
  1150. list($row1, $col1) = $this->_cellToRowcol($match[1]);
  1151. list($row2, $col2) = $this->_cellToRowcol($match[2]);
  1152. return(array($row1, $col1, $row2, $col2));
  1153. }
  1154. // Convert a cell reference: 'A1' or 'AD2000'
  1155. if (preg_match("/\$?([A-I]?[A-Z]\$?\d+)/", $cell)) {
  1156. list($row1, $col1) = $this->_cellToRowcol($match[1]);
  1157. return(array($row1, $col1));
  1158. }
  1159. // TODO use real error codes
  1160. $this->raiseError("Unknown cell reference $cell", 0, PEAR_ERROR_DIE);
  1161. }
  1162. /**
  1163. * Convert an Excel cell reference in A1 notation to a zero based row and column
  1164. * reference; converts C1 to (0, 2).
  1165. *
  1166. * @access private
  1167. * @param string $cell The cell reference.
  1168. * @return array containing (row, column)
  1169. */
  1170. function _cellToRowcol($cell)
  1171. {
  1172. preg_match("/\$?([A-I]?[A-Z])\$?(\d+)/",$cell,$match);
  1173. $col = $match[1];
  1174. $row = $match[2];
  1175. // Convert base26 column string to number
  1176. $chars = split('', $col);
  1177. $expn = 0;
  1178. $col = 0;
  1179. while ($chars) {
  1180. $char = array_pop($chars); // LS char first
  1181. $col += (ord($char) -ord('A') +1) * pow(26,$expn);
  1182. $expn++;
  1183. }
  1184. // Convert 1-index to zero-index
  1185. $row--;
  1186. $col--;
  1187. return(array($row, $col));
  1188. }
  1189. /**
  1190. * Based on the algorithm provided by Daniel Rentz of OpenOffice.
  1191. *
  1192. * @access private
  1193. * @param string $plaintext The password to be encoded in plaintext.
  1194. * @return string The encoded password
  1195. */
  1196. function _encodePassword($plaintext)
  1197. {
  1198. $password = 0x0000;
  1199. $i = 1; // char position
  1200. // split the plain text password in its component characters
  1201. $chars = preg_split('//', $plaintext, -1, PREG_SPLIT_NO_EMPTY);
  1202. foreach ($chars as $char) {
  1203. $value = ord($char) << $i; // shifted ASCII value
  1204. $rotated_bits = $value >> 15; // rotated bits beyond bit 15
  1205. $value &= 0x7fff; // first 15 bits
  1206. $password ^= ($value | $rotated_bits);
  1207. $i++;
  1208. }
  1209. $password ^= strlen($plaintext);
  1210. $password ^= 0xCE4B;
  1211. return($password);
  1212. }
  1213. /**
  1214. * This method sets the properties for outlining and grouping. The defaults
  1215. * correspond to Excel's defaults.
  1216. *
  1217. * @param bool $visible
  1218. * @param bool $symbols_below
  1219. * @param bool $symbols_right
  1220. * @param bool $auto_style
  1221. */
  1222. function setOutline($visible = true, $symbols_below = true, $symbols_right = true, $auto_style = false)
  1223. {
  1224. $this->_outline_on = $visible;
  1225. $this->_outline_below = $symbols_below;
  1226. $this->_outline_right = $symbols_right;
  1227. $this->_outline_style = $auto_style;
  1228. // Ensure this is a boolean vale for Window2
  1229. if ($this->_outline_on) {
  1230. $this->_outline_on = 1;
  1231. }
  1232. }
  1233. /******************************************************************************
  1234. *******************************************************************************
  1235. *
  1236. * BIFF RECORDS
  1237. */
  1238. /**
  1239. * Write a double to the specified row and column (zero indexed).
  1240. * An integer can be written as a double. Excel will display an
  1241. * integer. $format is optional.
  1242. *
  1243. * Returns 0 : normal termination
  1244. * -2 : row or column out of range
  1245. *
  1246. * @access public
  1247. * @param integer $row Zero indexed row
  1248. * @param integer $col Zero indexed column
  1249. * @param float $num The number to write
  1250. * @param mixed $format The optional XF format
  1251. * @return integer
  1252. */
  1253. function writeNumber($row, $col, $num, $format = null)
  1254. {
  1255. $record = 0x0203; // Record identifier
  1256. $length = 0x000E; // Number of bytes to follow
  1257. $xf = $this->_XF($format); // The cell format
  1258. // Check that row and col are valid and store max and min values
  1259. if ($row >= $this->_xls_rowmax) {
  1260. return(-2);
  1261. }
  1262. if ($col >= $this->_xls_colmax) {
  1263. return(-2);
  1264. }
  1265. if ($row < $this->_dim_rowmin) {
  1266. $this->_dim_rowmin = $row;
  1267. }
  1268. if ($row > $this->_dim_rowmax) {
  1269. $this->_dim_rowmax = $row;
  1270. }
  1271. if ($col < $this->_dim_colmin) {
  1272. $this->_dim_colmin = $col;
  1273. }
  1274. if ($col > $this->_dim_colmax) {
  1275. $this->_dim_colmax = $col;
  1276. }
  1277. $header = pack("vv", $record, $length);
  1278. $data = pack("vvv", $row, $col, $xf);
  1279. $xl_double = pack("d", $num);
  1280. if ($this->_byte_order) { // if it's Big Endian
  1281. $xl_double = strrev($xl_double);
  1282. }
  1283. $this->_append($header.$data.$xl_double);
  1284. return(0);
  1285. }
  1286. /**
  1287. * Write a string to the specified row and column (zero indexed).
  1288. * NOTE: there is an Excel 5 defined limit of 255 characters.
  1289. * $format is optional.
  1290. * Returns 0 : normal termination
  1291. * -2 : row or column out of range
  1292. * -3 : long string truncated to 255 chars
  1293. *
  1294. * @access public
  1295. * @param integer $row Zero indexed row
  1296. * @param integer $col Zero indexed column
  1297. * @param string $str The string to write
  1298. * @param mixed $format The XF format for the cell
  1299. * @return integer
  1300. */
  1301. function writeString($row, $col, $str, $format = null)
  1302. {
  1303. if ($this->_BIFF_version == 0x0600) {
  1304. return $this->writeStringBIFF8($row, $col, $str, $format);
  1305. }
  1306. $strlen = strlen($str);
  1307. $record = 0x0204; // Record identifier
  1308. $length = 0x0008 + $strlen; // Bytes to follow
  1309. $xf = $this->_XF($format); // The cell format
  1310. $str_error = 0;
  1311. // Check that row and col are valid and store max and min values
  1312. if ($row >= $this->_xls_rowmax) {
  1313. return(-2);
  1314. }
  1315. if ($col >= $this->_xls_colmax) {
  1316. return(-2);
  1317. }
  1318. if ($row < $this->_dim_rowmin) {
  1319. $this->_dim_rowmin = $row;
  1320. }
  1321. if ($row > $this->_dim_rowmax) {
  1322. $this->_dim_rowmax = $row;
  1323. }
  1324. if ($col < $this->_dim_colmin) {
  1325. $this->_dim_colmin = $col;
  1326. }
  1327. if ($col > $this->_dim_colmax) {
  1328. $this->_dim_colmax = $col;
  1329. }
  1330. if ($strlen > $this->_xls_strmax) { // LABEL must be < 255 chars
  1331. $str = substr($str, 0, $this->_xls_strmax);
  1332. $length = 0x0008 + $this->_xls_strmax;
  1333. $strlen = $this->_xls_strmax;
  1334. $str_error = -3;
  1335. }
  1336. $header = pack("vv", $record, $length);
  1337. $data = pack("vvvv", $row, $col, $xf, $strlen);
  1338. $this->_append($header . $data . $str);
  1339. return($str_error);
  1340. }
  1341. /**
  1342. * Sets Input Encoding for writing strings
  1343. *
  1344. * @access public
  1345. * @param string $encoding The encoding. Ex: 'UTF-16LE', 'utf-8', 'ISO-859-7'
  1346. */
  1347. function setInputEncoding($encoding)
  1348. {
  1349. if ($encoding != 'UTF-16LE' && !function_exists('iconv')) {
  1350. $this->raiseError("Using an input encoding other than UTF-16LE requires PHP support for iconv");
  1351. }
  1352. $this->_input_encoding = $encoding;
  1353. }
  1354. /**
  1355. * Write a string to the specified row and column (zero indexed).
  1356. * This is the BIFF8 version (no 255 chars limit).
  1357. * $format is optional.
  1358. * Returns 0 : normal termination
  1359. * -2 : row or column out of range
  1360. * -3 : long string truncated to 255 chars
  1361. *
  1362. * @access public
  1363. * @param integer $row Zero indexed row
  1364. * @param integer $col Zero indexed column
  1365. * @param string $str The string to write
  1366. * @param mixed $format The XF format for the cell
  1367. * @return integer
  1368. */
  1369. function writeStringBIFF8($row, $col, $str, $format = null)
  1370. {
  1371. if ($this->_input_encoding == 'UTF-16LE')
  1372. {
  1373. $strlen = function_exists('mb_strlen') ? mb_strlen($str, 'UTF-16LE') : (strlen($str) / 2);
  1374. $encoding = 0x1;
  1375. }
  1376. elseif ($this->_input_encoding != '')
  1377. {
  1378. $str = iconv($this->_input_encoding, 'UTF-16LE', $str);
  1379. $strlen = function_exists('mb_strlen') ? mb_strlen($str, 'UTF-16LE') : (strlen($str) / 2);
  1380. $encoding = 0x1;
  1381. }
  1382. else
  1383. {
  1384. $strlen = strlen($str);
  1385. $encoding = 0x0;
  1386. }
  1387. $record = 0x00FD; // Record identifier
  1388. $length = 0x000A; // Bytes to follow
  1389. $xf = $this->_XF($format); // The cell format
  1390. $str_error = 0;
  1391. // Check that row and col are valid and store max and min values
  1392. if ($this->_checkRowCol($row, $col) == false) {
  1393. return -2;
  1394. }
  1395. $str = pack('vC', $strlen, $encoding).$str;
  1396. /* check if string is already present */
  1397. if (!isset($this->_str_table[$str])) {
  1398. $this->_str_table[$str] = $this->_str_unique++;
  1399. }
  1400. $this->_str_total++;
  1401. $header = pack('vv', $record, $length);
  1402. $data = pack('vvvV', $row, $col, $xf, $this->_str_table[$str]);
  1403. $this->_append($header.$data);
  1404. return $str_error;
  1405. }
  1406. /**
  1407. * Check row and col before writing to a cell, and update the sheet's
  1408. * dimensions accordingly
  1409. *
  1410. * @access private
  1411. * @param integer $row Zero indexed row
  1412. * @param integer $col Zero indexed column
  1413. * @return boolean true for success, false if row and/or col are grester
  1414. * then maximums allowed.
  1415. */
  1416. function _checkRowCol($row, $col)
  1417. {
  1418. if ($row >= $this->_xls_rowmax) {
  1419. return false;
  1420. }
  1421. if ($col >= $this->_xls_colmax) {
  1422. return false;
  1423. }
  1424. if ($row < $this->_dim_rowmin) {
  1425. $this->_dim_rowmin = $row;
  1426. }
  1427. if ($row > $this->_dim_rowmax) {
  1428. $this->_dim_rowmax = $row;
  1429. }
  1430. if ($col < $this->_dim_colmin) {
  1431. $this->_dim_colmin = $col;
  1432. }
  1433. if ($col > $this->_dim_colmax) {
  1434. $this->_dim_colmax = $col;
  1435. }
  1436. return true;
  1437. }
  1438. /**
  1439. * Writes a note associated with the cell given by the row and column.
  1440. * NOTE records don't have a length limit.
  1441. *
  1442. * @access public
  1443. * @param integer $row Zero indexed row
  1444. * @param integer $col Zero indexed column
  1445. * @param string $note The note to write
  1446. */
  1447. function writeNote($row, $col, $note)
  1448. {
  1449. $note_length = strlen($note);
  1450. $record = 0x001C; // Record identifier
  1451. $max_length = 2048; // Maximun length for a NOTE record
  1452. //$length = 0x0006 + $note_length; // Bytes to follow
  1453. // Check that row and col are valid and store max and min values
  1454. if ($row >= $this->_xls_rowmax) {
  1455. return(-2);
  1456. }
  1457. if ($col >= $this->_xls_colmax) {
  1458. return(-2);
  1459. }
  1460. if ($row < $this->_dim_rowmin) {
  1461. $this->_dim_rowmin = $row;
  1462. }
  1463. if ($row > $this->_dim_rowmax) {
  1464. $this->_dim_rowmax = $row;
  1465. }
  1466. if ($col < $this->_dim_colmin) {
  1467. $this->_dim_colmin = $col;
  1468. }
  1469. if ($col > $this->_dim_colmax) {
  1470. $this->_dim_colmax = $col;
  1471. }
  1472. // Length for this record is no more than 2048 + 6
  1473. $length = 0x0006 + min($note_length, 2048);
  1474. $header = pack("vv", $record, $length);
  1475. $data = pack("vvv", $row, $col, $note_length);
  1476. $this->_append($header . $data . substr($note, 0, 2048));
  1477. for ($i = $max_length; $i < $note_length; $i += $max_length) {
  1478. $chunk = substr($note, $i, $max_length);
  1479. $length = 0x0006 + strlen($chunk);
  1480. $header = pack("vv", $record, $length);
  1481. $data = pack("vvv", -1, 0, strlen($chunk));
  1482. $this->_append($header.$data.$chunk);
  1483. }
  1484. return(0);
  1485. }
  1486. /**
  1487. * Write a blank cell to the specified row and column (zero indexed).
  1488. * A blank cell is used to specify formatting without adding a string
  1489. * or a number.
  1490. *
  1491. * A blank cell without a format serves no purpose. Therefore, we don't write
  1492. * a BLANK record unless a format is specified.
  1493. *
  1494. * Returns 0 : normal termination (including no format)
  1495. * -1 : insufficient number of arguments
  1496. * -2 : row or column out of rang…

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