PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/pear/Spreadsheet/Excel/Writer/Format.php

http://github.com/moodle/moodle
PHP | 1102 lines | 560 code | 118 blank | 424 comment | 112 complexity | 860bfc48af004587e9cf06d1e79f459d MD5 | raw file
Possible License(s): MIT, AGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, Apache-2.0, LGPL-2.1, BSD-3-Clause
  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 'PEAR.php';
  35. /**
  36. * Class for generating Excel XF records (formats)
  37. *
  38. * @author Xavier Noguer <xnoguer@rezebra.com>
  39. * @category FileFormats
  40. * @package Spreadsheet_Excel_Writer
  41. */
  42. class Spreadsheet_Excel_Writer_Format extends PEAR
  43. {
  44. /**
  45. * The index given by the workbook when creating a new format.
  46. * @var integer
  47. */
  48. var $_xf_index;
  49. /**
  50. * Index to the FONT record.
  51. * @var integer
  52. */
  53. var $font_index;
  54. /**
  55. * The font name (ASCII).
  56. * @var string
  57. */
  58. var $_font_name;
  59. /**
  60. * Height of font (1/20 of a point)
  61. * @var integer
  62. */
  63. var $_size;
  64. /**
  65. * Bold style
  66. * @var integer
  67. */
  68. var $_bold;
  69. /**
  70. * Bit specifiying if the font is italic.
  71. * @var integer
  72. */
  73. var $_italic;
  74. /**
  75. * Index to the cell's color
  76. * @var integer
  77. */
  78. var $_color;
  79. /**
  80. * The text underline property
  81. * @var integer
  82. */
  83. var $_underline;
  84. /**
  85. * Bit specifiying if the font has strikeout.
  86. * @var integer
  87. */
  88. var $_font_strikeout;
  89. /**
  90. * Bit specifiying if the font has outline.
  91. * @var integer
  92. */
  93. var $_font_outline;
  94. /**
  95. * Bit specifiying if the font has shadow.
  96. * @var integer
  97. */
  98. var $_font_shadow;
  99. /**
  100. * 2 bytes specifiying the script type for the font.
  101. * @var integer
  102. */
  103. var $_font_script;
  104. /**
  105. * Byte specifiying the font family.
  106. * @var integer
  107. */
  108. var $_font_family;
  109. /**
  110. * Byte specifiying the font charset.
  111. * @var integer
  112. */
  113. var $_font_charset;
  114. /**
  115. * An index (2 bytes) to a FORMAT record (number format).
  116. * @var integer
  117. */
  118. var $_num_format;
  119. /**
  120. * Bit specifying if formulas are hidden.
  121. * @var integer
  122. */
  123. var $_hidden;
  124. /**
  125. * Bit specifying if the cell is locked.
  126. * @var integer
  127. */
  128. var $_locked;
  129. /**
  130. * The three bits specifying the text horizontal alignment.
  131. * @var integer
  132. */
  133. var $_text_h_align;
  134. /**
  135. * Bit specifying if the text is wrapped at the right border.
  136. * @var integer
  137. */
  138. var $_text_wrap;
  139. /**
  140. * The three bits specifying the text vertical alignment.
  141. * @var integer
  142. */
  143. var $_text_v_align;
  144. /**
  145. * 1 bit, apparently not used.
  146. * @var integer
  147. */
  148. var $_text_justlast;
  149. /**
  150. * The two bits specifying the text rotation.
  151. * @var integer
  152. */
  153. var $_rotation;
  154. /**
  155. * The cell's foreground color.
  156. * @var integer
  157. */
  158. var $_fg_color;
  159. /**
  160. * The cell's background color.
  161. * @var integer
  162. */
  163. var $_bg_color;
  164. /**
  165. * The cell's background fill pattern.
  166. * @var integer
  167. */
  168. var $_pattern;
  169. /**
  170. * Style of the bottom border of the cell
  171. * @var integer
  172. */
  173. var $_bottom;
  174. /**
  175. * Color of the bottom border of the cell.
  176. * @var integer
  177. */
  178. var $_bottom_color;
  179. /**
  180. * Style of the top border of the cell
  181. * @var integer
  182. */
  183. var $_top;
  184. /**
  185. * Color of the top border of the cell.
  186. * @var integer
  187. */
  188. var $_top_color;
  189. /**
  190. * Style of the left border of the cell
  191. * @var integer
  192. */
  193. var $_left;
  194. /**
  195. * Color of the left border of the cell.
  196. * @var integer
  197. */
  198. var $_left_color;
  199. /**
  200. * Style of the right border of the cell
  201. * @var integer
  202. */
  203. var $_right;
  204. /**
  205. * Color of the right border of the cell.
  206. * @var integer
  207. */
  208. var $_right_color;
  209. /**
  210. * Constructor
  211. *
  212. * @access private
  213. * @param integer $index the XF index for the format.
  214. * @param array $properties array with properties to be set on initialization.
  215. */
  216. function Spreadsheet_Excel_Writer_Format($BIFF_version, $index = 0, $properties = array())
  217. {
  218. $this->_xf_index = $index;
  219. $this->_BIFF_version = $BIFF_version;
  220. $this->font_index = 0;
  221. $this->_font_name = 'Arial';
  222. $this->_size = 10;
  223. $this->_bold = 0x0190;
  224. $this->_italic = 0;
  225. $this->_color = 0x7FFF;
  226. $this->_underline = 0;
  227. $this->_font_strikeout = 0;
  228. $this->_font_outline = 0;
  229. $this->_font_shadow = 0;
  230. $this->_font_script = 0;
  231. $this->_font_family = 0;
  232. $this->_font_charset = 0;
  233. $this->_num_format = 0;
  234. $this->_hidden = 0;
  235. $this->_locked = 0;
  236. $this->_text_h_align = 0;
  237. $this->_text_wrap = 0;
  238. $this->_text_v_align = 2;
  239. $this->_text_justlast = 0;
  240. $this->_rotation = 0;
  241. $this->_fg_color = 0x40;
  242. $this->_bg_color = 0x41;
  243. $this->_pattern = 0;
  244. $this->_bottom = 0;
  245. $this->_top = 0;
  246. $this->_left = 0;
  247. $this->_right = 0;
  248. $this->_diag = 0;
  249. $this->_bottom_color = 0x40;
  250. $this->_top_color = 0x40;
  251. $this->_left_color = 0x40;
  252. $this->_right_color = 0x40;
  253. $this->_diag_color = 0x40;
  254. // Set properties passed to Spreadsheet_Excel_Writer_Workbook::addFormat()
  255. foreach ($properties as $property => $value)
  256. {
  257. if (method_exists($this, 'set'.ucwords($property))) {
  258. $method_name = 'set'.ucwords($property);
  259. $this->$method_name($value);
  260. }
  261. }
  262. }
  263. /**
  264. * Generate an Excel BIFF XF record (style or cell).
  265. *
  266. * @param string $style The type of the XF record ('style' or 'cell').
  267. * @return string The XF record
  268. */
  269. function getXf($style)
  270. {
  271. // Set the type of the XF record and some of the attributes.
  272. if ($style == 'style') {
  273. $style = 0xFFF5;
  274. } else {
  275. $style = $this->_locked;
  276. $style |= $this->_hidden << 1;
  277. }
  278. // Flags to indicate if attributes have been set.
  279. $atr_num = ($this->_num_format != 0)?1:0;
  280. $atr_fnt = ($this->font_index != 0)?1:0;
  281. $atr_alc = ($this->_text_wrap)?1:0;
  282. $atr_bdr = ($this->_bottom ||
  283. $this->_top ||
  284. $this->_left ||
  285. $this->_right)?1:0;
  286. $atr_pat = (($this->_fg_color != 0x40) ||
  287. ($this->_bg_color != 0x41) ||
  288. $this->_pattern)?1:0;
  289. $atr_prot = $this->_locked | $this->_hidden;
  290. // Zero the default border colour if the border has not been set.
  291. if ($this->_bottom == 0) {
  292. $this->_bottom_color = 0;
  293. }
  294. if ($this->_top == 0) {
  295. $this->_top_color = 0;
  296. }
  297. if ($this->_right == 0) {
  298. $this->_right_color = 0;
  299. }
  300. if ($this->_left == 0) {
  301. $this->_left_color = 0;
  302. }
  303. if ($this->_diag == 0) {
  304. $this->_diag_color = 0;
  305. }
  306. $record = 0x00E0; // Record identifier
  307. if ($this->_BIFF_version == 0x0500) {
  308. $length = 0x0010; // Number of bytes to follow
  309. }
  310. if ($this->_BIFF_version == 0x0600) {
  311. $length = 0x0014;
  312. }
  313. $ifnt = $this->font_index; // Index to FONT record
  314. $ifmt = $this->_num_format; // Index to FORMAT record
  315. if ($this->_BIFF_version == 0x0500) {
  316. $align = $this->_text_h_align; // Alignment
  317. $align |= $this->_text_wrap << 3;
  318. $align |= $this->_text_v_align << 4;
  319. $align |= $this->_text_justlast << 7;
  320. $align |= $this->_rotation << 8;
  321. $align |= $atr_num << 10;
  322. $align |= $atr_fnt << 11;
  323. $align |= $atr_alc << 12;
  324. $align |= $atr_bdr << 13;
  325. $align |= $atr_pat << 14;
  326. $align |= $atr_prot << 15;
  327. $icv = $this->_fg_color; // fg and bg pattern colors
  328. $icv |= $this->_bg_color << 7;
  329. $fill = $this->_pattern; // Fill and border line style
  330. $fill |= $this->_bottom << 6;
  331. $fill |= $this->_bottom_color << 9;
  332. $border1 = $this->_top; // Border line style and color
  333. $border1 |= $this->_left << 3;
  334. $border1 |= $this->_right << 6;
  335. $border1 |= $this->_top_color << 9;
  336. $border2 = $this->_left_color; // Border color
  337. $border2 |= $this->_right_color << 7;
  338. $header = pack("vv", $record, $length);
  339. $data = pack("vvvvvvvv", $ifnt, $ifmt, $style, $align,
  340. $icv, $fill,
  341. $border1, $border2);
  342. } elseif ($this->_BIFF_version == 0x0600) {
  343. $align = $this->_text_h_align; // Alignment
  344. $align |= $this->_text_wrap << 3;
  345. $align |= $this->_text_v_align << 4;
  346. $align |= $this->_text_justlast << 7;
  347. $used_attrib = $atr_num << 2;
  348. $used_attrib |= $atr_fnt << 3;
  349. $used_attrib |= $atr_alc << 4;
  350. $used_attrib |= $atr_bdr << 5;
  351. $used_attrib |= $atr_pat << 6;
  352. $used_attrib |= $atr_prot << 7;
  353. $icv = $this->_fg_color; // fg and bg pattern colors
  354. $icv |= $this->_bg_color << 7;
  355. $border1 = $this->_left; // Border line style and color
  356. $border1 |= $this->_right << 4;
  357. $border1 |= $this->_top << 8;
  358. $border1 |= $this->_bottom << 12;
  359. $border1 |= $this->_left_color << 16;
  360. $border1 |= $this->_right_color << 23;
  361. $diag_tl_to_rb = 0; // FIXME: add method
  362. $diag_tr_to_lb = 0; // FIXME: add method
  363. $border1 |= $diag_tl_to_rb << 30;
  364. $border1 |= $diag_tr_to_lb << 31;
  365. $border2 = $this->_top_color; // Border color
  366. $border2 |= $this->_bottom_color << 7;
  367. $border2 |= $this->_diag_color << 14;
  368. $border2 |= $this->_diag << 21;
  369. $border2 |= $this->_pattern << 26;
  370. $header = pack("vv", $record, $length);
  371. $rotation = 0x00;
  372. $biff8_options = 0x00;
  373. $data = pack("vvvC", $ifnt, $ifmt, $style, $align);
  374. $data .= pack("CCC", $rotation, $biff8_options, $used_attrib);
  375. $data .= pack("VVv", $border1, $border2, $icv);
  376. }
  377. return($header . $data);
  378. }
  379. /**
  380. * Generate an Excel BIFF FONT record.
  381. *
  382. * @return string The FONT record
  383. */
  384. function getFont()
  385. {
  386. $dyHeight = $this->_size * 20; // Height of font (1/20 of a point)
  387. $icv = $this->_color; // Index to color palette
  388. $bls = $this->_bold; // Bold style
  389. $sss = $this->_font_script; // Superscript/subscript
  390. $uls = $this->_underline; // Underline
  391. $bFamily = $this->_font_family; // Font family
  392. $bCharSet = $this->_font_charset; // Character set
  393. $encoding = 0; // TODO: Unicode support
  394. $cch = strlen($this->_font_name); // Length of font name
  395. $record = 0x31; // Record identifier
  396. if ($this->_BIFF_version == 0x0500) {
  397. $length = 0x0F + $cch; // Record length
  398. } elseif ($this->_BIFF_version == 0x0600) {
  399. $length = 0x10 + $cch;
  400. }
  401. $reserved = 0x00; // Reserved
  402. $grbit = 0x00; // Font attributes
  403. if ($this->_italic) {
  404. $grbit |= 0x02;
  405. }
  406. if ($this->_font_strikeout) {
  407. $grbit |= 0x08;
  408. }
  409. if ($this->_font_outline) {
  410. $grbit |= 0x10;
  411. }
  412. if ($this->_font_shadow) {
  413. $grbit |= 0x20;
  414. }
  415. $header = pack("vv", $record, $length);
  416. if ($this->_BIFF_version == 0x0500) {
  417. $data = pack("vvvvvCCCCC", $dyHeight, $grbit, $icv, $bls,
  418. $sss, $uls, $bFamily,
  419. $bCharSet, $reserved, $cch);
  420. } elseif ($this->_BIFF_version == 0x0600) {
  421. $data = pack("vvvvvCCCCCC", $dyHeight, $grbit, $icv, $bls,
  422. $sss, $uls, $bFamily,
  423. $bCharSet, $reserved, $cch, $encoding);
  424. }
  425. return($header . $data . $this->_font_name);
  426. }
  427. /**
  428. * Returns a unique hash key for a font.
  429. * Used by Spreadsheet_Excel_Writer_Workbook::_storeAllFonts()
  430. *
  431. * The elements that form the key are arranged to increase the probability of
  432. * generating a unique key. Elements that hold a large range of numbers
  433. * (eg. _color) are placed between two binary elements such as _italic
  434. *
  435. * @return string A key for this font
  436. */
  437. function getFontKey()
  438. {
  439. $key = "$this->_font_name$this->_size";
  440. $key .= "$this->_font_script$this->_underline";
  441. $key .= "$this->_font_strikeout$this->_bold$this->_font_outline";
  442. $key .= "$this->_font_family$this->_font_charset";
  443. $key .= "$this->_font_shadow$this->_color$this->_italic";
  444. $key = str_replace(' ', '_', $key);
  445. return ($key);
  446. }
  447. /**
  448. * Returns the index used by Spreadsheet_Excel_Writer_Worksheet::_XF()
  449. *
  450. * @return integer The index for the XF record
  451. */
  452. function getXfIndex()
  453. {
  454. return($this->_xf_index);
  455. }
  456. /**
  457. * Used in conjunction with the set_xxx_color methods to convert a color
  458. * string into a number. Color range is 0..63 but we will restrict it
  459. * to 8..63 to comply with Gnumeric. Colors 0..7 are repeated in 8..15.
  460. *
  461. * @access private
  462. * @param string $name_color name of the color (i.e.: 'blue', 'red', etc..). Optional.
  463. * @return integer The color index
  464. */
  465. function _getColor($name_color = '')
  466. {
  467. $colors = array(
  468. 'aqua' => 0x0F,
  469. 'cyan' => 0x0F,
  470. 'black' => 0x08,
  471. 'blue' => 0x0C,
  472. 'brown' => 0x10,
  473. 'magenta' => 0x0E,
  474. 'fuchsia' => 0x0E,
  475. 'gray' => 0x17,
  476. 'grey' => 0x17,
  477. 'green' => 0x11,
  478. 'lime' => 0x0B,
  479. 'navy' => 0x12,
  480. 'orange' => 0x35,
  481. 'purple' => 0x14,
  482. 'red' => 0x0A,
  483. 'silver' => 0x16,
  484. 'white' => 0x09,
  485. 'yellow' => 0x0D
  486. );
  487. // Return the default color, 0x7FFF, if undef,
  488. if ($name_color == '') {
  489. return(0x7FFF);
  490. }
  491. // or the color string converted to an integer,
  492. if (isset($colors[$name_color])) {
  493. return($colors[$name_color]);
  494. }
  495. // or the default color if string is unrecognised,
  496. if (preg_match("/\D/",$name_color)) {
  497. return(0x7FFF);
  498. }
  499. // or an index < 8 mapped into the correct range,
  500. if ($name_color < 8) {
  501. return($name_color + 8);
  502. }
  503. // or the default color if arg is outside range,
  504. if ($name_color > 63) {
  505. return(0x7FFF);
  506. }
  507. // or an integer in the valid range
  508. return($name_color);
  509. }
  510. /**
  511. * Set cell alignment.
  512. *
  513. * @access public
  514. * @param string $location alignment for the cell ('left', 'right', etc...).
  515. */
  516. function setAlign($location)
  517. {
  518. if (preg_match("/\d/",$location)) {
  519. return; // Ignore numbers
  520. }
  521. $location = strtolower($location);
  522. if ($location == 'left') {
  523. $this->_text_h_align = 1;
  524. }
  525. if ($location == 'centre') {
  526. $this->_text_h_align = 2;
  527. }
  528. if ($location == 'center') {
  529. $this->_text_h_align = 2;
  530. }
  531. if ($location == 'right') {
  532. $this->_text_h_align = 3;
  533. }
  534. if ($location == 'fill') {
  535. $this->_text_h_align = 4;
  536. }
  537. if ($location == 'justify') {
  538. $this->_text_h_align = 5;
  539. }
  540. if ($location == 'merge') {
  541. $this->_text_h_align = 6;
  542. }
  543. if ($location == 'equal_space') { // For T.K.
  544. $this->_text_h_align = 7;
  545. }
  546. if ($location == 'top') {
  547. $this->_text_v_align = 0;
  548. }
  549. if ($location == 'vcentre') {
  550. $this->_text_v_align = 1;
  551. }
  552. if ($location == 'vcenter') {
  553. $this->_text_v_align = 1;
  554. }
  555. if ($location == 'bottom') {
  556. $this->_text_v_align = 2;
  557. }
  558. if ($location == 'vjustify') {
  559. $this->_text_v_align = 3;
  560. }
  561. if ($location == 'vequal_space') { // For T.K.
  562. $this->_text_v_align = 4;
  563. }
  564. }
  565. /**
  566. * Set cell horizontal alignment.
  567. *
  568. * @access public
  569. * @param string $location alignment for the cell ('left', 'right', etc...).
  570. */
  571. function setHAlign($location)
  572. {
  573. if (preg_match("/\d/",$location)) {
  574. return; // Ignore numbers
  575. }
  576. $location = strtolower($location);
  577. if ($location == 'left') {
  578. $this->_text_h_align = 1;
  579. }
  580. if ($location == 'centre') {
  581. $this->_text_h_align = 2;
  582. }
  583. if ($location == 'center') {
  584. $this->_text_h_align = 2;
  585. }
  586. if ($location == 'right') {
  587. $this->_text_h_align = 3;
  588. }
  589. if ($location == 'fill') {
  590. $this->_text_h_align = 4;
  591. }
  592. if ($location == 'justify') {
  593. $this->_text_h_align = 5;
  594. }
  595. if ($location == 'merge') {
  596. $this->_text_h_align = 6;
  597. }
  598. if ($location == 'equal_space') { // For T.K.
  599. $this->_text_h_align = 7;
  600. }
  601. }
  602. /**
  603. * Set cell vertical alignment.
  604. *
  605. * @access public
  606. * @param string $location alignment for the cell ('top', 'vleft', 'vright', etc...).
  607. */
  608. function setVAlign($location)
  609. {
  610. if (preg_match("/\d/",$location)) {
  611. return; // Ignore numbers
  612. }
  613. $location = strtolower($location);
  614. if ($location == 'top') {
  615. $this->_text_v_align = 0;
  616. }
  617. if ($location == 'vcentre') {
  618. $this->_text_v_align = 1;
  619. }
  620. if ($location == 'vcenter') {
  621. $this->_text_v_align = 1;
  622. }
  623. if ($location == 'bottom') {
  624. $this->_text_v_align = 2;
  625. }
  626. if ($location == 'vjustify') {
  627. $this->_text_v_align = 3;
  628. }
  629. if ($location == 'vequal_space') { // For T.K.
  630. $this->_text_v_align = 4;
  631. }
  632. }
  633. /**
  634. * This is an alias for the unintuitive setAlign('merge')
  635. *
  636. * @access public
  637. */
  638. function setMerge()
  639. {
  640. $this->setAlign('merge');
  641. }
  642. /**
  643. * Sets the boldness of the text.
  644. * Bold has a range 100..1000.
  645. * 0 (400) is normal. 1 (700) is bold.
  646. *
  647. * @access public
  648. * @param integer $weight Weight for the text, 0 maps to 400 (normal text),
  649. 1 maps to 700 (bold text). Valid range is: 100-1000.
  650. It's Optional, default is 1 (bold).
  651. */
  652. function setBold($weight = 1)
  653. {
  654. if ($weight == 1) {
  655. $weight = 0x2BC; // Bold text
  656. }
  657. if ($weight == 0) {
  658. $weight = 0x190; // Normal text
  659. }
  660. if ($weight < 0x064) {
  661. $weight = 0x190; // Lower bound
  662. }
  663. if ($weight > 0x3E8) {
  664. $weight = 0x190; // Upper bound
  665. }
  666. $this->_bold = $weight;
  667. }
  668. /************************************
  669. * FUNCTIONS FOR SETTING CELLS BORDERS
  670. */
  671. /**
  672. * Sets the width for the bottom border of the cell
  673. *
  674. * @access public
  675. * @param integer $style style of the cell border. 1 => thin, 2 => thick.
  676. */
  677. function setBottom($style)
  678. {
  679. $this->_bottom = $style;
  680. }
  681. /**
  682. * Sets the width for the top border of the cell
  683. *
  684. * @access public
  685. * @param integer $style style of the cell top border. 1 => thin, 2 => thick.
  686. */
  687. function setTop($style)
  688. {
  689. $this->_top = $style;
  690. }
  691. /**
  692. * Sets the width for the left border of the cell
  693. *
  694. * @access public
  695. * @param integer $style style of the cell left border. 1 => thin, 2 => thick.
  696. */
  697. function setLeft($style)
  698. {
  699. $this->_left = $style;
  700. }
  701. /**
  702. * Sets the width for the right border of the cell
  703. *
  704. * @access public
  705. * @param integer $style style of the cell right border. 1 => thin, 2 => thick.
  706. */
  707. function setRight($style)
  708. {
  709. $this->_right = $style;
  710. }
  711. /**
  712. * Set cells borders to the same style
  713. *
  714. * @access public
  715. * @param integer $style style to apply for all cell borders. 1 => thin, 2 => thick.
  716. */
  717. function setBorder($style)
  718. {
  719. $this->setBottom($style);
  720. $this->setTop($style);
  721. $this->setLeft($style);
  722. $this->setRight($style);
  723. }
  724. /*******************************************
  725. * FUNCTIONS FOR SETTING CELLS BORDERS COLORS
  726. */
  727. /**
  728. * Sets all the cell's borders to the same color
  729. *
  730. * @access public
  731. * @param mixed $color The color we are setting. Either a string (like 'blue'),
  732. * or an integer (range is [8...63]).
  733. */
  734. function setBorderColor($color)
  735. {
  736. $this->setBottomColor($color);
  737. $this->setTopColor($color);
  738. $this->setLeftColor($color);
  739. $this->setRightColor($color);
  740. }
  741. /**
  742. * Sets the cell's bottom border color
  743. *
  744. * @access public
  745. * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
  746. */
  747. function setBottomColor($color)
  748. {
  749. $value = $this->_getColor($color);
  750. $this->_bottom_color = $value;
  751. }
  752. /**
  753. * Sets the cell's top border color
  754. *
  755. * @access public
  756. * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
  757. */
  758. function setTopColor($color)
  759. {
  760. $value = $this->_getColor($color);
  761. $this->_top_color = $value;
  762. }
  763. /**
  764. * Sets the cell's left border color
  765. *
  766. * @access public
  767. * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
  768. */
  769. function setLeftColor($color)
  770. {
  771. $value = $this->_getColor($color);
  772. $this->_left_color = $value;
  773. }
  774. /**
  775. * Sets the cell's right border color
  776. *
  777. * @access public
  778. * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
  779. */
  780. function setRightColor($color)
  781. {
  782. $value = $this->_getColor($color);
  783. $this->_right_color = $value;
  784. }
  785. /**
  786. * Sets the cell's foreground color
  787. *
  788. * @access public
  789. * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
  790. */
  791. function setFgColor($color)
  792. {
  793. $value = $this->_getColor($color);
  794. $this->_fg_color = $value;
  795. if ($this->_pattern == 0) { // force color to be seen
  796. $this->_pattern = 1;
  797. }
  798. }
  799. /**
  800. * Sets the cell's background color
  801. *
  802. * @access public
  803. * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
  804. */
  805. function setBgColor($color)
  806. {
  807. $value = $this->_getColor($color);
  808. $this->_bg_color = $value;
  809. if ($this->_pattern == 0) { // force color to be seen
  810. $this->_pattern = 1;
  811. }
  812. }
  813. /**
  814. * Sets the cell's color
  815. *
  816. * @access public
  817. * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
  818. */
  819. function setColor($color)
  820. {
  821. $value = $this->_getColor($color);
  822. $this->_color = $value;
  823. }
  824. /**
  825. * Sets the fill pattern attribute of a cell
  826. *
  827. * @access public
  828. * @param integer $arg Optional. Defaults to 1. Meaningful values are: 0-18,
  829. * 0 meaning no background.
  830. */
  831. function setPattern($arg = 1)
  832. {
  833. $this->_pattern = $arg;
  834. }
  835. /**
  836. * Sets the underline of the text
  837. *
  838. * @access public
  839. * @param integer $underline The value for underline. Possible values are:
  840. * 1 => underline, 2 => double underline.
  841. */
  842. function setUnderline($underline)
  843. {
  844. $this->_underline = $underline;
  845. }
  846. /**
  847. * Sets the font style as italic
  848. *
  849. * @access public
  850. */
  851. function setItalic()
  852. {
  853. $this->_italic = 1;
  854. }
  855. /**
  856. * Sets the font size
  857. *
  858. * @access public
  859. * @param integer $size The font size (in pixels I think).
  860. */
  861. function setSize($size)
  862. {
  863. $this->_size = $size;
  864. }
  865. /**
  866. * Sets text wrapping
  867. *
  868. * @access public
  869. */
  870. function setTextWrap()
  871. {
  872. $this->_text_wrap = 1;
  873. }
  874. /**
  875. * Sets the orientation of the text
  876. *
  877. * @access public
  878. * @param integer $angle The rotation angle for the text (clockwise). Possible
  879. values are: 0, 90, 270 and -1 for stacking top-to-bottom.
  880. */
  881. function setTextRotation($angle)
  882. {
  883. switch ($angle)
  884. {
  885. case 0:
  886. $this->_rotation = 0;
  887. break;
  888. case 90:
  889. $this->_rotation = 3;
  890. break;
  891. case 270:
  892. $this->_rotation = 2;
  893. break;
  894. case -1:
  895. $this->_rotation = 1;
  896. break;
  897. default :
  898. return $this->raiseError("Invalid value for angle.".
  899. " Possible values are: 0, 90, 270 and -1 ".
  900. "for stacking top-to-bottom.");
  901. $this->_rotation = 0;
  902. break;
  903. }
  904. }
  905. /**
  906. * Sets the numeric format.
  907. * It can be date, time, currency, etc...
  908. *
  909. * @access public
  910. * @param integer $num_format The numeric format.
  911. */
  912. function setNumFormat($num_format)
  913. {
  914. $this->_num_format = $num_format;
  915. }
  916. /**
  917. * Sets font as strikeout.
  918. *
  919. * @access public
  920. */
  921. function setStrikeOut()
  922. {
  923. $this->_font_strikeout = 1;
  924. }
  925. /**
  926. * Sets outlining for a font.
  927. *
  928. * @access public
  929. */
  930. function setOutLine()
  931. {
  932. $this->_font_outline = 1;
  933. }
  934. /**
  935. * Sets font as shadow.
  936. *
  937. * @access public
  938. */
  939. function setShadow()
  940. {
  941. $this->_font_shadow = 1;
  942. }
  943. /**
  944. * Sets the script type of the text
  945. *
  946. * @access public
  947. * @param integer $script The value for script type. Possible values are:
  948. * 1 => superscript, 2 => subscript.
  949. */
  950. function setScript($script)
  951. {
  952. $this->_font_script = $script;
  953. }
  954. /**
  955. * Locks a cell.
  956. *
  957. * @access public
  958. */
  959. function setLocked()
  960. {
  961. $this->_locked = 1;
  962. }
  963. /**
  964. * Unlocks a cell. Useful for unprotecting particular cells of a protected sheet.
  965. *
  966. * @access public
  967. */
  968. function setUnLocked()
  969. {
  970. $this->_locked = 0;
  971. }
  972. /**
  973. * Sets the font family name.
  974. *
  975. * @access public
  976. * @param string $fontfamily The font family name. Possible values are:
  977. * 'Times New Roman', 'Arial', 'Courier'.
  978. */
  979. function setFontFamily($font_family)
  980. {
  981. $this->_font_name = $font_family;
  982. }
  983. }
  984. ?>