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

Documentation generated on Wed, 09 Feb 2011 09:01:11 +0700 by phpDocumentor 1.4.2