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

Documentation generated on Mon, 25 Aug 2008 13:39:00 +0200 by phpDocumentor 1.4.1