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

Public Member Functions

 __construct ()
 Create a new PHPExcel with one Worksheet.
 getProperties ()
 Get properties.
 setProperties (PHPExcel_DocumentProperties $pValue)
 Set properties.
 getSecurity ()
 Get security.
 setSecurity (PHPExcel_DocumentSecurity $pValue)
 Set security.
 getActiveSheet ()
 Get active sheet.
 createSheet ($iSheetIndex=null)
 Create sheet and add it to this workbook.
 addSheet (PHPExcel_Worksheet $pSheet=null, $iSheetIndex=null)
 Add sheet.
 removeSheetByIndex ($pIndex=0)
 Remove sheet by index.
 getSheet ($pIndex=0)
 Get sheet by index.
 getAllSheets ()
 Get all sheets.
 getSheetByName ($pName= '')
 Get sheet by name.
 getIndex (PHPExcel_Worksheet $pSheet)
 Get index for sheet.
 setIndexByName ($sheetName, $newIndex)
 Set index for sheet by sheet name.
 getSheetCount ()
 Get sheet count.
 getActiveSheetIndex ()
 Get active sheet index.
 setActiveSheetIndex ($pIndex=0)
 Set active sheet index.
 getSheetNames ()
 Get sheet names.
 addExternalSheet (PHPExcel_Worksheet $pSheet)
 Add external sheet.
 getNamedRanges ()
 Get named ranges.
 addNamedRange (PHPExcel_NamedRange $namedRange)
 Add named range.
 getNamedRange ($namedRange, PHPExcel_Worksheet $pSheet=null)
 Get named range.
 removeNamedRange ($namedRange, PHPExcel_Worksheet $pSheet=null)
 Remove named range.
 getWorksheetIterator ()
 Get worksheet iterator.
 copy ()
 Copy workbook (!= clone!)
 __clone ()
 Implement PHP __clone to create a deep clone, not just a shallow copy.
 getCellXfCollection ()
 Get the workbook collection of cellXfs.
 getCellXfByIndex ($pIndex=0)
 Get cellXf by index.
 getCellXfByHashCode ($pValue= '')
 Get cellXf by hash code.
 getDefaultStyle ()
 Get default style.
 addCellXf (PHPExcel_Style $style)
 Add a cellXf to the workbook.
 removeCellXfByIndex ($pIndex=0)
 Remove cellXf by index.
 getCellXfSupervisor ()
 Get the cellXf supervisor.
 getCellStyleXfCollection ()
 Get the workbook collection of cellStyleXfs.
 getCellStyleXfByIndex ($pIndex=0)
 Get cellStyleXf by index.
 getCellStyleXfByHashCode ($pValue= '')
 Get cellStyleXf by hash code.
 addCellStyleXf (PHPExcel_Style $pStyle)
 Add a cellStyleXf to the workbook.
 removeCellStyleXfByIndex ($pIndex=0)
 Remove cellStyleXf by index.
 garbageCollect ()
 Eliminate all unneeded cellXf and afterwards update the xfIndex for all cells in the workbook.

Private Attributes

 $_properties
 $_security
 $_workSheetCollection = array()
 $_activeSheetIndex = 0
 $_namedRanges = array()
 $_cellXfSupervisor
 $_cellXfCollection = array()
 $_cellStyleXfCollection = array()

Detailed Description

Definition at line 63 of file PHPExcel.php.

Constructor & Destructor Documentation

PHPExcel::__construct ( )

Create a new PHPExcel with one Worksheet.

Definition at line 124 of file PHPExcel.php.

References addCellStyleXf(), and addCellXf().

{
// Initialise worksheet collection and add one worksheet
$this->_workSheetCollection = array();
$this->_workSheetCollection[] = new PHPExcel_Worksheet($this);
$this->_activeSheetIndex = 0;
// Create document properties
$this->_properties = new PHPExcel_DocumentProperties();
// Create document security
$this->_security = new PHPExcel_DocumentSecurity();
// Set named ranges
$this->_namedRanges = array();
// Create the cellXf supervisor
$this->_cellXfSupervisor = new PHPExcel_Style(true);
$this->_cellXfSupervisor->bindParent($this);
// Create the default style
}

+ Here is the call graph for this function:

Member Function Documentation

PHPExcel::__clone ( )

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

Definition at line 529 of file PHPExcel.php.

References $key.

{
foreach($this as $key => $val) {
if (is_object($val) || (is_array($val))) {
$this->{$key} = unserialize(serialize($val));
}
}
}
PHPExcel::addCellStyleXf ( PHPExcel_Style  $pStyle)

Add a cellStyleXf to the workbook.

Parameters
PHPExcel_Style$pStyle

Definition at line 681 of file PHPExcel.php.

References PHPExcel_Style\setIndex().

Referenced by __construct().

{
$this->_cellStyleXfCollection[] = $pStyle;
$pStyle->setIndex(count($this->_cellStyleXfCollection) - 1);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PHPExcel::addCellXf ( PHPExcel_Style  $style)

Add a cellXf to the workbook.

Parameters
PHPExcel_Style

Definition at line 593 of file PHPExcel.php.

References PHPExcel_Style\setIndex().

Referenced by __construct(), and addExternalSheet().

{
$this->_cellXfCollection[] = $style;
$style->setIndex(count($this->_cellXfCollection) - 1);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PHPExcel::addExternalSheet ( PHPExcel_Worksheet  $pSheet)

Add external sheet.

Parameters
PHPExcel_Worksheet$pSheetExternal sheet to add
Exceptions
Exception
Returns
PHPExcel_Worksheet

Definition at line 396 of file PHPExcel.php.

References addCellXf(), addSheet(), PHPExcel_Worksheet\getCellCollection(), PHPExcel_Worksheet\getParent(), getSheetByName(), PHPExcel_Worksheet\getTitle(), and PHPExcel_Worksheet\rebindParent().

{
if (!is_null($this->getSheetByName($pSheet->getTitle()))) {
throw new Exception("Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename the external sheet first.");
}
// count how many cellXfs there are in this workbook currently, we will need this below
$countCellXfs = count($this->_cellXfCollection);
// copy all the shared cellXfs from the external workbook and append them to the current
foreach ($pSheet->getParent()->getCellXfCollection() as $cellXf) {
$this->addCellXf(clone $cellXf);
}
// move sheet to this workbook
$pSheet->rebindParent($this);
// update the cellXfs
foreach ($pSheet->getCellCollection(false) as $cell) {
$cell->setXfIndex( $cell->getXfIndex() + $countCellXfs );
}
return $this->addSheet($pSheet);
}

+ Here is the call graph for this function:

PHPExcel::addNamedRange ( PHPExcel_NamedRange  $namedRange)

Add named range.

Parameters
PHPExcel_NamedRange$namedRange
Returns
PHPExcel

Definition at line 435 of file PHPExcel.php.

References PHPExcel_NamedRange\getName(), and PHPExcel_NamedRange\getWorksheet().

Referenced by PHPExcel_Worksheet\rebindParent().

{
$this->_namedRanges[$namedRange->getWorksheet()->getTitle().'!'.$namedRange->getName()] = $namedRange;
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PHPExcel::addSheet ( PHPExcel_Worksheet  $pSheet = null,
  $iSheetIndex = null 
)

Add sheet.

Parameters
PHPExcel_Worksheet$pSheet
Exceptions
Exception

Definition at line 217 of file PHPExcel.php.

Referenced by addExternalSheet(), and createSheet().

{
if(is_null($iSheetIndex))
{
$this->_workSheetCollection[] = $pSheet;
}
else
{
// Insert the sheet at the requested index
array_splice(
$this->_workSheetCollection,
$iSheetIndex,
0,
array($pSheet)
);
}
}

+ Here is the caller graph for this function:

PHPExcel::copy ( )

Copy workbook (!= clone!)

Returns
PHPExcel

Definition at line 514 of file PHPExcel.php.

{
$copied = clone $this;
$worksheetCount = count($this->_workSheetCollection);
for ($i = 0; $i < $worksheetCount; ++$i) {
$this->_workSheetCollection[$i] = $this->_workSheetCollection[$i]->copy();
$this->_workSheetCollection[$i]->rebindParent($this);
}
return $copied;
}
PHPExcel::createSheet (   $iSheetIndex = null)

Create sheet and add it to this workbook.

Returns
PHPExcel_Worksheet

Definition at line 204 of file PHPExcel.php.

References addSheet().

Referenced by PHPExcel_Reader_CSV\loadIntoExisting().

{
$newSheet = new PHPExcel_Worksheet($this);
$this->addSheet($newSheet, $iSheetIndex);
return $newSheet;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PHPExcel::garbageCollect ( )

Eliminate all unneeded cellXf and afterwards update the xfIndex for all cells in the workbook.

Definition at line 705 of file PHPExcel.php.

References $map, and getWorksheetIterator().

{
// how many references are there to each cellXf ?
$countReferencesCellXf = array();
foreach ($this->_cellXfCollection as $index => $cellXf) {
$countReferencesCellXf[$index] = 0;
}
foreach ($this->getWorksheetIterator() as $sheet) {
foreach ($sheet->getCellCollection(false) as $cell) {
++$countReferencesCellXf[$cell->getXfIndex()];
}
}
// remove those cellXfs that have zero references and create mapping so we can update xfIndex for all cells
$countNeededCellXfs = 0;
foreach ($this->_cellXfCollection as $index => $cellXf) {
if ($countReferencesCellXf[$index] > 0 || $index == 0) { // we must never remove the first cellXf
++$countNeededCellXfs;
} else {
unset($this->_cellXfCollection[$index]);
}
$map[$index] = $countNeededCellXfs - 1;
}
$this->_cellXfCollection = array_values($this->_cellXfCollection);
// if we removed the first style by accident, recreate it
if (count($this->_cellXfCollection) == 0) {
$this->_cellXfCollection[] = new PHPExcel_Style();
}
// update the xfIndex for all cells
foreach ($this->getWorksheetIterator() as $sheet) {
foreach ($sheet->getCellCollection(false) as $cell) {
$cell->setXfIndex( $map[$cell->getXfIndex()] );
}
}
// also do garbage collection for all the sheets
foreach ($this->getWorksheetIterator() as $sheet) {
$sheet->garbageCollect();
}
}

+ Here is the call graph for this function:

PHPExcel::getActiveSheet ( )

Get active sheet.

Returns
PHPExcel_Worksheet

Definition at line 194 of file PHPExcel.php.

References $_activeSheetIndex.

Referenced by PHPExcel_Reader_CSV\loadIntoExisting(), and setActiveSheetIndex().

{
return $this->_workSheetCollection[$this->_activeSheetIndex];
}

+ Here is the caller graph for this function:

PHPExcel::getActiveSheetIndex ( )

Get active sheet index.

Returns
int Active sheet index

Definition at line 351 of file PHPExcel.php.

References $_activeSheetIndex.

PHPExcel::getAllSheets ( )

Get all sheets.

Returns
PHPExcel_Worksheet[]

Definition at line 271 of file PHPExcel.php.

References $_workSheetCollection.

PHPExcel::getCellStyleXfByHashCode (   $pValue = '')

Get cellStyleXf by hash code.

Parameters
string$pValue
Returns
PHPExcel_Style|false

Definition at line 666 of file PHPExcel.php.

{
foreach ($this->_cellXfStyleCollection as $cellStyleXf) {
if ($cellStyleXf->getHashCode() == $pValue) {
return $cellStyleXf;
}
}
return false;
}
PHPExcel::getCellStyleXfByIndex (   $pIndex = 0)

Get cellStyleXf by index.

Parameters
int$pIndex
Returns
PHPExcel_Style

Definition at line 655 of file PHPExcel.php.

{
return $this->_cellStyleXfCollection[$pIndex];
}
PHPExcel::getCellStyleXfCollection ( )

Get the workbook collection of cellStyleXfs.

Returns
PHPExcel_Style[]

Definition at line 644 of file PHPExcel.php.

References $_cellStyleXfCollection.

PHPExcel::getCellXfByHashCode (   $pValue = '')

Get cellXf by hash code.

Parameters
string$pValue
Returns
PHPExcel_Style|false

Definition at line 564 of file PHPExcel.php.

{
foreach ($this->_cellXfCollection as $cellXf) {
if ($cellXf->getHashCode() == $pValue) {
return $cellXf;
}
}
return false;
}
PHPExcel::getCellXfByIndex (   $pIndex = 0)

Get cellXf by index.

Parameters
int$index
Returns
PHPExcel_Style

Definition at line 553 of file PHPExcel.php.

{
return $this->_cellXfCollection[$pIndex];
}
PHPExcel::getCellXfCollection ( )

Get the workbook collection of cellXfs.

Returns
PHPExcel_Style[]

Definition at line 542 of file PHPExcel.php.

References $_cellXfCollection.

PHPExcel::getCellXfSupervisor ( )

Get the cellXf supervisor.

Returns
PHPExcel_Style

Definition at line 634 of file PHPExcel.php.

References $_cellXfSupervisor.

PHPExcel::getDefaultStyle ( )

Get default style.

Returns
PHPExcel_Style
Exceptions
Exception

Definition at line 580 of file PHPExcel.php.

Referenced by PHPExcel_Writer_HTML\__construct().

{
if (isset($this->_cellXfCollection[0])) {
return $this->_cellXfCollection[0];
}
throw new Exception('No default style found for this workbook');
}

+ Here is the caller graph for this function:

PHPExcel::getIndex ( PHPExcel_Worksheet  $pSheet)

Get index for sheet.

Parameters
PHPExcel_Worksheet$pSheet
Returns
Sheet index
Exceptions
Exception

Definition at line 302 of file PHPExcel.php.

References $key, and PHPExcel_Worksheet\getHashCode().

Referenced by setIndexByName().

{
foreach ($this->_workSheetCollection as $key => $value) {
if ($value->getHashCode() == $pSheet->getHashCode()) {
return $key;
}
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PHPExcel::getNamedRange (   $namedRange,
PHPExcel_Worksheet  $pSheet = null 
)

Get named range.

Parameters
string$namedRange

Definition at line 445 of file PHPExcel.php.

References $key.

{
if ($namedRange != '' && !is_null($namedRange)) {
if (!is_null($pSheet)) {
$key = $pSheet->getTitle().'!'.$namedRange;
if (isset($this->_namedRanges[$key])) {
return $this->_namedRanges[$key];
}
}
$returnCount = 0;
foreach($this->_namedRanges as $_namedRange) {
if ($_namedRange->getName() == $namedRange) {
if ((!is_null($pSheet)) && ($_namedRange->getWorksheet()->getTitle() == $pSheet->getTitle())) {
return $_namedRange;
} else {
$returnCount++;
$returnValue = $_namedRange;
}
}
}
if ($returnCount == 1) {
return $returnValue;
}
}
return null;
}
PHPExcel::getNamedRanges ( )

Get named ranges.

Returns
PHPExcel_NamedRange[]

Definition at line 425 of file PHPExcel.php.

References $_namedRanges.

Referenced by PHPExcel_Writer_Excel2007_Workbook\_writeNamedRanges().

{
}

+ Here is the caller graph for this function:

PHPExcel::getProperties ( )

Get properties.

Returns
PHPExcel_DocumentProperties

Definition at line 154 of file PHPExcel.php.

References $_properties.

{
}
PHPExcel::getSecurity ( )

Get security.

Returns
PHPExcel_DocumentSecurity

Definition at line 174 of file PHPExcel.php.

References $_security.

{
}
PHPExcel::getSheet (   $pIndex = 0)

Get sheet by index.

Parameters
int$pIndexSheet index
Returns
PHPExcel_Worksheet
Exceptions
Exception

Definition at line 257 of file PHPExcel.php.

Referenced by getSheetNames().

{
if ($pIndex > count($this->_workSheetCollection) - 1) {
throw new Exception("Sheet index is out of bounds.");
} else {
return $this->_workSheetCollection[$pIndex];
}
}

+ Here is the caller graph for this function:

PHPExcel::getSheetByName (   $pName = '')

Get sheet by name.

Parameters
string$pNameSheet name
Returns
PHPExcel_Worksheet
Exceptions
Exception

Definition at line 283 of file PHPExcel.php.

Referenced by addExternalSheet(), and setIndexByName().

{
$worksheetCount = count($this->_workSheetCollection);
for ($i = 0; $i < $worksheetCount; ++$i) {
if ($this->_workSheetCollection[$i]->getTitle() == $pName) {
return $this->_workSheetCollection[$i];
}
}
return null;
}

+ Here is the caller graph for this function:

PHPExcel::getSheetCount ( )

Get sheet count.

Returns
int

Definition at line 341 of file PHPExcel.php.

Referenced by getSheetNames(), and PHPExcel_Reader_CSV\loadIntoExisting().

{
return count($this->_workSheetCollection);
}

+ Here is the caller graph for this function:

PHPExcel::getSheetNames ( )

Get sheet names.

Returns
string[]

Definition at line 378 of file PHPExcel.php.

References getSheet(), and getSheetCount().

{
$returnValue = array();
$worksheetCount = $this->getSheetCount();
for ($i = 0; $i < $worksheetCount; ++$i) {
array_push($returnValue, $this->getSheet($i)->getTitle());
}
return $returnValue;
}

+ Here is the call graph for this function:

PHPExcel::getWorksheetIterator ( )

Get worksheet iterator.

Returns
PHPExcel_WorksheetIterator

Definition at line 505 of file PHPExcel.php.

Referenced by garbageCollect(), and PHPExcel_ReferenceHelper\updateNamedFormulas().

{
return new PHPExcel_WorksheetIterator($this);
}

+ Here is the caller graph for this function:

PHPExcel::removeCellStyleXfByIndex (   $pIndex = 0)

Remove cellStyleXf by index.

Parameters
int$pIndex
Exceptions
Exception

Definition at line 693 of file PHPExcel.php.

{
if ($pIndex > count($this->_cellStyleXfCollection) - 1) {
throw new Exception("CellStyleXf index is out of bounds.");
} else {
array_splice($this->_cellStyleXfCollection, $pIndex, 1);
}
}
PHPExcel::removeCellXfByIndex (   $pIndex = 0)

Remove cellXf by index.

It is ensured that all cells get their xf index updated.

Parameters
int$pIndexIndex to cellXf
Exceptions
Exception

Definition at line 605 of file PHPExcel.php.

{
if ($pIndex > count($this->_cellXfCollection) - 1) {
throw new Exception("CellXf index is out of bounds.");
} else {
// first remove the cellXf
array_splice($this->_cellXfCollection, $pIndex, 1);
// then update cellXf indexes for cells
foreach ($this->_workSheetCollection as $worksheet) {
foreach ($worksheet->getCellCollection(false) as $cell) {
$xfIndex = $cell->getXfIndex();
if ($xfIndex > $pIndex ) {
// decrease xf index by 1
$cell->setXfIndex($xfIndex - 1);
} else if ($xfIndex == $pIndex) {
// set to default xf index 0
$cell->setXfIndex(0);
}
}
}
}
}
PHPExcel::removeNamedRange (   $namedRange,
PHPExcel_Worksheet  $pSheet = null 
)

Remove named range.

Parameters
string$namedRange
Returns
PHPExcel

Definition at line 478 of file PHPExcel.php.

References $key.

{
if ($namedRange != '' && !is_null($namedRange)) {
if (!is_null($pSheet)) {
$key = $pSheet->getTitle().'!'.$namedRange;
if (isset($this->_namedRanges[$key])) {
unset($this->_namedRanges[$key]);
}
}
foreach($this->_namedRanges as $_namedRange) {
if ($_namedRange->getName() == $namedRange) {
if ((!is_null($pSheet)) && ($_namedRange->getWorksheet()->getTitle() == $pSheet->getTitle())) {
$key = $pSheet->getTitle().'!'.$namedRange;
if (isset($this->_namedRanges[$key])) {
unset($this->_namedRanges[$key]);
}
}
}
}
}
return $this;
}
PHPExcel::removeSheetByIndex (   $pIndex = 0)

Remove sheet by index.

Parameters
int$pIndexActive sheet index
Exceptions
Exception

Definition at line 241 of file PHPExcel.php.

Referenced by PHPExcel_Reader_Excel2007\load(), and PHPExcel_Reader_Excel5\load().

{
if ($pIndex > count($this->_workSheetCollection) - 1) {
throw new Exception("Sheet index is out of bounds.");
} else {
array_splice($this->_workSheetCollection, $pIndex, 1);
}
}

+ Here is the caller graph for this function:

PHPExcel::setActiveSheetIndex (   $pIndex = 0)

Set active sheet index.

Parameters
int$pIndexActive sheet index
Exceptions
Exception
Returns
PHPExcel_Worksheet

Definition at line 363 of file PHPExcel.php.

References getActiveSheet().

Referenced by PHPExcel_Reader_CSV\loadIntoExisting().

{
if ($pIndex > count($this->_workSheetCollection) - 1) {
throw new Exception("Active sheet index is out of bounds.");
} else {
$this->_activeSheetIndex = $pIndex;
}
return $this->getActiveSheet();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PHPExcel::setIndexByName (   $sheetName,
  $newIndex 
)

Set index for sheet by sheet name.

Parameters
string$sheetNameSheet name to modify index for
int$newIndexNew index for the sheet
Returns
New sheet index
Exceptions
Exception

Definition at line 319 of file PHPExcel.php.

References getIndex(), and getSheetByName().

{
$oldIndex = $this->getIndex($this->getSheetByName($sheetName));
$pSheet = array_splice(
$this->_workSheetCollection,
$oldIndex,
1
);
array_splice(
$this->_workSheetCollection,
$newIndex,
0,
$pSheet
);
return $newIndex;
}

+ Here is the call graph for this function:

PHPExcel::setProperties ( PHPExcel_DocumentProperties  $pValue)

Set properties.

Parameters
PHPExcel_DocumentProperties$pValue

Definition at line 164 of file PHPExcel.php.

{
$this->_properties = $pValue;
}
PHPExcel::setSecurity ( PHPExcel_DocumentSecurity  $pValue)

Set security.

Parameters
PHPExcel_DocumentSecurity$pValue

Definition at line 184 of file PHPExcel.php.

{
$this->_security = $pValue;
}

Field Documentation

PHPExcel::$_activeSheetIndex = 0
private

Definition at line 91 of file PHPExcel.php.

Referenced by getActiveSheet(), and getActiveSheetIndex().

PHPExcel::$_cellStyleXfCollection = array()
private

Definition at line 119 of file PHPExcel.php.

Referenced by getCellStyleXfCollection().

PHPExcel::$_cellXfCollection = array()
private

Definition at line 112 of file PHPExcel.php.

Referenced by getCellXfCollection().

PHPExcel::$_cellXfSupervisor
private

Definition at line 105 of file PHPExcel.php.

Referenced by getCellXfSupervisor().

PHPExcel::$_namedRanges = array()
private

Definition at line 98 of file PHPExcel.php.

Referenced by getNamedRanges().

PHPExcel::$_properties
private

Definition at line 70 of file PHPExcel.php.

Referenced by getProperties().

PHPExcel::$_security
private

Definition at line 77 of file PHPExcel.php.

Referenced by getSecurity().

PHPExcel::$_workSheetCollection = array()
private

Definition at line 84 of file PHPExcel.php.

Referenced by getAllSheets().


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