31 define(
'PHPEXCEL_ROOT', dirname(__FILE__) .
'/');
32 require(PHPEXCEL_ROOT .
'PHPExcel/Autoloader.php');
165 $this->_hasMacros=(bool)$hasMacros;
174 $this->_macrosCode=$MacrosCode;
193 $this->_macrosCertificate=$Certificate;
202 return !is_null($this->_macrosCertificate);
221 $this->_hasMacros=
false;
222 $this->_macrosCode=NULL;
223 $this->_macrosCertificate=NULL;
231 if(!is_null($Target) && !is_null($XMLData)){
232 $this->_ribbonXMLData=array(
'target'=>$Target,
'data'=>$XMLData);
234 $this->_ribbonXMLData=NULL;
245 $What=strtolower($What);
252 if(is_array($this->_ribbonXMLData) && array_key_exists($What,$this->_ribbonXMLData)){
253 $ReturnData=$this->_ribbonXMLData[$What];
265 if(!is_null($BinObjectsNames) && !is_null($BinObjectsData)){
266 $this->_ribbonBinObjects=array(
'names'=>$BinObjectsNames,
'data'=>$BinObjectsData);
268 $this->_ribbonBinObjects=NULL;
276 return pathinfo($ThePath, PATHINFO_EXTENSION);
285 $What=strtolower($What);
292 if(is_array($this->_ribbonBinObjects) && array_key_exists($What, $this->_ribbonBinObjects)){
293 $ReturnData=$this->_ribbonBinObjects[$What];
297 if(is_array($this->_ribbonBinObjects) && array_key_exists(
'data', $this->_ribbonBinObjects) && is_array($this->_ribbonBinObjects[
'data'])){
298 $tmpTypes=array_keys($this->_ribbonBinObjects[
'data']);
299 $ReturnData=array_unique(array_map(array($this,
'_getExtensionOnly'), $tmpTypes));
313 return !is_null($this->_ribbonXMLData);
322 return !is_null($this->_ribbonBinObjects);
344 $worksheetCount = count($this->_workSheetCollection);
345 for (
$i = 0;
$i < $worksheetCount; ++
$i) {
346 if ($this->_workSheetCollection[
$i]->getCodeName() == $pName) {
347 return $this->_workSheetCollection[
$i];
359 $this->_uniqueID = uniqid();
363 $this->_workSheetCollection = array();
365 $this->_activeSheetIndex = 0;
374 $this->_namedRanges = array();
378 $this->_cellXfSupervisor->bindParent($this);
402 foreach($this->_workSheetCollection as $k => &
$worksheet) {
404 $this->_workSheetCollection[$k] =
null;
407 $this->_workSheetCollection = array();
437 $this->_properties = $pValue;
457 $this->_security = $pValue;
469 return $this->
getSheet($this->_activeSheetIndex);
482 $this->
addSheet($newSheet, $iSheetIndex);
509 "Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename this worksheet first."
513 if($iSheetIndex === NULL) {
514 if ($this->_activeSheetIndex < 0) {
515 $this->_activeSheetIndex = 0;
517 $this->_workSheetCollection[] = $pSheet;
521 $this->_workSheetCollection,
528 if ($this->_activeSheetIndex >= $iSheetIndex) {
549 $numSheets = count($this->_workSheetCollection);
551 if ($pIndex > $numSheets - 1) {
553 "You tried to remove a sheet by the out of bounds index: {$pIndex}. The actual number of sheets is {$numSheets}."
556 array_splice($this->_workSheetCollection, $pIndex, 1);
559 if (($this->_activeSheetIndex >= $pIndex) &&
560 ($pIndex > count($this->_workSheetCollection) - 1)) {
575 if (!isset($this->_workSheetCollection[$pIndex])) {
578 "Your requested sheet index: {$pIndex} is out of bounds. The actual number of sheets is {$numSheets}."
582 return $this->_workSheetCollection[$pIndex];
603 $worksheetCount = count($this->_workSheetCollection);
604 for (
$i = 0;
$i < $worksheetCount; ++
$i) {
605 if ($this->_workSheetCollection[
$i]->getTitle() === $pName) {
606 return $this->_workSheetCollection[
$i];
622 foreach ($this->_workSheetCollection as
$key => $value) {
623 if ($value->getHashCode() == $pSheet->
getHashCode()) {
642 $pSheet = array_splice(
643 $this->_workSheetCollection,
648 $this->_workSheetCollection,
663 return count($this->_workSheetCollection);
685 $numSheets = count($this->_workSheetCollection);
687 if ($pIndex > $numSheets - 1) {
689 "You tried to set a sheet active by the out of bounds index: {$pIndex}. The actual number of sheets is {$numSheets}."
692 $this->_activeSheetIndex = $pIndex;
721 $returnValue = array();
723 for (
$i = 0;
$i < $worksheetCount; ++
$i) {
724 $returnValue[] = $this->
getSheet(
$i)->getTitle();
740 throw new PHPExcel_Exception(
"Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename the external sheet first.");
744 $countCellXfs = count($this->_cellXfCollection);
747 foreach ($pSheet->
getParent()->getCellXfCollection() as $cellXf) {
756 $cell = $pSheet->
getCell($cellID);
757 $cell->setXfIndex( $cell->getXfIndex() + $countCellXfs );
760 return $this->
addSheet($pSheet, $iSheetIndex);
779 if ($namedRange->
getScope() ==
null) {
781 $this->_namedRanges[$namedRange->
getName()] = $namedRange;
784 $this->_namedRanges[$namedRange->
getScope()->getTitle().
'!'.$namedRange->
getName()] = $namedRange;
799 if ($namedRange !=
'' && ($namedRange !== NULL)) {
801 if (isset($this->_namedRanges[$namedRange])) {
802 $returnValue = $this->_namedRanges[$namedRange];
806 if (($pSheet !== NULL) && isset($this->_namedRanges[$pSheet->getTitle() .
'!' . $namedRange])) {
807 $returnValue = $this->_namedRanges[$pSheet->getTitle() .
'!' . $namedRange];
822 if ($pSheet === NULL) {
823 if (isset($this->_namedRanges[$namedRange])) {
824 unset($this->_namedRanges[$namedRange]);
827 if (isset($this->_namedRanges[$pSheet->getTitle() .
'!' . $namedRange])) {
828 unset($this->_namedRanges[$pSheet->getTitle() .
'!' . $namedRange]);
849 $copied = clone $this;
851 $worksheetCount = count($this->_workSheetCollection);
852 for (
$i = 0;
$i < $worksheetCount; ++
$i) {
853 $this->_workSheetCollection[
$i] = $this->_workSheetCollection[
$i]->copy();
854 $this->_workSheetCollection[
$i]->rebindParent($this);
864 foreach($this as
$key => $val) {
865 if (is_object($val) || (is_array($val))) {
866 $this->{
$key} = unserialize(serialize($val));
889 return $this->_cellXfCollection[$pIndex];
900 foreach ($this->_cellXfCollection as $cellXf) {
901 if ($cellXf->getHashCode() == $pValue) {
916 return in_array($pCellStyle, $this->_cellXfCollection,
true);
927 if (isset($this->_cellXfCollection[0])) {
928 return $this->_cellXfCollection[0];
940 $this->_cellXfCollection[] =
$style;
941 $style->setIndex(count($this->_cellXfCollection) - 1);
952 if ($pIndex > count($this->_cellXfCollection) - 1) {
956 array_splice($this->_cellXfCollection, $pIndex, 1);
959 foreach ($this->_workSheetCollection as
$worksheet) {
960 foreach (
$worksheet->getCellCollection(
false) as $cellID) {
962 $xfIndex = $cell->getXfIndex();
963 if ($xfIndex > $pIndex ) {
965 $cell->setXfIndex($xfIndex - 1);
966 }
else if ($xfIndex == $pIndex) {
968 $cell->setXfIndex(0);
1003 return $this->_cellStyleXfCollection[$pIndex];
1014 foreach ($this->_cellStyleXfCollection as $cellStyleXf) {
1015 if ($cellStyleXf->getHashCode() == $pValue) {
1016 return $cellStyleXf;
1029 $this->_cellStyleXfCollection[] = $pStyle;
1030 $pStyle->
setIndex(count($this->_cellStyleXfCollection) - 1);
1041 if ($pIndex > count($this->_cellStyleXfCollection) - 1) {
1044 array_splice($this->_cellStyleXfCollection, $pIndex, 1);
1055 $countReferencesCellXf = array();
1056 foreach ($this->_cellXfCollection as
$index => $cellXf) {
1057 $countReferencesCellXf[
$index] = 0;
1063 foreach ($sheet->getCellCollection(
false) as $cellID) {
1064 $cell = $sheet->getCell($cellID);
1065 ++$countReferencesCellXf[$cell->getXfIndex()];
1069 foreach ($sheet->getRowDimensions() as $rowDimension) {
1070 if ($rowDimension->getXfIndex() !==
null) {
1071 ++$countReferencesCellXf[$rowDimension->getXfIndex()];
1076 foreach ($sheet->getColumnDimensions() as $columnDimension) {
1077 ++$countReferencesCellXf[$columnDimension->getXfIndex()];
1083 $countNeededCellXfs = 0;
1084 foreach ($this->_cellXfCollection as
$index => $cellXf) {
1085 if ($countReferencesCellXf[
$index] > 0 ||
$index == 0) {
1086 ++$countNeededCellXfs;
1088 unset($this->_cellXfCollection[
$index]);
1090 $map[
$index] = $countNeededCellXfs - 1;
1092 $this->_cellXfCollection = array_values($this->_cellXfCollection);
1095 foreach ($this->_cellXfCollection as
$i => $cellXf) {
1096 $cellXf->setIndex(
$i);
1100 if (empty($this->_cellXfCollection)) {
1108 foreach ($sheet->getCellCollection(
false) as $cellID) {
1109 $cell = $sheet->getCell($cellID);
1110 $cell->setXfIndex( $map[$cell->getXfIndex()] );
1114 foreach ($sheet->getRowDimensions() as $rowDimension) {
1115 if ($rowDimension->getXfIndex() !==
null) {
1116 $rowDimension->setXfIndex( $map[$rowDimension->getXfIndex()] );
1121 foreach ($sheet->getColumnDimensions() as $columnDimension) {
1122 $columnDimension->setXfIndex( $map[$columnDimension->getXfIndex()] );
1126 $sheet->garbageCollect();
An exception for terminatinating execution or to throw for unit testing.
static getInstance(PHPExcel $workbook=NULL)
Get an instance of this class.
static unsetInstance(PHPExcel $workbook=NULL)
Unset an instance of this class.
setIndex($pValue)
Set own index in style collection.
getCell($pCoordinate='A1')
Get cell at a specific coordinate.
getHashCode()
Get hash code.
rebindParent(PHPExcel $parent)
Re-bind parent.
getCellCollection($pSorted=true)
Get collection of cells.
setActiveSheetIndex($pIndex=0)
Set active sheet index.
getWorksheetIterator()
Get worksheet iterator.
removeNamedRange($namedRange, PHPExcel_Worksheet $pSheet=null)
Remove named range.
garbageCollect()
Eliminate all unneeded cellXf and afterwards update the xfIndex for all cells and columns in the work...
getDefaultStyle()
Get default style.
_getExtensionOnly($ThePath)
return the extension of a filename.
getCellStyleXfByHashCode($pValue='')
Get cellStyleXf by hash code.
hasRibbon()
This workbook have a custom UI ?
sheetNameExists($pSheetName)
Check if a sheet with a specified name already exists.
addCellXf(PHPExcel_Style $style)
Add a cellXf to the workbook.
discardMacros()
Remove all macros, certificate from spreadsheet.
cellXfExists($pCellStyle=null)
Check if style exists in style collection.
addExternalSheet(PHPExcel_Worksheet $pSheet, $iSheetIndex=null)
Add external sheet.
hasMacrosCertificate()
Is the project signed ?
getAllSheets()
Get all sheets.
getID()
Return the unique ID value assigned to this spreadsheet workbook.
setRibbonBinObjects($BinObjectsNames=NULL, $BinObjectsData=NULL)
store binaries ribbon objects (pictures)
getSheetCount()
Get sheet count.
disconnectWorksheets()
Disconnect all worksheets from this PHPExcel workbook object, typically so that the PHPExcel object c...
getSheetByName($pName='')
Get sheet by name.
createSheet($iSheetIndex=NULL)
Create sheet and add it to this workbook.
hasMacros()
The workbook has macros ?
getNamedRanges()
Get named ranges.
getActiveSheetIndex()
Get active sheet index.
removeCellStyleXfByIndex($pIndex=0)
Remove cellStyleXf by index.
getSecurity()
Get security.
setHasMacros($hasMacros=false)
Define if a workbook has macros.
getCellXfCollection()
Get the workbook collection of cellXfs.
copy()
Copy workbook (!= clone!)
getCellXfByHashCode($pValue='')
Get cellXf by hash code.
setMacrosCertificate($Certificate=NULL)
Set the macros certificate.
sheetCodeNameExists($pSheetCodeName)
Check if a sheet with a specified code name already exists.
setProperties(PHPExcel_DocumentProperties $pValue)
Set properties.
__destruct()
Code to execute when this worksheet is unset()
getRibbonXMLData($What='all')
retrieve ribbon XML Data
getActiveSheet()
Get active sheet.
getCellStyleXfCollection()
Get the workbook collection of cellStyleXfs.
addNamedRange(PHPExcel_NamedRange $namedRange)
Add named range.
getCalculationEngine()
Return the calculation engine for this worksheet.
setIndexByName($sheetName, $newIndex)
Set index for sheet by sheet name.
setRibbonXMLData($Target=NULL, $XMLData=NULL)
set ribbon XML data
removeCellXfByIndex($pIndex=0)
Remove cellXf by index.
__clone()
Implement PHP __clone to create a deep clone, not just a shallow copy.
getSheetByCodeName($pName='')
Get sheet by code name.
setSecurity(PHPExcel_DocumentSecurity $pValue)
Set security.
getMacrosCertificate()
Return the macros certificate.
setMacrosCode($MacrosCode)
Set the macros code.
getIndex(PHPExcel_Worksheet $pSheet)
Get index for sheet.
getCellXfSupervisor()
Get the cellXf supervisor.
addCellStyleXf(PHPExcel_Style $pStyle)
Add a cellStyleXf to the workbook.
__construct()
Create a new PHPExcel with one Worksheet.
addSheet(PHPExcel_Worksheet $pSheet, $iSheetIndex=NULL)
Add sheet.
getSheetNames()
Get sheet names.
getRibbonBinObjects($What='all')
retrieve Binaries Ribbon Objects
getCellXfByIndex($pIndex=0)
Get cellXf by index.
removeSheetByIndex($pIndex=0)
Remove sheet by index.
getCellStyleXfByIndex($pIndex=0)
Get cellStyleXf by index.
getProperties()
Get properties.
getNamedRange($namedRange, PHPExcel_Worksheet $pSheet=null)
Get named range.
getMacrosCode()
Return the macros code.
getSheet($pIndex=0)
Get sheet by index.
setActiveSheetIndexByName($pValue='')
Set active sheet index by name.
hasRibbonBinObjects()
This workbook have additionnal object for the ribbon ?
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'