home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Spreadsheet / Excel / Writer / Format.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  29.7 KB  |  1,103 lines

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