Spreadsheet_Excel_Writer
[ class tree: Spreadsheet_Excel_Writer ] [ index: Spreadsheet_Excel_Writer ] [ all elements ]

Source for file Format.php

Documentation is available at Format.php

  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.             {
  303.                 $method_name 'set'.ucwords($property);
  304.                 $this->$method_name($value);
  305.             }
  306.         }
  307.     }
  308.  
  309.  
  310.     /**
  311.     * Generate an Excel BIFF XF record (style or cell).
  312.     *
  313.     * @param string $style The type of the XF record ('style' or 'cell').
  314.     * @return string The XF record
  315.     */
  316.     function getXf($style)
  317.     {
  318.         // Set the type of the XF record and some of the attributes.
  319.         if ($style == "style"{
  320.             $style = 0xFFF5;
  321.         }
  322.         else {
  323.             $style   $this->_locked;
  324.             $style  |= $this->_hidden << 1;
  325.         }
  326.     
  327.         // Flags to indicate if attributes have been set.
  328.         $atr_num     ($this->_num_format != 0)?1:0;
  329.         $atr_fnt     ($this->font_index != 0)?1:0;
  330.         $atr_alc     ($this->_text_wrap)?1:0;
  331.         $atr_bdr     ($this->_bottom   ||
  332.                         $this->_top      ||
  333.                         $this->_left     ||
  334.                         $this->_right)?1:0;
  335.         $atr_pat     (($this->_fg_color != 0x40||
  336.                         ($this->_bg_color != 0x41||
  337.                         $this->_pattern)?1:0;
  338.         $atr_prot    $this->_locked $this->_hidden;
  339.     
  340.         // Zero the default border colour if the border has not been set.
  341.         if ($this->_bottom == 0{
  342.             $this->_bottom_color = 0;
  343.         }
  344.         if ($this->_top  == 0{
  345.             $this->_top_color = 0;
  346.         }
  347.         if ($this->_right == 0{
  348.             $this->_right_color = 0;
  349.         }
  350.         if ($this->_left == 0{
  351.             $this->_left_color = 0;
  352.         }
  353.         if ($this->_diag == 0{
  354.             $this->_diag_color = 0;
  355.         }
  356.     
  357.         $record         = 0x00E0;              // Record identifier
  358.         if ($this->_BIFF_version == 0x0500{
  359.             $length         = 0x0010;              // Number of bytes to follow
  360.         }
  361.         if ($this->_BIFF_version == 0x0600{
  362.             $length         = 0x0014;
  363.         }
  364.                                                
  365.         $ifnt           $this->font_index;   // Index to FONT record
  366.         $ifmt           $this->_num_format;  // Index to FORMAT record
  367.         if ($this->_BIFF_version == 0x0500)
  368.         {
  369.             $align          $this->_text_h_align;       // Alignment
  370.             $align         |= $this->_text_wrap     << 3;
  371.             $align         |= $this->_text_v_align  << 4;
  372.             $align         |= $this->_text_justlast << 7;
  373.             $align         |= $this->_rotation      << 8;
  374.             $align         |= $atr_num                << 10;
  375.             $align         |= $atr_fnt                << 11;
  376.             $align         |= $atr_alc                << 12;
  377.             $align         |= $atr_bdr                << 13;
  378.             $align         |= $atr_pat                << 14;
  379.             $align         |= $atr_prot               << 15;
  380.  
  381.             $icv            $this->_fg_color;       // fg and bg pattern colors
  382.             $icv           |= $this->_bg_color      << 7;
  383.      
  384.             $fill           $this->_pattern;        // Fill and border line style
  385.             $fill          |= $this->_bottom        << 6;
  386.             $fill          |= $this->_bottom_color  << 9;
  387.      
  388.             $border1        $this->_top;            // Border line style and color
  389.             $border1       |= $this->_left          << 3;
  390.             $border1       |= $this->_right         << 6;
  391.             $border1       |= $this->_top_color     << 9;
  392.      
  393.             $border2        $this->_left_color;     // Border color
  394.             $border2       |= $this->_right_color   << 7;
  395.          
  396.             $header      pack("vv",       $record$length);
  397.             $data        pack("vvvvvvvv"$ifnt$ifmt$style$align,
  398.                                             $icv$fill,
  399.                                             $border1$border2);
  400.         }
  401.         elseif ($this->_BIFF_version == 0x0600)
  402.         {
  403.             $align          $this->_text_h_align;       // Alignment
  404.             $align         |= $this->_text_wrap     << 3;
  405.             $align         |= $this->_text_v_align  << 4;
  406.             $align         |= $this->_text_justlast << 7;
  407.  
  408.             $used_attrib    $atr_num              << 2;
  409.             $used_attrib   |= $atr_fnt              << 3;
  410.             $used_attrib   |= $atr_alc              << 4;
  411.             $used_attrib   |= $atr_bdr              << 5;
  412.             $used_attrib   |= $atr_pat              << 6;
  413.             $used_attrib   |= $atr_prot             << 7;
  414.  
  415.             $icv            $this->_fg_color;      // fg and bg pattern colors
  416.             $icv           |= $this->_bg_color      << 7;
  417.    
  418.             $border1        $this->_left;          // Border line style and color
  419.             $border1       |= $this->_right         << 4;
  420.             $border1       |= $this->_top           << 8;
  421.             $border1       |= $this->_bottom        << 12;
  422.             $border1       |= $this->_left_color    << 16;
  423.             $border1       |= $this->_right_color   << 23;
  424.             $diag_tl_to_rb = 0; // FIXME: add method
  425.             $diag_tr_to_lb = 0; // FIXME: add method
  426.             $border1       |= $diag_tl_to_rb        << 30;
  427.             $border1       |= $diag_tr_to_lb        << 31;
  428.      
  429.             $border2        $this->_top_color;    // Border color
  430.             $border2       |= $this->_bottom_color   << 7;
  431.             $border2       |= $this->_diag_color     << 14;
  432.             $border2       |= $this->_diag           << 21;
  433.             $border2       |= $this->_pattern        << 26;
  434.  
  435.             $header      pack("vv",       $record$length);
  436.  
  437.             $rotation      = 0x00;
  438.             $biff8_options = 0x00;
  439.             $data  pack("vvvC"$ifnt$ifmt$style$align);
  440.             $data .= pack("CCC"$rotation$biff8_options$used_attrib);
  441.             $data .= pack("VVv"$border1$border2$icv);
  442.         }
  443.  
  444.         return($header.$data);
  445.     }
  446.     
  447.     /**
  448.     * Generate an Excel BIFF FONT record.
  449.     *
  450.     * @return string The FONT record
  451.     */
  452.     function getFont()
  453.     {
  454.         $dyHeight   $this->_size * 20;    // Height of font (1/20 of a point)
  455.         $icv        $this->_color;        // Index to color palette
  456.         $bls        $this->_bold;         // Bold style
  457.         $sss        $this->_font_script;  // Superscript/subscript
  458.         $uls        $this->_underline;    // Underline
  459.         $bFamily    $this->_font_family;  // Font family
  460.         $bCharSet   $this->_font_charset// Character set
  461.         $encoding   = 0;                    // TODO: Unicode support
  462.     
  463.         $cch        strlen($this->_font_name)// Length of font name
  464.         $record     = 0x31;                      // Record identifier
  465.         if ($this->_BIFF_version == 0x0500{
  466.             $length     = 0x0F + $cch;            // Record length
  467.         }
  468.         elseif ($this->_BIFF_version == 0x0600{
  469.             $length     = 0x10 + $cch;
  470.         }
  471.         $reserved   = 0x00;                // Reserved
  472.         $grbit      = 0x00;                // Font attributes
  473.         if ($this->_italic{
  474.             $grbit     |= 0x02;
  475.         }
  476.         if ($this->_font_strikeout{
  477.             $grbit     |= 0x08;
  478.         }
  479.         if ($this->_font_outline{
  480.             $grbit     |= 0x10;
  481.         }
  482.         if ($this->_font_shadow{
  483.             $grbit     |= 0x20;
  484.         }
  485.     
  486.         $header  pack("vv",         $record$length);
  487.         if ($this->_BIFF_version == 0x0500{
  488.             $data    pack("vvvvvCCCCC"$dyHeight$grbit$icv$bls,
  489.                                           $sss$uls$bFamily,
  490.                                           $bCharSet$reserved$cch);
  491.         }
  492.         elseif ($this->_BIFF_version == 0x0600{
  493.             $data    pack("vvvvvCCCCCC"$dyHeight$grbit$icv$bls,
  494.                                            $sss$uls$bFamily,
  495.                                            $bCharSet$reserved$cch$encoding);
  496.         }
  497.         return($header $data$this->_font_name);
  498.     }
  499.     
  500.     /**
  501.     * Returns a unique hash key for a font.
  502.     * Used by Spreadsheet_Excel_Writer_Workbook::_storeAllFonts()
  503.     *
  504.     * The elements that form the key are arranged to increase the probability of
  505.     * generating a unique key. Elements that hold a large range of numbers
  506.     * (eg. _color) are placed between two binary elements such as _italic
  507.     *
  508.     * @return string A key for this font
  509.     */
  510.     function getFontKey()
  511.     {
  512.         $key  = "$this->_font_name$this->_size";
  513.         $key .= "$this->_font_script$this->_underline";
  514.         $key .= "$this->_font_strikeout$this->_bold$this->_font_outline";
  515.         $key .= "$this->_font_family$this->_font_charset";
  516.         $key .= "$this->_font_shadow$this->_color$this->_italic";
  517.         $key  str_replace(" ","_",$key);
  518.         return ($key);
  519.     }
  520.     
  521.     /**
  522.     * Returns the index used by Spreadsheet_Excel_Writer_Worksheet::_XF()
  523.     *
  524.     * @return integer The index for the XF record
  525.     */
  526.     function getXfIndex()
  527.     {
  528.         return($this->_xf_index);
  529.     }
  530.     
  531.     /**
  532.     * Used in conjunction with the set_xxx_color methods to convert a color
  533.     * string into a number. Color range is 0..63 but we will restrict it
  534.     * to 8..63 to comply with Gnumeric. Colors 0..7 are repeated in 8..15.
  535.     *
  536.     * @access private
  537.     * @param string $name_color name of the color (i.e.: 'blue', 'red', etc..). Optional.
  538.     * @return integer The color index
  539.     */
  540.     function _getColor($name_color '')
  541.     {
  542.         $colors = array(
  543.                         'aqua'    => 0x0F,
  544.                         'cyan'    => 0x0F,
  545.                         'black'   => 0x08,
  546.                         'blue'    => 0x0C,
  547.                         'brown'   => 0x10,
  548.                         'magenta' => 0x0E,
  549.                         'fuchsia' => 0x0E,
  550.                         'gray'    => 0x17,
  551.                         'grey'    => 0x17,
  552.                         'green'   => 0x11,
  553.                         'lime'    => 0x0B,
  554.                         'navy'    => 0x12,
  555.                         'orange'  => 0x35,
  556.                         'purple'  => 0x14,
  557.                         'red'     => 0x0A,
  558.                         'silver'  => 0x16,
  559.                         'white'   => 0x09,
  560.                         'yellow'  => 0x0D
  561.                        );
  562.     
  563.         // Return the default color, 0x7FFF, if undef,
  564.         if($name_color == ''{
  565.             return(0x7FFF);
  566.         }
  567.     
  568.         // or the color string converted to an integer,
  569.         if(isset($colors[$name_color])) {
  570.             return($colors[$name_color]);
  571.         }
  572.     
  573.         // or the default color if string is unrecognised,
  574.         if(preg_match("/\D/",$name_color)) {
  575.             return(0x7FFF);
  576.         }
  577.     
  578.         // or an index < 8 mapped into the correct range,
  579.         if($name_color < 8{
  580.             return($name_color + 8);
  581.         }
  582.     
  583.         // or the default color if arg is outside range,
  584.         if($name_color > 63{
  585.             return(0x7FFF);
  586.         }
  587.     
  588.         // or an integer in the valid range
  589.         return($name_color);
  590.     }
  591.     
  592.     /**
  593.     * Set cell alignment.
  594.     *
  595.     * @access public
  596.     * @param string $location alignment for the cell ('left', 'right', etc...).
  597.     */
  598.     function setAlign($location)
  599.     {
  600.         if (preg_match("/\d/",$location)) {
  601.             return;                      // Ignore numbers
  602.         }
  603.     
  604.         $location strtolower($location);
  605.     
  606.         if ($location == 'left'{
  607.             $this->_text_h_align = 1;
  608.         }
  609.         if ($location == 'centre'{
  610.             $this->_text_h_align = 2;
  611.         }
  612.         if ($location == 'center'{
  613.             $this->_text_h_align = 2;
  614.         }
  615.         if ($location == 'right'{
  616.             $this->_text_h_align = 3;
  617.         }
  618.         if ($location == 'fill'{
  619.             $this->_text_h_align = 4;
  620.         }
  621.         if ($location == 'justify'{
  622.             $this->_text_h_align = 5;
  623.         }
  624.         if ($location == 'merge'{
  625.             $this->_text_h_align = 6;
  626.         }
  627.         if ($location == 'equal_space'// For T.K.
  628.             $this->_text_h_align = 7;
  629.         }
  630.         if ($location == 'top'{
  631.             $this->_text_v_align = 0;
  632.         }
  633.         if ($location == 'vcentre'{
  634.             $this->_text_v_align = 1;
  635.         }
  636.         if ($location == 'vcenter'{
  637.             $this->_text_v_align = 1;
  638.         }
  639.         if ($location == 'bottom'{
  640.             $this->_text_v_align = 2;
  641.         }
  642.         if ($location == 'vjustify'{
  643.             $this->_text_v_align = 3;
  644.         }
  645.         if ($location == 'vequal_space'// For T.K.
  646.             $this->_text_v_align = 4;
  647.         }
  648.     }
  649.     
  650.     /**
  651.     * This is an alias for the unintuitive setAlign('merge')
  652.     *
  653.     * @access public
  654.     */
  655.     function setMerge()
  656.     {
  657.         $this->setAlign('merge');
  658.     }
  659.     
  660.     /**
  661.     * Sets the boldness of the text.
  662.     * Bold has a range 100..1000.
  663.     * 0 (400) is normal. 1 (700) is bold.
  664.     *
  665.     * @access public
  666.     * @param integer $weight Weight for the text, 0 maps to 400 (normal text),
  667.                              1 maps to 700 (bold text). Valid range is: 100-1000.
  668.                              It's Optional, default is 1 (bold).
  669.     */
  670.     function setBold($weight = 1)
  671.     {
  672.         if($weight == 1{
  673.             $weight = 0x2BC;  // Bold text
  674.         }
  675.         if($weight == 0{
  676.             $weight = 0x190;  // Normal text
  677.         }
  678.         if($weight <  0x064{
  679.             $weight = 0x190;  // Lower bound
  680.         }
  681.         if($weight >  0x3E8{
  682.             $weight = 0x190;  // Upper bound
  683.         }
  684.         $this->_bold $weight;
  685.     }
  686.     
  687.     
  688.     /************************************
  689.     * FUNCTIONS FOR SETTING CELLS BORDERS
  690.     */
  691.     
  692.     /**
  693.     * Sets the width for the bottom border of the cell
  694.     *
  695.     * @access public
  696.     * @param integer $style style of the cell border. 1 => thin, 2 => thick.
  697.     */
  698.     function setBottom($style)
  699.     {
  700.         $this->_bottom $style;
  701.     }
  702.     
  703.     /**
  704.     * Sets the width for the top border of the cell
  705.     *
  706.     * @access public
  707.     * @param integer $style style of the cell top border. 1 => thin, 2 => thick.
  708.     */
  709.     function setTop($style)
  710.     {
  711.         $this->_top $style;
  712.     }
  713.     
  714.     /**
  715.     * Sets the width for the left border of the cell
  716.     *
  717.     * @access public
  718.     * @param integer $style style of the cell left border. 1 => thin, 2 => thick.
  719.     */
  720.     function setLeft($style)
  721.     {
  722.         $this->_left $style;
  723.     }
  724.     
  725.     /**
  726.     * Sets the width for the right border of the cell
  727.     *
  728.     * @access public
  729.     * @param integer $style style of the cell right border. 1 => thin, 2 => thick.
  730.     */
  731.     function setRight($style)
  732.     {
  733.         $this->_right $style;
  734.     }
  735.     
  736.     
  737.     /**
  738.     * Set cells borders to the same style
  739.     *
  740.     * @access public
  741.     * @param integer $style style to apply for all cell borders. 1 => thin, 2 => thick.
  742.     */
  743.     function setBorder($style)
  744.     {
  745.         $this->setBottom($style);
  746.         $this->setTop($style);
  747.         $this->setLeft($style);
  748.         $this->setRight($style);
  749.     }
  750.     
  751.     
  752.     /*******************************************
  753.     * FUNCTIONS FOR SETTING CELLS BORDERS COLORS
  754.     */
  755.     
  756.     /**
  757.     * Sets all the cell's borders to the same color
  758.     *
  759.     * @access public
  760.     * @param mixed $color The color we are setting. Either a string (like 'blue'),
  761.     *                      or an integer (range is [8...63]).
  762.     */
  763.     function setBorderColor($color)
  764.     {
  765.         $this->setBottomColor($color);
  766.         $this->setTopColor($color);
  767.         $this->setLeftColor($color);
  768.         $this->setRightColor($color);
  769.     }
  770.     
  771.     /**
  772.     * Sets the cell's bottom border color
  773.     *
  774.     * @access public
  775.     * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
  776.     */
  777.     function setBottomColor($color)
  778.     {
  779.         $value $this->_getColor($color);
  780.         $this->_bottom_color $value;
  781.     }
  782.     
  783.     /**
  784.     * Sets the cell's top border color
  785.     *
  786.     * @access public
  787.     * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
  788.     */
  789.     function setTopColor($color)
  790.     {
  791.         $value $this->_getColor($color);
  792.         $this->_top_color $value;
  793.     }
  794.     
  795.     /**
  796.     * Sets the cell's left border color
  797.     *
  798.     * @access public
  799.     * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
  800.     */
  801.     function setLeftColor($color)
  802.     {
  803.         $value $this->_getColor($color);
  804.         $this->_left_color $value;
  805.     }
  806.     
  807.     /**
  808.     * Sets the cell's right border color
  809.     *
  810.     * @access public
  811.     * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
  812.     */
  813.     function setRightColor($color)
  814.     {
  815.         $value $this->_getColor($color);
  816.         $this->_right_color $value;
  817.     }
  818.     
  819.     
  820.     /**
  821.     * Sets the cell's foreground color
  822.     *
  823.     * @access public
  824.     * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
  825.     */
  826.     function setFgColor($color)
  827.     {
  828.         $value $this->_getColor($color);
  829.         $this->_fg_color $value;
  830.         if ($this->_pattern == 0// force color to be seen
  831.             $this->_pattern = 1;
  832.         }
  833.     }
  834.       
  835.     /**
  836.     * Sets the cell's background color
  837.     *
  838.     * @access public
  839.     * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
  840.     */
  841.     function setBgColor($color)
  842.     {
  843.         $value $this->_getColor($color);
  844.         $this->_bg_color $value;
  845.         if ($this->_pattern == 0// force color to be seen
  846.             $this->_pattern = 1;
  847.         }
  848.     }
  849.     
  850.     /**
  851.     * Sets the cell's color
  852.     *
  853.     * @access public
  854.     * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
  855.     */
  856.     function setColor($color)
  857.     {
  858.         $value $this->_getColor($color);
  859.         $this->_color $value;
  860.     }
  861.     
  862.     /**
  863.     * Sets the fill pattern attribute of a cell
  864.     *
  865.     * @access public
  866.     * @param integer $arg Optional. Defaults to 1. Meaningful values are: 0-18,
  867.     *                      0 meaning no background.
  868.     */
  869.     function setPattern($arg = 1)
  870.     {
  871.         $this->_pattern $arg;
  872.     }
  873.     
  874.     /**
  875.     * Sets the underline of the text
  876.     *
  877.     * @access public
  878.     * @param integer $underline The value for underline. Possible values are:
  879.     *                           1 => underline, 2 => double underline.
  880.     */
  881.     function setUnderline($underline)
  882.     {
  883.         $this->_underline $underline;
  884.     }
  885.  
  886.     /**
  887.     * Sets the font style as italic
  888.     *
  889.     * @access public
  890.     */
  891.     function setItalic()
  892.     {
  893.         $this->_italic = 1;
  894.     }
  895.  
  896.     /**
  897.     * Sets the font size
  898.     *
  899.     * @access public
  900.     * @param integer $size The font size (in pixels I think).
  901.     */
  902.     function setSize($size)
  903.     {
  904.         $this->_size $size;
  905.     }
  906.     
  907.     /**
  908.     * Sets text wrapping
  909.     *
  910.     * @access public
  911.     */
  912.     function setTextWrap()
  913.     {
  914.         $this->_text_wrap = 1;
  915.     }
  916.  
  917.     /**
  918.     * Sets the orientation of the text
  919.     *
  920.     * @access public
  921.     * @param integer $angle The rotation angle for the text (clockwise). Possible
  922.                             values are: 0, 90, 270 and -1 for stacking top-to-bottom.
  923.     */
  924.     function setTextRotation($angle)
  925.     {
  926.         switch ($angle)
  927.         {
  928.             case 0:
  929.                 $this->_rotation = 0;
  930.                 break;
  931.             case 90:
  932.                 $this->_rotation = 3;
  933.                 break;
  934.             case 270:
  935.                 $this->_rotation = 2;
  936.                 break;
  937.             case -1:
  938.                 $this->_rotation = 1;
  939.                 break;
  940.             default :
  941.                 return $this->raiseError("Invalid value for angle.".
  942.                                   " Possible values are: 0, 90, 270 and -1 ".
  943.                                   "for stacking top-to-bottom.");
  944.                 $this->_rotation = 0;
  945.                 break;
  946.         }
  947.     }
  948.  
  949.     /**
  950.     * Sets the numeric format.
  951.     * It can be date, time, currency, etc...
  952.     *
  953.     * @access public
  954.     * @param integer $num_format The numeric format.
  955.     */
  956.     function setNumFormat($num_format)
  957.     {
  958.         $this->_num_format $num_format;
  959.     }
  960.  
  961.     /**
  962.     * Sets font as strikeout.
  963.     *
  964.     * @access public
  965.     */
  966.     function setStrikeOut()
  967.     {
  968.         $this->_font_strikeout = 1;
  969.     }
  970.  
  971.     /**
  972.     * Sets outlining for a font.
  973.     *
  974.     * @access public
  975.     */
  976.     function setOutLine()
  977.     {
  978.         $this->_font_outline = 1;
  979.     }
  980.  
  981.     /**
  982.     * Sets font as shadow.
  983.     *
  984.     * @access public
  985.     */
  986.     function setShadow()
  987.     {
  988.         $this->_font_shadow = 1;
  989.     }
  990.  
  991.     /**
  992.     * Sets the script type of the text
  993.     *
  994.     * @access public
  995.     * @param integer $script The value for script type. Possible values are:
  996.     *                         1 => superscript, 2 => subscript.
  997.     */
  998.     function setScript($script)
  999.     {
  1000.         $this->_font_script $script;
  1001.     }
  1002.  
  1003.      /**
  1004.      * Locks a cell.
  1005.      *
  1006.      * @access public
  1007.      */
  1008.      function setLocked()
  1009.      {
  1010.          $this->_locked = 1;
  1011.      }
  1012.  
  1013.     /**
  1014.     * Unlocks a cell. Useful for unprotecting particular cells of a protected sheet.
  1015.     *
  1016.     * @access public
  1017.     */
  1018.     function setUnLocked()
  1019.     {
  1020.         $this->_locked = 0;
  1021.     }
  1022.  
  1023.     /**
  1024.     * Sets the font family name.
  1025.     *
  1026.     * @access public
  1027.     * @param string $fontfamily The font family name. Possible values are:
  1028.     *                            'Times New Roman', 'Arial', 'Courier'.
  1029.     */
  1030.     function setFontFamily($font_family)
  1031.     {
  1032.         $this->_font_name $font_family;
  1033.     }
  1034. }
  1035. ?>

Documentation generated on Mon, 11 Mar 2019 13:51:57 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.