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

Source for file ExcelWriterXML_Style.php

Documentation is available at ExcelWriterXML_Style.php

  1. <?php
  2. /**
  3.  * File contains the class files for ExcelWriterXML_Style
  4.  * @package ExcelWriterXML
  5.  */
  6.  
  7. /**
  8.  * Style class for generating Excel styles
  9.  * @link http://msdn.microsoft.com/en-us/library/aa140066(office.10).aspx
  10.  * @author Robert F Greer
  11.  * @version 1.0
  12.  * @package ExcelWriterXML
  13.  */
  14.     // Private Variables
  15.     /////////////////////
  16.     // Options
  17.     private $id;
  18.     private $name;
  19.     private $useAlignment false;
  20.     private $useFont false;
  21.     private $useBorder false;
  22.     private $useInterior false;
  23.     
  24.     // Alignment
  25.     private $valign;
  26.     private $halign;
  27.     private $rotate;
  28.     private $shrinktofit 0;
  29.     private $verticaltext 0;
  30.     private $wraptext 0;
  31.  
  32.     // Font
  33.     private $fontColor 'Automatic';
  34.     private $fontName;
  35.     private $fontFamily;
  36.     private $fontSize;
  37.     private $bold;
  38.     private $italic;
  39.     private $underline;
  40.     private $strikethrough;
  41.     private $shadow;
  42.     private $outline;
  43.     /////////////////////
  44.     
  45.     // Borders
  46.     private $borderTop array();
  47.     private $borderBottom array();
  48.     private $borderLeft array();
  49.     private $borderRight array();
  50.     private $borderDL array();
  51.     private $borderDR array();
  52.     /////////////////////
  53.     
  54.     // Interior
  55.     private $interiorColor;
  56.     private $interiorPattern;
  57.     private $interiorPatternColor;
  58.     /////////////////////
  59.     
  60.     // NumberFormat
  61.     private $numberFormat;
  62.     /////////////////////
  63.     
  64.     // Other Vars
  65.     private $formatErrors array();
  66.     private $namedColorsIE array (
  67.         'aliceblue' => '#F0F8FF',
  68.         'antiquewhite' => '#FAEBD7',
  69.         'aqua' => '#00FFFF',
  70.         'aquamarine' => '#7FFFD4',
  71.         'azure' => '#F0FFFF',
  72.         'beige' => '#F5F5DC',
  73.         'bisque' => '#FFE4C4',
  74.         'black' => '#000000',
  75.         'blanchedalmond' => '#FFEBCD',
  76.         'blue' => '#0000FF',
  77.         'blueviolet' => '#8A2BE2',
  78.         'brown' => '#A52A2A',
  79.         'burlywood' => '#DEB887',
  80.         'cadetblue' => '#5F9EA0',
  81.         'chartreuse' => '#7FFF00',
  82.         'chocolate' => '#D2691E',
  83.         'coral' => '#FF7F50',
  84.         'cornflowerblue' => '#6495ED',
  85.         'cornsilk' => '#FFF8DC',
  86.         'crimson' => '#DC143C',
  87.         'cyan' => '#00FFFF',
  88.         'darkblue' => '#00008B',
  89.         'darkcyan' => '#008B8B',
  90.         'darkgoldenrod' => '#B8860B',
  91.         'darkgray' => '#A9A9A9',
  92.         'darkgreen' => '#006400',
  93.         'darkkhaki' => '#BDB76B',
  94.         'darkmagenta' => '#8B008B',
  95.         'darkolivegreen' => '#556B2F',
  96.         'darkorange' => '#FF8C00',
  97.         'darkorchid' => '#9932CC',
  98.         'darkred' => '#8B0000',
  99.         'darksalmon' => '#E9967A',
  100.         'darkseagreen' => '#8FBC8F',
  101.         'darkslateblue' => '#483D8B',
  102.         'darkslategray' => '#2F4F4F',
  103.         'darkturquoise' => '#00CED1',
  104.         'darkviolet' => '#9400D3',
  105.         'deeppink' => '#FF1493',
  106.         'deepskyblue' => '#00BFFF',
  107.         'dimgray' => '#696969',
  108.         'dodgerblue' => '#1E90FF',
  109.         'firebrick' => '#B22222',
  110.         'floralwhite' => '#FFFAF0',
  111.         'forestgreen' => '#228B22',
  112.         'fuchsia' => '#FF00FF',
  113.         'gainsboro' => '#DCDCDC',
  114.         'ghostwhite' => '#F8F8FF',
  115.         'gold' => '#FFD700',
  116.         'goldenrod' => '#DAA520',
  117.         'gray' => '#808080',
  118.         'green' => '#008000',
  119.         'greenyellow' => '#ADFF2F',
  120.         'honeydew' => '#F0FFF0',
  121.         'hotpink' => '#FF69B4',
  122.         'indianred' => '#CD5C5C',
  123.         'indigo' => '#4B0082',
  124.         'ivory' => '#FFFFF0',
  125.         'khaki' => '#F0E68C',
  126.         'lavender' => '#E6E6FA',
  127.         'lavenderblush' => '#FFF0F5',
  128.         'lawngreen' => '#7CFC00',
  129.         'lemonchiffon' => '#FFFACD',
  130.         'lightblue' => '#ADD8E6',
  131.         'lightcoral' => '#F08080',
  132.         'lightcyan' => '#E0FFFF',
  133.         'lightgoldenrodyellow' => '#FAFAD2',
  134.         'lightgreen' => '#90EE90',
  135.         'lightgrey' => '#D3D3D3',
  136.         'lightpink' => '#FFB6C1',
  137.         'lightsalmon' => '#FFA07A',
  138.         'lightseagreen' => '#20B2AA',
  139.         'lightskyblue' => '#87CEFA',
  140.         'lightslategray' => '#778899',
  141.         'lightsteelblue' => '#B0C4DE',
  142.         'lightyellow' => '#FFFFE0',
  143.         'lime' => '#00FF00',
  144.         'limegreen' => '#32CD32',
  145.         'linen' => '#FAF0E6',
  146.         'magenta' => '#FF00FF',
  147.         'maroon' => '#800000',
  148.         'mediumaquamarine' => '#66CDAA',
  149.         'mediumblue' => '#0000CD',
  150.         'mediumorchid' => '#BA55D3',
  151.         'mediumpurple' => '#9370DB',
  152.         'mediumseagreen' => '#3CB371',
  153.         'mediumslateblue' => '#7B68EE',
  154.         'mediumspringgreen' => '#00FA9A',
  155.         'mediumturquoise' => '#48D1CC',
  156.         'mediumvioletred' => '#C71585',
  157.         'midnightblue' => '#191970',
  158.         'mintcream' => '#F5FFFA',
  159.         'mistyrose' => '#FFE4E1',
  160.         'moccasin' => '#FFE4B5',
  161.         'navajowhite' => '#FFDEAD',
  162.         'navy' => '#000080',
  163.         'oldlace' => '#FDF5E6',
  164.         'olive' => '#808000',
  165.         'olivedrab' => '#6B8E23',
  166.         'orange' => '#FFA500',
  167.         'orangered' => '#FF4500',
  168.         'orchid' => '#DA70D6',
  169.         'palegoldenrod' => '#EEE8AA',
  170.         'palegreen' => '#98FB98',
  171.         'paleturquoise' => '#AFEEEE',
  172.         'palevioletred' => '#DB7093',
  173.         'papayawhip' => '#FFEFD5',
  174.         'peachpuff' => '#FFDAB9',
  175.         'peru' => '#CD853F',
  176.         'pink' => '#FFC0CB',
  177.         'plum' => '#DDA0DD',
  178.         'powderblue' => '#B0E0E6',
  179.         'purple' => '#800080',
  180.         'red' => '#FF0000',
  181.         'rosybrown' => '#BC8F8F',
  182.         'royalblue' => '#4169E1',
  183.         'saddlebrown' => '#8B4513',
  184.         'salmon' => '#FA8072',
  185.         'sandybrown' => '#F4A460',
  186.         'seagreen' => '#2E8B57',
  187.         'seashell' => '#FFF5EE',
  188.         'sienna' => '#A0522D',
  189.         'silver' => '#C0C0C0',
  190.         'skyblue' => '#87CEEB',
  191.         'slateblue' => '#6A5ACD',
  192.         'slategray' => '#708090',
  193.         'snow' => '#FFFAFA',
  194.         'springgreen' => '#00FF7F',
  195.         'steelblue' => '#4682B4',
  196.         'tan' => '#D2B48C',
  197.         'teal' => '#008080',
  198.         'thistle' => '#D8BFD8',
  199.         'tomato' => '#FF6347',
  200.         'turquoise' => '#40E0D0',
  201.         'violet' => '#EE82EE',
  202.         'wheat' => '#F5DEB3',
  203.         'white' => '#FFFFFF',
  204.         'whitesmoke' => '#F5F5F5',
  205.         'yellow' => '#FFFF00',
  206.         'yellowgreen' => '#9ACD32',
  207.     );
  208.     /////////////////////
  209.     
  210.     // Public Variables
  211.     /////////////////////
  212.     
  213.     // Constructor
  214.     
  215.     /**
  216.      * Constructor for a style
  217.      * @param string $id The named style referenced by Excel.  This is called by
  218.      *  ExcelWriterXML object when adding a style
  219.      */
  220.     function ExcelWriterXML_Style($id){
  221.         $this->id $id;
  222.     }
  223.     /////////////////////
  224.     
  225.     /**
  226.      * Returns the named style for this style
  227.      * @return string $id The id for this style
  228.      */
  229.     public function getID(){
  230.         return $this->id;
  231.     }
  232.     
  233.     /**
  234.      * Retrieves the XML string data for a style.
  235.      * Called by ExcelWriterXML object
  236.      * @return string Returns the formatted XML data <style>...</style>
  237.      */
  238.     public function getStyleXML(){
  239.         $name '';
  240.         $valign '';
  241.         $halign '';
  242.         $rotate '';
  243.         $shrinktofit '';
  244.         $verticaltext '';
  245.         $wraptext '';
  246.         
  247.         $bold '';
  248.         $italic '';
  249.         $strikethrough '';
  250.         $underline '';
  251.         $outline '';
  252.         $shadow '';
  253.         $fontName '';
  254.         $fontFamily '';
  255.         $fontSize '';
  256.         
  257.         $borders '';
  258.         
  259.         $interior '';
  260.         $interiorColor '';
  261.         $interiorPattern '';
  262.         $interiorPatternColor '';
  263.         
  264.         $numberFormat '';
  265.         
  266.         if (empty($this->id)) throw new exception;
  267.         if (!empty($this->name)){$name 'ss:Name="'.$this->name.'"';}
  268.         
  269.         // Alignment
  270.         if ($this->useAlignment){
  271.             if (!empty($this->valign)){$valign 'ss:Vertical="'.$this->valign.'"';}
  272.             if (!empty($this->halign)){$halign 'ss:Horizontal="'.$this->halign.'"';}
  273.             if (!empty($this->rotate)){$rotate 'ss:Rotate="'.$this->rotate.'"';}
  274.             if (!empty($this->shinktofit)){$shrinktofit 'ss:ShrinkToFit="1"';}
  275.             if (!empty($this->verticaltext)){$verticaltext 'ss:VerticalText="1"';}
  276.             if (!empty($this->wraptext)){$wraptext 'ss:WrapText="1"';}
  277.         }
  278.         
  279.         // Font
  280.         if ($this->useFont){
  281.             if (!empty($this->fontColor)){$fontColor 'ss:Color="'.$this->fontColor.'"';}
  282.             if (!empty($this->bold)){$bold 'ss:Bold="1"';}
  283.             if (!empty($this->italic)){$italic 'ss:Italic="1"';}
  284.             if (!empty($this->strikethrough)){$strikethrough 'ss:StrikeThrough="'.$this->strikethrough.'"';}
  285.             if (!empty($this->underline)){$underline 'ss:Underline="'.$this->underline.'"';}
  286.             if (!empty($this->outline)){$outline 'ss:Outline="1"';}
  287.             if (!empty($this->shadow)){$shadow 'ss:Shadow="1"';}
  288.             if (!empty($this->fontName)){$fontName 'ss:FontName="'.$this->fontName.'"';}
  289.             if (!empty($this->fontFamily)){$fontFamily 'x:Family="'.$this->fontFamily.'"';}
  290.             if (!empty($this->fontSize)){$fontSize 'ss:Size="'.$this->fontSize.'"';}
  291.         }
  292.         // Border
  293.         if ($this->useBorder){
  294.             $borders '        <Borders>'."\r";
  295.             $positions array(
  296.                 'Top'            => $this->borderTop,
  297.                 'Bottom'        => $this->borderBottom,
  298.                 'Left'            => $this->borderLeft,
  299.                 'Right'            => $this->borderRight,
  300.                 'DiagonalLeft'    => $this->borderDL,
  301.                 'DiagonalRight'    => $this->borderDR,
  302.  
  303.             );
  304.             foreach($positions as $position => $pData){
  305.                 if (empty($pData)) continue;
  306.                 $bLinestyle = isset($pData['LineStyle'])
  307.                     ? 'ss:LineStyle="'.$pData['LineStyle'].'"'
  308.                     : '';
  309.                 $bColor = isset($pData['Color'])
  310.                     ? 'ss:Color="'.$pData['Color'].'"'
  311.                     : '';
  312.                 $bWeight = isset($pData['Weight'])
  313.                     ? 'ss:Weight="'.$pData['Weight'].'"'
  314.                     : '';
  315.                 $borders .= '<Border ss:Position="'.$position.'" '.$bLinestyle.' '.$bColor.' '.$bWeight.'/>'."\r";
  316.             }
  317.             $borders .= '</Borders>'."\r";
  318.         }
  319.         
  320.         if ($this->useInterior){
  321.             if (!empty($this->interiorColor)){$interiorColor 'ss:Color="'.$this->interiorColor.'"';}
  322.             if (!empty($this->interiorPattern)){$interiorPattern 'ss:Pattern="'.$this->interiorPattern.'"';}
  323.             if (!empty($this->interiorPatternColor)){$interiorPatternColor 'ss:PatternColor="'.$this->interiorPatternColor.'"';}
  324.             $interior '        <Interior '.$interiorColor.' '.$interiorPattern.' '.$interiorPatternColor.'/>'."\r";
  325.         }
  326.         
  327.         if (!empty($this->numberFormat)) {$numberFormat '        <NumberFormat ss:Format="'.$this->numberFormat.'"/>'."\r";}
  328.         else $numberFormat '        <NumberFormat/>'."\r";
  329.         
  330.         $xml '    <Style ss:ID="'.$this->id.'" '.$name.'>'."\r";
  331.         if ($this->useAlignment$xml .= '        <Alignment '.$valign.' '.$halign.' '.$rotate.' '.$shrinktofit.' '.$wraptext.' '.$verticaltext.'/>'."\r";
  332.         if ($this->useBorder$xml .= $borders;
  333.         if ($this->useFont$xml .= '        <Font '.$fontSize.' '.$fontColor.' '.$bold.' '.$italic.' '.$strikethrough.' '.$underline.' '.$shadow.' '.$outline.' '.$fontName.' '.$fontFamily.'/>'."\r";
  334.         if ($this->useInterior$xml .= $interior;
  335.         $xml .= $numberFormat;
  336.         $xml .= '        <Protection/>'."\r";
  337.         $xml .= '    </Style>'."\r";
  338.         return($xml);
  339.     }
  340.     
  341.     /**
  342.      * Checks whether a color is valid for the spreadsheet
  343.      * @param string $color Named color from MS or web color in HEX format (e.g.
  344.      *  #ff00ff
  345.      * @return mixed Either the valid color in HEX format or false if the color
  346.      *  is not valid
  347.      */
  348.     public function checkColor($color){
  349.         $pattern "/[0-9a-f]{6}/";
  350.         if (preg_match($patternstrtolower($color)$matches)) {
  351.             $color '#'.$matches[0];
  352.             return($color);
  353.         }
  354.         else if (isset($this->namedColorsIE[strtolower($color)])){
  355.             $color $this->namedColorsIE[strtolower($color)];
  356.             return($color);
  357.         }
  358.         else{
  359.             $this->addError(__FUNCTION__,'Supplied color was not valid "'.$color.'"');
  360.             return(false);
  361.         }
  362.     }
  363.     
  364.     /**
  365.      * Adds a format error.  When the document is generated if there are any
  366.      * errors they will be listed on a seperate sheet.
  367.      * @param string $namedStyle The style in which the error occurred
  368.      * @param string $function The name of the function that was called
  369.      * @param string $message Details of the error
  370.      */
  371.     private function addError($function$message){
  372.         $tmp array(
  373.             'style'        => $this->id,
  374.             'function'    => $function,
  375.             'message'    => $message,
  376.         );
  377.         $this->formatErrors[$tmp;
  378.     }
  379.  
  380.     /**
  381.      * Returns any errors found in the sheet
  382.      * @return mixed Array of errors if they exist, otherwise false
  383.      */
  384.     public function getErrors(){
  385.         return($this->formatErrors);
  386.     }
  387.  
  388.     
  389.     // Change Options
  390.     
  391.     /**
  392.      * Changes the name of the named style
  393.      * @param string $name The named style referenced by Excel.
  394.      */
  395.     public function name($name){$this->name $name}
  396.     ////////////////////////
  397.     
  398.     // Change Alignment
  399.     /**
  400.      * Changes the vertical alignment setting for the style
  401.      * @param string $valign The value for the vertical alignment.
  402.      *  Acceptable values are "Automatic" "Top" "Bottom" "Center"
  403.      */
  404.     public function alignVertical($valign){
  405.         // Automatic, Top, Bottom, Center
  406.         if ($valign != 'Automatic'
  407.             && $valign != 'Top'
  408.             && $valign != 'Bottom'
  409.             && $valign != 'Center'){
  410.             $this->addError(__FUNCTION__,'vertical alignment was not valid "'.$valign.'"');
  411.             return;
  412.         }
  413.         $this->valign $valign;
  414.         $this->useAlignment true;
  415.     }
  416.     
  417.     /**
  418.      * Changes the horizontal alignment setting for the style
  419.      * @param string $halign The value for the horizontal alignment. Acceptable
  420.      *  values are "Automatic" "Left" "Center" "Right"
  421.      */
  422.     public function alignHorizontal($halign){
  423.         // Automatic, Left, Center, Right
  424.         if ($halign != 'Automatic'
  425.             && $halign != 'Left'
  426.             && $halign != 'Center'
  427.             && $halign != 'Right'){
  428.             $this->addError(__FUNCTION__,'horizontal alignment was not valid "'.$halign.'"');
  429.             $halign 'Automatic';
  430.         }
  431.         $this->halign $halign;
  432.         $this->useAlignment true;
  433.     }
  434.     
  435.     /**
  436.      * Changes the rotation setting for the style
  437.      * @param mixed $rotate The value for the Rotation.  Value must be a
  438.      *  number between -90 and 90
  439.      */
  440.     public function alignRotate($rotate){
  441.         // Degrees to rotate the text
  442.         if (!is_numeric($rotate)){
  443.             $this->addError(__FUNCTION__,'rotation was not numeric "'.$rotate.'"');
  444.             return;
  445.         }
  446.         if (abs($rotate90){
  447.             $rotate $rotate 90;
  448.             $this->addError(__FUNCTION__,'rotation was greater than 90, defaulted to "'.$rotate.'"');
  449.         }
  450.         $this->rotate $rotate;
  451.         $this->useAlignment true;
  452.     }
  453.     
  454.     /**
  455.      * Changes the Shrink To Fit setting for the style
  456.      * ShrinkToFit shrinks the text so that it fits within the cell.
  457.      * This doesn't actually work.
  458.      */
  459.     public function alignShrinktofit(){
  460.         $this->shrinktofit 1;
  461.         $this->useAlignment true;
  462.     }
  463.     
  464.     /**
  465.      * Changes the Vertical Text setting for the style.
  466.      * Text will be displayed vertically.
  467.      */
  468.     public function alignVerticaltext(){
  469.         $this->verticaltext 1;
  470.         $this->useAlignment true;
  471.     }
  472.     
  473.     /**
  474.      * Changes the Wrap Text setting for the style.
  475.      */
  476.     public function alignWraptext(){
  477.         $this->wraptext 1;
  478.         $this->useAlignment true;
  479.     }
  480.     /////////////////////////
  481.     
  482.     // Change Font
  483.     /**
  484.      * Changes the size of the font
  485.      * @param string $fontSize The value for the Size. Value must be greater
  486.      *  than zero
  487.      */
  488.     public function fontSize($fontSize 10){
  489.         if (!is_numeric($fontSize)){
  490.             $fontSize 10;
  491.             $this->addError(__FUNCTION__,'font size was not a number, defaulted to 10 "'.$fontSize.'"');
  492.         }
  493.         if ($fontSize <= 0){
  494.             $fontSize 10;
  495.             $this->addError(__FUNCTION__,'font size was less than zero, defaulted to 10 "'.$fontSize.'"');
  496.         }
  497.         $this->fontSize $fontSize;
  498.         $this->useFont true;
  499.     }
  500.     
  501.     /**
  502.      * Changes the color for the font
  503.      * @param string $fontColor The value for the Color.
  504.      *  This can be a MS named color or a Hex web color.
  505.      */
  506.     public function fontColor($fontColor 'Automatic'){
  507.         $pattern "/[0-9a-f]{6}/";
  508.         $fontColor $this->checkColor($fontColor);
  509.         if ($fontColor === false){
  510.             $this->addError(__FUNCTION__,'font color was not valid "'.$fontColor.'"');
  511.             $fontColor 'Automatic';
  512.         }
  513.         $this->fontColor $fontColor;
  514.         $this->useFont true;
  515.     }
  516.     
  517.     /**
  518.      * Changes the font for the cell
  519.      * @param string $fontName The value for the font name. This should be a
  520.      *  standard windows font available on most systems.
  521.      */
  522.     public function fontName($fontName 'Arial'){
  523.         $this->fontName $fontName;
  524.         $this->useFont true;
  525.     }
  526.     
  527.     /**
  528.      * Changes the family for the font
  529.      * @param string $fontFamily The value for the font family. Not really sure
  530.      *  what this does.
  531.      *  Win32-dependant font family.
  532.      *  Values can be "Automatic" "Decorative"
  533.      *  "Modern" "Roman" "Script" "Swiss"
  534.      */
  535.     public function fontFamily($fontFamily 'Swiss'){
  536.         // Win32-dependent font family.
  537.         // Automatic, Decorative, Modern, Roman, Script, and Swiss
  538.         if ($fontFamily != 'Automatic'
  539.             && $fontFamily != 'Decorative'
  540.             && $fontFamily != 'Modern'
  541.             && $fontFamily != 'Roman'
  542.             && $fontFamily != 'Script'
  543.             && $fontFamily != 'Swiss'){
  544.             $this->addError(__FUNCTION__,'font family was not valid "'.$fontFamily.'"');
  545.             return;
  546.         }
  547.         $this->fontFamily $fontFamily;
  548.         $this->useFont true;
  549.     }
  550.     
  551.     /**
  552.      * Makes the font bold for the named style
  553.      */
  554.     public function fontBold(){
  555.         $this->bold 1;
  556.         $this->useFont true;
  557.     }
  558.     
  559.     /**
  560.      * Makes the font italic for the named style
  561.      */
  562.     public function fontItalic(){
  563.         $this->italic 1;
  564.         $this->useFont true;
  565.     }
  566.     
  567.     /**
  568.      * Makes the font strikethrough for the named style
  569.      */
  570.     public function fontStrikethrough(){
  571.         $this->strikethrough 1;
  572.         $this->useFont true;
  573.     }
  574.     
  575.     /**
  576.      * Makes the font underlined for the named style
  577.      * @param string $uStyle The type of underlining for the style.
  578.      *  Acceptable values are "None" "Single" "Double" "SingleAccounting"
  579.      *  "DoubleAccounting"
  580.      */
  581.     public function fontUnderline($uStyle 'Single'){
  582.         // None, Single, Double, SingleAccounting, and DoubleAccounting
  583.         if ($uStyle != 'None'
  584.             && $uStyle != 'Single'
  585.             && $uStyle != 'Double'
  586.             && $uStyle != 'SingleAccounting'
  587.             && $uStyle != 'DoubleAccounting'){
  588.             $this->addError(__FUNCTION__,'underline type was not valid "'.$uStyle.'"');
  589.             return;
  590.         }
  591.         $this->underline $uStyle;
  592.         $this->useFont true;
  593.     }
  594.     
  595.     /**
  596.      * Makes the font shadowed for the named style
  597.      */
  598.     public function fontShadow(){
  599.         $this->shadow 1;
  600.         $this->useFont true;
  601.     }
  602.  
  603.     /**
  604.      * Makes the font outlines for the named style
  605.      */
  606.     public function fontOutline(){
  607.         $this->outline 1;
  608.         $this->useFont true;
  609.     }
  610.     //////////////////////////
  611.     
  612.     // Change Border
  613.     
  614.     /**
  615.      * Sets the border for the named style.
  616.      * This function can be called multiple times to set different sides of the
  617.      * cell or set all sides the same at once.
  618.      * @param string $position Sets which side of the cell should be modified.
  619.      *  Acceptable values are "All" "Left" "Top" "Right" "Bottom" "DiagonalLeft"
  620.      *  "DiagonalRight"
  621.      * @param integer $weight Thickness of the border.  Default is 1 "Thin"
  622.      * @param string $color Color of the border. Default is "Automatic" but any
  623.      *  6-hexadecimal digit number in "#rrggbb" format or it can be any of the
  624.      *  Microsoft® Internet Explorer named colors
  625.      * @param string $linestyle Type of line to use on the border.
  626.      *  Default is "Continuous".  Acceptable balues are "None" "Continuous"
  627.      *  "Dash" "Dot" "DashDot" "DashDotDot" "SlantDashDot" "Double"
  628.      */
  629.     public function border(
  630.         $position 'All'            // All, Left, Top, Right, Bottom, DiagonalLeft, DiagonalRight
  631.         ,$weight '1'                // 0—Hairline, 1—Thin, 2—Medium, 3—Thick
  632.         ,$color 'Automatic'        // Automatic, 6-hexadecimal digit number in "#rrggbb" format or it can be any of the Microsoft® Internet Explorer named colors
  633.         ,$linestyle 'Continuous'    // None, Continuous, Dash, Dot, DashDot, DashDotDot, SlantDashDot, Double
  634.         ){
  635.         
  636.         if ($position != 'All'
  637.             && $position != 'Left'
  638.             && $position != 'Top'
  639.             && $position != 'Right'
  640.             && $position != 'Bottom'
  641.             && $position != 'DiagonalLeft'
  642.             && $position != 'DiagonalRight'){
  643.             $this->addError(__FUNCTION__,'border position was not valid, defaulted to All "'.$position.'"');
  644.             $position 'All';
  645.         }
  646.         
  647.         if (is_numeric($weight)){
  648.             if (abs($weight3){
  649.                 $this->addError(__FUNCTION__,'line weight greater than 3, defaulted to 3 "'.$weight.'"');
  650.                 $weight 3;
  651.             }
  652.         }
  653.         else{
  654.             $this->addError(__FUNCTION__,'line weight not numeric, defaulted to 3 "'.$weight.'"');
  655.             $weight 1;
  656.         }
  657.  
  658.         $color $this->checkColor($color);
  659.         if ($color === false){
  660.             $this->addError(__FUNCTION__,'border color was not valid, defaulted to Automatic "'.$weight.'"');
  661.             $color 'Automatic';
  662.         }
  663.  
  664.         if ($linestyle != 'None'
  665.             && $linestyle != 'Continuous'
  666.             && $linestyle != 'Dash'
  667.             && $linestyle != 'Dot'
  668.             && $linestyle != 'DashDot'
  669.             && $linestyle != 'DashDotDot'
  670.             && $linestyle != 'SlantDashDot'
  671.             && $linestyle != 'Double'){
  672.             $linestyle 'Continuous';
  673.             $this->addError(__FUNCTION__,'line style was not valid, defaulted to Continuous "'.$linestyle.'"');
  674.         }
  675.  
  676.         
  677.         $tmp array(
  678.             'LineStyle'    => $linestyle,
  679.             'Color'        => $color,
  680.             'Weight'    => $weight,
  681.         );
  682.         if ($position == 'Top'        || $position == 'All'$this->borderTop $tmp;
  683.         if ($position == 'Bottom'    || $position == 'All'$this->borderBottom $tmp;
  684.         if ($position == 'Left'        || $position == 'All'$this->borderLeft $tmp;
  685.         if ($position == 'Right'    || $position == 'All'$this->borderRight $tmp;
  686.         if ($position == 'DiagonalLeft'    )                    $this->borderDL $tmp;
  687.         if ($position == 'DiagonalRight'    )                $this->borderDR $tmp;
  688.         
  689.         $this->useBorder true;
  690.     }
  691.     //////////////////////////
  692.     
  693.     // Change Interior
  694.     /**
  695.      * Sets the background style of a style
  696.      * @param string $color Named color from MS or web color in HEX format (e.g.
  697.      *  #ff00ff
  698.      * @param string $pattern Defaults to a None if not supplied.
  699.      * @param string $patternColor Defaults to a Automatic if not supplied.
  700.      */
  701.     public function bgColor($color 'Yellow',$pattern 'Solid'$patternColor null){
  702.         // 6-hexadecimal digit number in "#rrggbb" format
  703.         // Or it can be any of the Internet Explorer named colors
  704.         $color $this->checkColor($color);
  705.         if ($color === false){
  706.             $color 'Yellow';
  707.             $this->addError(__FUNCTION__,'cell color not valid, defaulted to Yellow "'.$color.'"');
  708.         }
  709.         $this->interiorColor $color;
  710.         if ($pattern != 'None'){
  711.             $this->bgPattern($pattern$patternColor);
  712.         }
  713.         $this->useInterior true;
  714.     }
  715.  
  716.     /**
  717.      * Sets the background pattern of a style.
  718.      * @see bgColor()
  719.      * @param string $color Named color from MS or web color in HEX format (e.g.
  720.      *  #ff00ff
  721.      * @param string $pattern Defaults to a solid if not supplied.
  722.      */
  723.     public function bgPattern($pattern 'None'$color null){
  724.         // None, Solid, Gray75, Gray50, Gray25, Gray125, Gray0625,
  725.         // HorzStripe, VertStripe, ReverseDiagStripe, DiagStripe,
  726.         // DiagCross, ThickDiagCross, ThinHorzStripe, ThinVertStripe,
  727.         // ThinReverseDiagStripe, ThinDiagStripe, ThinHorzCross, and ThinDiagCross
  728.         if ($pattern != 'None'
  729.             && $pattern != 'Solid'
  730.             && $pattern != 'Gray75'
  731.             && $pattern != 'Gray50'
  732.             && $pattern != 'Gray25'
  733.             && $pattern != 'Gray125'
  734.             && $pattern != 'Gray0625'
  735.             && $pattern != 'HorzStripe'
  736.             && $pattern != 'VertStripe'
  737.             && $pattern != 'ReverseDiagStripe'
  738.             && $pattern != 'DiagStripe'
  739.             && $pattern != 'DiagCross'
  740.             && $pattern != 'ThickDiagCross'
  741.             && $pattern != 'ThinHorzStripe'
  742.             && $pattern != 'ThinVertStripe'
  743.             && $pattern != 'ThinReverseDiagStripe'
  744.             && $pattern != 'ThinDiagStripe'
  745.             && $pattern != 'ThinHorzCross'
  746.             && $pattern != 'ThinDiagCross'){
  747.             $pattern 'None';
  748.             $this->addError(__FUNCTION__,'cell pattern was not valid, defaulted to Solid "'.$pattern.'"');
  749.         }
  750.  
  751.         $this->interiorPattern $pattern;
  752.         if ($color != null$this->bgPatternColor($color);
  753.         $this->useInterior true;
  754.     }
  755.  
  756.     /**
  757.      * Specifies the secondary fill color of the cell when Pattern does not equal Solid.
  758.      * @see function bgPattern()
  759.      * @param string $color Named color from MS or web color in HEX format (e.g.
  760.      *  #ff00ff
  761.      * @param string $pattern Defaults to a solid if not supplied.
  762.      */
  763.     public function bgPatternColor($color 'Yellow'){
  764.         // 6-hexadecimal digit number in "#rrggbb" format
  765.         // Or it can be any of the Internet Explorer named colors
  766.         if ($color != 'Automatic'){
  767.             $color $this->checkColor($color);
  768.             if ($color === false){
  769.                 $color 'Automatic';
  770.                 $this->addError(__FUNCTION__,'cell pattern color was not valid, defaulted to Automatic "'.$color.'"');
  771.             }
  772.         }
  773.         $this->interiorPatternColor $color;
  774.         $this->useInterior true;
  775.     }
  776.  
  777.     //////////////////////////
  778.     
  779.     // Number Formats
  780.  
  781.     /**
  782.      * Sets the number format of a style
  783.      * @param string $formatString Format string to be used by Excel for
  784.      *  displaying the number.
  785.      */
  786.     public function numberFormat($formatString){$this->numberFormat = $formatString;}
  787.  
  788.     /**
  789.      * Sets a default date format for a style
  790.      */
  791.     public function numberFormatDate(){$this->numberFormat('mm/dd/yy');}
  792.  
  793.     /**
  794.      * Sets a default time format for a style
  795.      */
  796.     public function numberFormatTime(){$this->numberFormat('hh:mm:ss');}
  797.  
  798.     /**
  799.      * Sets a default date and time format for a style
  800.      */
  801.     public function numberFormatDatetime(){$this->numberFormat('mm/dd/yy\ hh:mm:ss');}
  802.     //////////////////////////
  803. }
  804. ?>

Documentation generated on Wed, 16 Feb 2011 20:04:38 -0600 by phpDocumentor 1.4.3