PageRenderTime 78ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/application/libraries/admin/pear/Spreadsheet/Excel/Writer/Worksheet.php

https://bitbucket.org/sammousa/valuematchbv-ls2
PHP | 3503 lines | 1739 code | 423 blank | 1341 comment | 268 complexity | b62abdebb05fec02ee57a2566fef7a87 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause, GPL-3.0, LGPL-3.0

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

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