ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
PHPExcel_Style Class Reference
+ Inheritance diagram for PHPExcel_Style:
+ Collaboration diagram for PHPExcel_Style:

Public Member Functions

 __construct ($isSupervisor=false)
 Create a new PHPExcel_Style.
 bindParent ($parent)
 Bind parent.
 getIsSupervisor ()
 Is this a supervisor or a real style component?
 getSharedComponent ()
 Get the shared style component for the currently active cell in currently active sheet.
 getActiveSheet ()
 Get the currently active sheet.
 getXSelectedCells ()
 Get the currently active cell coordinate in currently active sheet.
 getXActiveCell ()
 Get the currently active cell coordinate in currently active sheet.
 getParent ()
 Get parent.
 applyFromArray ($pStyles=null, $pAdvanced=true)
 Apply styles from array.
 getFill ()
 Get Fill.
 getFont ()
 Get Font.
 setFont (PHPExcel_Style_Font $font)
 Set font.
 getBorders ()
 Get Borders.
 getAlignment ()
 Get Alignment.
 getNumberFormat ()
 Get Number Format.
 getConditionalStyles ()
 Get Conditional Styles.
 setConditionalStyles ($pValue=null)
 Set Conditional Styles.
 getProtection ()
 Get Protection.
 getHashCode ()
 Get hash code.
 getHashIndex ()
 Get hash index.
 setHashIndex ($value)
 Set hash index.
 getIndex ()
 Get own index in style collection.
 setIndex ($pValue)
 Set own index in style collection.
 __clone ()
 Implement PHP __clone to create a deep clone, not just a shallow copy.

Private Attributes

 $_font
 $_fill
 $_borders
 $_alignment
 $_numberFormat
 $_conditionalStyles
 $_protection
 $_isSupervisor
 $_parent
 $_index
 $_hashIndex

Detailed Description

Definition at line 71 of file Style.php.

Constructor & Destructor Documentation

PHPExcel_Style::__construct (   $isSupervisor = false)

Create a new PHPExcel_Style.

Parameters
boolean$isSupervisor

Definition at line 148 of file Style.php.

{
// Supervisor?
$this->_isSupervisor = $isSupervisor;
// Initialise values
$this->_conditionalStyles = array();
$this->_font = new PHPExcel_Style_Font($isSupervisor);
$this->_fill = new PHPExcel_Style_Fill($isSupervisor);
$this->_borders = new PHPExcel_Style_Borders($isSupervisor);
$this->_alignment = new PHPExcel_Style_Alignment($isSupervisor);
$this->_numberFormat = new PHPExcel_Style_NumberFormat($isSupervisor);
$this->_protection = new PHPExcel_Style_Protection($isSupervisor);
// bind parent if we are a supervisor
if ($isSupervisor) {
$this->_font->bindParent($this);
$this->_fill->bindParent($this);
$this->_borders->bindParent($this);
$this->_alignment->bindParent($this);
$this->_numberFormat->bindParent($this);
$this->_protection->bindParent($this);
}
}

Member Function Documentation

PHPExcel_Style::__clone ( )

Implement PHP __clone to create a deep clone, not just a shallow copy.

Definition at line 692 of file Style.php.

References $key.

{
$vars = get_object_vars($this);
foreach ($vars as $key => $value) {
if (is_object($value)) {
$this->$key = clone $value;
} else {
$this->$key = $value;
}
}
}
PHPExcel_Style::applyFromArray (   $pStyles = null,
  $pAdvanced = true 
)

Apply styles from array.

$objPHPExcel->getActiveSheet()->getStyle('B2')->applyFromArray( array( 'font' => array( 'name' => 'Arial', 'bold' => true, 'italic' => false, 'underline' => PHPExcel_Style_Font::UNDERLINE_DOUBLE, 'strike' => false, 'color' => array( 'rgb' => '808080' ) ), 'borders' => array( 'bottom' => array( 'style' => PHPExcel_Style_Border::BORDER_DASHDOT, 'color' => array( 'rgb' => '808080' ) ), 'top' => array( 'style' => PHPExcel_Style_Border::BORDER_DASHDOT, 'color' => array( 'rgb' => '808080' ) ) ) ) );

Parameters
array$pStylesArray containing style information
boolean$pAdvancedAdvanced mode for setting borders.
Exceptions
Exception
Returns
PHPExcel_Style

Definition at line 298 of file Style.php.

References $row, $x, $y, PHPExcel_Cell\columnIndexFromString(), PHPExcel_Cell\coordinateFromString(), getActiveSheet(), getAlignment(), getBorders(), getFill(), getFont(), getNumberFormat(), getProtection(), getXSelectedCells(), and PHPExcel_Cell\stringFromColumnIndex().

{
if (is_array($pStyles)) {
if ($this->_isSupervisor) {
$pRange = $this->getXSelectedCells();
if (is_array($pStyles)) {
// Uppercase coordinate
$pRange = strtoupper($pRange);
// Is it a cell range or a single cell?
$rangeA = '';
$rangeB = '';
if (strpos($pRange, ':') === false) {
$rangeA = $pRange;
$rangeB = $pRange;
} else {
list($rangeA, $rangeB) = explode(':', $pRange);
}
// Calculate range outer borders
$rangeStart = PHPExcel_Cell::coordinateFromString($rangeA);
// Translate column into index
$rangeStart[0] = PHPExcel_Cell::columnIndexFromString($rangeStart[0]) - 1;
$rangeEnd[0] = PHPExcel_Cell::columnIndexFromString($rangeEnd[0]) - 1;
// Make sure we can loop upwards on rows and columns
if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) {
$tmp = $rangeStart;
$rangeStart = $rangeEnd;
$rangeEnd = $tmp;
}
// Advanced mode
if ($pAdvanced && isset($pStyles['borders'])) {
// 'allborders' is a shorthand property for 'outline' and 'inside' and
// it applies to components that have not been set explicitly
if (isset($pStyles['borders']['allborders'])) {
foreach (array('outline', 'inside') as $component) {
if (!isset($pStyles['borders'][$component])) {
$pStyles['borders'][$component] = $pStyles['borders']['allborders'];
}
}
unset($pStyles['borders']['allborders']); // not needed any more
}
// 'outline' is a shorthand property for 'top', 'right', 'bottom', 'left'
// it applies to components that have not been set explicitly
if (isset($pStyles['borders']['outline'])) {
foreach (array('top', 'right', 'bottom', 'left') as $component) {
if (!isset($pStyles['borders'][$component])) {
$pStyles['borders'][$component] = $pStyles['borders']['outline'];
}
}
unset($pStyles['borders']['outline']); // not needed any more
}
// 'inside' is a shorthand property for 'vertical' and 'horizontal'
// it applies to components that have not been set explicitly
if (isset($pStyles['borders']['inside'])) {
foreach (array('vertical', 'horizontal') as $component) {
if (!isset($pStyles['borders'][$component])) {
$pStyles['borders'][$component] = $pStyles['borders']['inside'];
}
}
unset($pStyles['borders']['inside']); // not needed any more
}
// width and height characteristics of selection, 1, 2, or 3 (for 3 or more)
$xMax = min($rangeEnd[0] - $rangeStart[0] + 1, 3);
$yMax = min($rangeEnd[1] - $rangeStart[1] + 1, 3);
// loop through up to 3 x 3 = 9 regions
for ($x = 1; $x <= $xMax; ++$x) {
// start column index for region
$colStart = ($x == 3) ?
: PHPExcel_Cell::stringFromColumnIndex($rangeStart[0] + $x - 1);
// end column index for region
$colEnd = ($x == 1) ?
: PHPExcel_Cell::stringFromColumnIndex($rangeEnd[0] - $xMax + $x);
for ($y = 1; $y <= $yMax; ++$y) {
// which edges are touching the region
$edges = array();
// are we at left edge
if ($x == 1) {
$edges[] = 'left';
}
// are we at right edge
if ($x == $xMax) {
$edges[] = 'right';
}
// are we at top edge?
if ($y == 1) {
$edges[] = 'top';
}
// are we at bottom edge?
if ($y == $yMax) {
$edges[] = 'bottom';
}
// start row index for region
$rowStart = ($y == 3) ?
$rangeEnd[1] : $rangeStart[1] + $y - 1;
// end row index for region
$rowEnd = ($y == 1) ?
$rangeStart[1] : $rangeEnd[1] - $yMax + $y;
// build range for region
$range = $colStart . $rowStart . ':' . $colEnd . $rowEnd;
// retrieve relevant style array for region
$regionStyles = $pStyles;
unset($regionStyles['borders']['inside']);
// what are the inner edges of the region when looking at the selection
$innerEdges = array_diff( array('top', 'right', 'bottom', 'left'), $edges );
// inner edges that are not touching the region should take the 'inside' border properties if they have been set
foreach ($innerEdges as $innerEdge) {
switch ($innerEdge) {
case 'top':
case 'bottom':
// should pick up 'horizontal' border property if set
if (isset($pStyles['borders']['horizontal'])) {
$regionStyles['borders'][$innerEdge] = $pStyles['borders']['horizontal'];
} else {
unset($regionStyles['borders'][$innerEdge]);
}
break;
case 'left':
case 'right':
// should pick up 'vertical' border property if set
if (isset($pStyles['borders']['vertical'])) {
$regionStyles['borders'][$innerEdge] = $pStyles['borders']['vertical'];
} else {
unset($regionStyles['borders'][$innerEdge]);
}
break;
}
}
// apply region style to region by calling applyFromArray() in simple mode
$this->getActiveSheet()->getStyle($range)->applyFromArray($regionStyles, false);
}
}
return;
}
// Simple mode
// First loop through cells to find out which styles are affected by this operation
$oldXfIndexes = array();
for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) {
$oldXfIndexes[$this->getActiveSheet()->getCellByColumnAndRow($col, $row)->getXfIndex()] = true;
}
}
// clone each of the affected styles, apply the style arrray, and add the new styles to the workbook
$workbook = $this->getActiveSheet()->getParent();
foreach ($oldXfIndexes as $oldXfIndex => $dummy) {
$style = $workbook->getCellXfByIndex($oldXfIndex);
$newStyle = clone $style;
$newStyle->applyFromArray($pStyles);
if ($existingStyle = $workbook->getCellXfByHashCode($newStyle->getHashCode())) {
// there is already such cell Xf in our collection
$newXfIndexes[$oldXfIndex] = $existingStyle->getIndex();
} else {
// we don't have such a cell Xf, need to add
$workbook->addCellXf($newStyle);
$newXfIndexes[$oldXfIndex] = $newStyle->getIndex();
}
}
// Loop through cells again and update the XF index
for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) {
$cell = $this->getActiveSheet()->getCellByColumnAndRow($col, $row);
$oldXfIndex = $cell->getXfIndex();
$cell->setXfIndex($newXfIndexes[$oldXfIndex]);
}
}
} else {
throw new Exception("Invalid style array passed.");
}
} else {
if (array_key_exists('fill', $pStyles)) {
$this->getFill()->applyFromArray($pStyles['fill']);
}
if (array_key_exists('font', $pStyles)) {
$this->getFont()->applyFromArray($pStyles['font']);
}
if (array_key_exists('borders', $pStyles)) {
$this->getBorders()->applyFromArray($pStyles['borders']);
}
if (array_key_exists('alignment', $pStyles)) {
$this->getAlignment()->applyFromArray($pStyles['alignment']);
}
if (array_key_exists('numberformat', $pStyles)) {
$this->getNumberFormat()->applyFromArray($pStyles['numberformat']);
}
if (array_key_exists('protection', $pStyles)) {
$this->getProtection()->applyFromArray($pStyles['protection']);
}
}
} else {
throw new Exception("Invalid style array passed.");
}
return $this;
}

+ Here is the call graph for this function:

PHPExcel_Style::bindParent (   $parent)

Bind parent.

Only used for supervisor

Parameters
PHPExcel$parent
Returns
PHPExcel_Style

Definition at line 179 of file Style.php.

{
$this->_parent = $parent;
return $this;
}
PHPExcel_Style::getActiveSheet ( )

Get the currently active sheet.

Only used for supervisor

Returns
PHPExcel_Worksheet

Definition at line 222 of file Style.php.

Referenced by applyFromArray(), getConditionalStyles(), getSharedComponent(), and setConditionalStyles().

{
return $this->_parent->getActiveSheet();
}

+ Here is the caller graph for this function:

PHPExcel_Style::getAlignment ( )

Get Alignment.

Returns
PHPExcel_Style_Alignment

Definition at line 569 of file Style.php.

References $_alignment.

Referenced by PHPExcel_Writer_HTML\_createCSSStyle(), applyFromArray(), and getHashCode().

{
}

+ Here is the caller graph for this function:

PHPExcel_Style::getBorders ( )

Get Borders.

Returns
PHPExcel_Style_Borders

Definition at line 560 of file Style.php.

References $_borders.

Referenced by PHPExcel_Writer_HTML\_createCSSStyle(), applyFromArray(), and getHashCode().

{
}

+ Here is the caller graph for this function:

PHPExcel_Style::getConditionalStyles ( )

Get Conditional Styles.

Only used on supervisor.

Returns
PHPExcel_Style_Conditional[]

Definition at line 587 of file Style.php.

References getActiveSheet(), and getXActiveCell().

{
return $this->getActiveSheet()->getConditionalStyles($this->getXActiveCell());
}

+ Here is the call graph for this function:

PHPExcel_Style::getFill ( )

Get Fill.

Returns
PHPExcel_Style_Fill

Definition at line 530 of file Style.php.

References $_fill.

Referenced by PHPExcel_Writer_HTML\_createCSSStyle(), applyFromArray(), and getHashCode().

{
return $this->_fill;
}

+ Here is the caller graph for this function:

PHPExcel_Style::getFont ( )

Get Font.

Returns
PHPExcel_Style_Font

Definition at line 539 of file Style.php.

References $_font.

Referenced by PHPExcel_Writer_HTML\_createCSSStyle(), applyFromArray(), and getHashCode().

{
return $this->_font;
}

+ Here is the caller graph for this function:

PHPExcel_Style::getHashCode ( )

Get hash code.

Returns
string Hash code

Implements PHPExcel_IComparable.

Definition at line 620 of file Style.php.

References getAlignment(), getBorders(), getFill(), getFont(), getNumberFormat(), and getProtection().

{
$hashConditionals = '';
foreach ($this->_conditionalStyles as $conditional) {
$hashConditionals .= $conditional->getHashCode();
}
return md5(
$this->getFill()->getHashCode()
. $this->getFont()->getHashCode()
. $this->getBorders()->getHashCode()
. $this->getAlignment()->getHashCode()
. $hashConditionals
. $this->getProtection()->getHashCode()
. __CLASS__
);
}

+ Here is the call graph for this function:

PHPExcel_Style::getHashIndex ( )

Get hash index.

Note that this index may vary during script execution! Only reliable moment is while doing a write of a workbook and when changes are not allowed.

Returns
string Hash index

Implements PHPExcel_IComparable.

Definition at line 653 of file Style.php.

References $_hashIndex.

{
}
PHPExcel_Style::getIndex ( )

Get own index in style collection.

Returns
int

Definition at line 674 of file Style.php.

References $_index.

{
return $this->_index;
}
PHPExcel_Style::getIsSupervisor ( )

Is this a supervisor or a real style component?

Returns
boolean

Definition at line 190 of file Style.php.

References $_isSupervisor.

{
}
PHPExcel_Style::getNumberFormat ( )

Get Number Format.

Returns
PHPExcel_Style_NumberFormat

Definition at line 578 of file Style.php.

References $_numberFormat.

Referenced by applyFromArray(), and getHashCode().

{
}

+ Here is the caller graph for this function:

PHPExcel_Style::getParent ( )

Get parent.

Only used for style supervisor

Returns
PHPExcel

Definition at line 254 of file Style.php.

References $_parent.

{
}
PHPExcel_Style::getProtection ( )

Get Protection.

Returns
PHPExcel_Style_Protection

Definition at line 611 of file Style.php.

References $_protection.

Referenced by applyFromArray(), and getHashCode().

{
}

+ Here is the caller graph for this function:

PHPExcel_Style::getSharedComponent ( )

Get the shared style component for the currently active cell in currently active sheet.

Only used for style supervisor

Returns
PHPExcel_Style

Definition at line 201 of file Style.php.

References getActiveSheet(), and getXActiveCell().

{
$activeSheet = $this->getActiveSheet();
$selectedCell = $this->getXActiveCell(); // e.g. 'A1'
if ($activeSheet->cellExists($selectedCell)) {
$cell = $activeSheet->getCell($selectedCell);
$xfIndex = $cell->getXfIndex();
} else {
$xfIndex = 0;
}
$activeStyle = $this->_parent->getCellXfByIndex($xfIndex);
return $activeStyle;
}

+ Here is the call graph for this function:

PHPExcel_Style::getXActiveCell ( )

Get the currently active cell coordinate in currently active sheet.

Only used for supervisor

Returns
string E.g. 'A1'

Definition at line 244 of file Style.php.

Referenced by getConditionalStyles(), and getSharedComponent().

{
return $this->_parent->getActiveSheet()->getXActiveCell();
}

+ Here is the caller graph for this function:

PHPExcel_Style::getXSelectedCells ( )

Get the currently active cell coordinate in currently active sheet.

Only used for supervisor

Returns
string E.g. 'A1'

Definition at line 233 of file Style.php.

Referenced by applyFromArray(), and setConditionalStyles().

{
return $this->_parent->getActiveSheet()->getXSelectedCells();
}

+ Here is the caller graph for this function:

PHPExcel_Style::setConditionalStyles (   $pValue = null)

Set Conditional Styles.

Only used on supervisor.

Parameters
PHPExcel_Style_Conditional[]$pValue Array of condtional styles
Returns
PHPExcel_Style

Definition at line 597 of file Style.php.

References PHPExcel_Cell\extractAllCellReferencesInRange(), getActiveSheet(), and getXSelectedCells().

{
if (is_array($pValue)) {
foreach (PHPExcel_Cell::extractAllCellReferencesInRange($this->getXSelectedCells()) as $cellReference) {
$this->getActiveSheet()->setConditionalStyles($cellReference, $pValue);
}
}
return $this;
}

+ Here is the call graph for this function:

PHPExcel_Style::setFont ( PHPExcel_Style_Font  $font)

Set font.

Parameters
PHPExcel_Style_Font$font
Returns
PHPExcel_Style

Definition at line 549 of file Style.php.

{
$this->_font = $font;
return $this;
}
PHPExcel_Style::setHashIndex (   $value)

Set hash index.

Note that this index may vary during script execution! Only reliable moment is while doing a write of a workbook and when changes are not allowed.

Parameters
string$valueHash index

Implements PHPExcel_IComparable.

Definition at line 665 of file Style.php.

{
$this->_hashIndex = $value;
}
PHPExcel_Style::setIndex (   $pValue)

Set own index in style collection.

Parameters
int$pValue

Definition at line 684 of file Style.php.

Referenced by PHPExcel\addCellStyleXf(), and PHPExcel\addCellXf().

{
$this->_index = $pValue;
}

+ Here is the caller graph for this function:

Field Documentation

PHPExcel_Style::$_alignment
private

Definition at line 99 of file Style.php.

Referenced by getAlignment().

PHPExcel_Style::$_borders
private

Definition at line 92 of file Style.php.

Referenced by getBorders().

PHPExcel_Style::$_conditionalStyles
private

Definition at line 113 of file Style.php.

PHPExcel_Style::$_fill
private

Definition at line 85 of file Style.php.

Referenced by getFill().

PHPExcel_Style::$_font
private

Definition at line 78 of file Style.php.

Referenced by getFont().

PHPExcel_Style::$_hashIndex
private

Definition at line 643 of file Style.php.

Referenced by getHashIndex().

PHPExcel_Style::$_index
private

Definition at line 141 of file Style.php.

Referenced by getIndex().

PHPExcel_Style::$_isSupervisor
private

Definition at line 127 of file Style.php.

Referenced by getIsSupervisor().

PHPExcel_Style::$_numberFormat
private

Definition at line 106 of file Style.php.

Referenced by getNumberFormat().

PHPExcel_Style::$_parent
private

Definition at line 134 of file Style.php.

Referenced by getParent().

PHPExcel_Style::$_protection
private

Definition at line 120 of file Style.php.

Referenced by getProtection().


The documentation for this class was generated from the following file: