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

Documentation generated on Mon, 05 Jan 2009 20:37:15 +0100 by phpDocumentor 1.4.1