Source for file Xf.php
Documentation is available at Xf.php
* Module written/ported by Xavier Noguer <xnoguer@rezebra.com>
* The majority of this is _NOT_ my code. I simply ported it from the
* PERL Spreadsheet::WriteExcel module.
* The author of the Spreadsheet::WriteExcel module is John McNamara
* I _DO_ maintain this code, and John McNamara has nothing to do with the
* porting of this code to PHP. Any questions directly related to this
* class library should be directed to me.
* PHPExcel_Writer_Excel5_Writer: A library for generating Excel Spreadsheets
* Copyright (c) 2002-2003 Xavier Noguer xnoguer@rezebra.com
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/** PHPExcel_Style_Alignment */
require_once 'PHPExcel/Style/Alignment.php';
/** PHPExcel_Style_Border */
require_once 'PHPExcel/Style/Border.php';
/** PHPExcel_Style_Fill */
require_once 'PHPExcel/Style/Fill.php';
/** PHPExcel_Style_Protection */
require_once 'PHPExcel/Style/Protection.php';
* Class for generating Excel XF records (formats)
* @author Xavier Noguer <xnoguer@rezebra.com>
* @package PHPExcel_Writer_Excel5
* Style XF or a cell XF ?
* Index to the FONT record. Index 4 does not exist
* An index (2 bytes) to a FORMAT record (number format).
* 1 bit, apparently not used.
* The cell's foreground color.
* The cell's background color.
* Color of the bottom border of the cell.
* Color of the top border of the cell.
* Color of the left border of the cell.
* Color of the right border of the cell.
* @param integer $index the XF index for the format.
$this->_diag_color = 0x40;
* Generate an Excel BIFF XF record (style or cell).
* @param string $style The type of the XF record ('style' or 'cell').
* @return string The XF record
// Set the type of the XF record and some of the attributes.
$style = $this->_mapLocked($this->_style->getProtection()->getLocked());
$style |= $this->_mapHidden($this->_style->getProtection()->getHidden()) << 1;
// Flags to indicate if attributes have been set.
$atr_alc = ((int) $this->_style->getAlignment()->getWrapText())? 1: 0;
$atr_bdr = ($this->_mapBorderStyle($this->_style->getBorders()->getBottom()->getBorderStyle()) ||
$this->_mapBorderStyle($this->_style->getBorders()->getTop()->getBorderStyle()) ||
$this->_mapBorderStyle($this->_style->getBorders()->getLeft()->getBorderStyle()) ||
$this->_mapBorderStyle($this->_style->getBorders()->getRight()->getBorderStyle()))? 1: 0;
$this->_mapFillType($this->_style->getFill()->getFillType()))? 1: 0;
$atr_prot = $this->_mapLocked($this->_style->getProtection()->getLocked())
| $this->_mapHidden($this->_style->getProtection()->getHidden());
// Zero the default border colour if the border has not been set.
if ($this->_mapBorderStyle($this->_style->getBorders()->getBottom()->getBorderStyle()) == 0) {
if ($this->_mapBorderStyle($this->_style->getBorders()->getTop()->getBorderStyle()) == 0) {
if ($this->_mapBorderStyle($this->_style->getBorders()->getRight()->getBorderStyle()) == 0) {
if ($this->_mapBorderStyle($this->_style->getBorders()->getLeft()->getBorderStyle()) == 0) {
$record = 0x00E0; // Record identifier
$length = 0x0010; // Number of bytes to follow
$ifnt = $this->_fontIndex; // Index to FONT record
$align = $this->_mapHAlign($this->_style->getAlignment()->getHorizontal()); // Alignment
$align |= (int) $this->_style->getAlignment()->getWrapText() << 3;
$align |= $this->_mapVAlign($this->_style->getAlignment()->getVertical()) << 4;
$align |= 0 << 8; // rotation
$align |= $atr_num << 10;
$align |= $atr_fnt << 11;
$align |= $atr_alc << 12;
$align |= $atr_bdr << 13;
$align |= $atr_pat << 14;
$align |= $atr_prot << 15;
$icv = $this->_fg_color; // fg and bg pattern colors
$fill = $this->_mapFillType($this->_style->getFill()->getFillType()); // Fill and border line style
$fill |= $this->_mapBorderStyle($this->_style->getBorders()->getBottom()->getBorderStyle()) << 6;
$border1 = $this->_mapBorderStyle($this->_style->getBorders()->getTop()->getBorderStyle()); // Border line style and color
$border1 |= $this->_mapBorderStyle($this->_style->getBorders()->getLeft()->getBorderStyle()) << 3;
$border1 |= $this->_mapBorderStyle($this->_style->getBorders()->getRight()->getBorderStyle()) << 6;
$header = pack("vv", $record, $length);
$data = pack("vvvvvvvv", $ifnt, $ifmt, $style, $align,
$align = $this->_mapHAlign($this->_style->getAlignment()->getHorizontal()); // Alignment
$align |= (int) $this->_style->getAlignment()->getWrapText() << 3;
$align |= $this->_mapVAlign($this->_style->getAlignment()->getVertical()) << 4;
$used_attrib = $atr_num << 2;
$used_attrib |= $atr_fnt << 3;
$used_attrib |= $atr_alc << 4;
$used_attrib |= $atr_bdr << 5;
$used_attrib |= $atr_pat << 6;
$used_attrib |= $atr_prot << 7;
$icv = $this->_fg_color; // fg and bg pattern colors
$border1 = $this->_mapBorderStyle($this->_style->getBorders()->getLeft()->getBorderStyle()); // Border line style and color
$border1 |= $this->_mapBorderStyle($this->_style->getBorders()->getRight()->getBorderStyle()) << 4;
$border1 |= $this->_mapBorderStyle($this->_style->getBorders()->getTop()->getBorderStyle()) << 8;
$border1 |= $this->_mapBorderStyle($this->_style->getBorders()->getBottom()->getBorderStyle()) << 12;
$diag_tl_to_rb = 0; // FIXME: add method
$diag_tr_to_lb = 0; // FIXME: add method
$border1 |= $diag_tl_to_rb << 30;
$border1 |= $diag_tr_to_lb << 31;
$border2 |= $this->_diag_color << 14;
$border2 |= $this->_diag << 21;
$border2 |= $this->_mapFillType($this->_style->getFill()->getFillType()) << 26;
$header = pack("vv", $record, $length);
//BIFF8 options: identation, shrinkToFit and text direction
$biff8_options = $this->_style->getAlignment()->getIndent();
$biff8_options |= (int) $this->_style->getAlignment()->getShrinkToFit() << 4;
$data = pack("vvvC", $ifnt, $ifmt, $style, $align);
$data .= pack("VVv", $border1, $border2, $icv);
* @param int $BIFFVersion
* Sets the cell's bottom border color
* @param int $colorIndex Color index
* Sets the cell's top border color
* @param int $colorIndex Color index
* Sets the cell's left border color
* @param int $colorIndex Color index
* Sets the cell's right border color
* @param int $colorIndex Color index
* Sets the cell's foreground color
* @param int $colorIndex Color index
* Sets the cell's background color
* @param int $colorIndex Color index
* Sets the index to the number format record
* It can be date, time, currency, etc...
* @param integer $numberFormatIndex Index to format record
* @param int $value Font index, note that value 4 does not exist
* Map to BIFF2-BIFF8 codes for horizontal alignment
* Map to BIFF2-BIFF8 codes for vertical alignment
* Map to BIFF8 codes for text rotation angle
* @param int $textRotation
if ($textRotation >= 0) {
if ($textRotation == - 165) {
return 90 - $textRotation;
|