Use of empty() rather than count() to test if arrays are empty or not - simple performance tweak... empty() is over twice as fast as count()

git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@85344 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
Mark Baker 2012-01-16 12:34:22 +00:00
parent ac37b8ae8d
commit 24a9eb285c
23 changed files with 56 additions and 56 deletions

View File

@ -767,7 +767,7 @@ class PHPExcel
} }
// make sure there is always at least one cellXf (there should be) // make sure there is always at least one cellXf (there should be)
if (count($this->_cellXfCollection) == 0) { if (empty($this->_cellXfCollection)) {
$this->_cellXfCollection[] = new PHPExcel_Style(); $this->_cellXfCollection[] = new PHPExcel_Style();
} }

View File

@ -171,7 +171,7 @@ class PHPExcel_CachedObjectStorage_CacheBase {
$row[$r] = $r; $row[$r] = $r;
$col[$c] = strlen($c).$c; $col[$c] = strlen($c).$c;
} }
if (count($row) > 0) { if (!empty($row)) {
// Determine highest column and row // Determine highest column and row
$highestRow = max($row); $highestRow = max($row);
$highestColumn = substr(max($col),1); $highestColumn = substr(max($col),1);

View File

@ -789,7 +789,7 @@ class PHPExcel_Calculation_DateTime {
} }
// Test any extra holiday parameters // Test any extra holiday parameters
if (count($dateArgs) > 0) { if (!empty($dateArgs)) {
$holidayCountedArray = $holidayDates = array(); $holidayCountedArray = $holidayDates = array();
foreach ($dateArgs as $holidayDate) { foreach ($dateArgs as $holidayDate) {
if ((!is_null($holidayDate)) && (trim($holidayDate) > '')) { if ((!is_null($holidayDate)) && (trim($holidayDate) > '')) {

View File

@ -555,7 +555,7 @@ class PHPExcel_Calculation_Functions {
} elseif (self::isMatrixValue($a)) { } elseif (self::isMatrixValue($a)) {
return 64; return 64;
} }
} elseif(count($value) == 0) { } elseif(empty($value)) {
// Empty Cell // Empty Cell
return 1; return 1;
} }

View File

@ -697,7 +697,7 @@ class PHPExcel_Calculation_LookupRef {
} }
// index_number must be less than or equal to the number of columns in lookup_array // index_number must be less than or equal to the number of columns in lookup_array
if ((!is_array($lookup_array)) || (count($lookup_array) < 1)) { if ((!is_array($lookup_array)) || (empty($lookup_array))) {
return PHPExcel_Calculation_Functions::REF(); return PHPExcel_Calculation_Functions::REF();
} else { } else {
$f = array_keys($lookup_array); $f = array_keys($lookup_array);

View File

@ -61,7 +61,7 @@ class PHPExcel_Calculation_MathTrig {
} }
} }
} }
if (count($factorArray) > 0) { if (!empty($factorArray)) {
rsort($factorArray); rsort($factorArray);
return $factorArray; return $factorArray;
} else { } else {
@ -1040,7 +1040,7 @@ class PHPExcel_Calculation_MathTrig {
$aArgs = PHPExcel_Calculation_Functions::flattenArray($aArgs); $aArgs = PHPExcel_Calculation_Functions::flattenArray($aArgs);
$sumArgs = PHPExcel_Calculation_Functions::flattenArray($sumArgs); $sumArgs = PHPExcel_Calculation_Functions::flattenArray($sumArgs);
if (count($sumArgs) == 0) { if (empty($sumArgs)) {
$sumArgs = $aArgs; $sumArgs = $aArgs;
} }
$condition = PHPExcel_Calculation_Functions::_ifCondition($condition); $condition = PHPExcel_Calculation_Functions::_ifCondition($condition);

View File

@ -841,7 +841,7 @@ class PHPExcel_Calculation_Statistical {
$aArgs = PHPExcel_Calculation_Functions::flattenArray($aArgs); $aArgs = PHPExcel_Calculation_Functions::flattenArray($aArgs);
$averageArgs = PHPExcel_Calculation_Functions::flattenArray($averageArgs); $averageArgs = PHPExcel_Calculation_Functions::flattenArray($averageArgs);
if (count($averageArgs) == 0) { if (empty($averageArgs)) {
$averageArgs = $aArgs; $averageArgs = $aArgs;
} }
$condition = PHPExcel_Calculation_Functions::_ifCondition($condition); $condition = PHPExcel_Calculation_Functions::_ifCondition($condition);
@ -1734,7 +1734,7 @@ class PHPExcel_Calculation_Statistical {
$const = (is_null($const)) ? True : (boolean) PHPExcel_Calculation_Functions::flattenSingleValue($const); $const = (is_null($const)) ? True : (boolean) PHPExcel_Calculation_Functions::flattenSingleValue($const);
$bestFitExponential = trendClass::calculate(trendClass::TREND_EXPONENTIAL,$yValues,$xValues,$const); $bestFitExponential = trendClass::calculate(trendClass::TREND_EXPONENTIAL,$yValues,$xValues,$const);
if (count($newValues) == 0) { if (empty($newValues)) {
$newValues = $bestFitExponential->getXValues(); $newValues = $bestFitExponential->getXValues();
} }
@ -2202,7 +2202,7 @@ class PHPExcel_Calculation_Statistical {
$aArgs = PHPExcel_Calculation_Functions::flattenArray($aArgs); $aArgs = PHPExcel_Calculation_Functions::flattenArray($aArgs);
$sumArgs = PHPExcel_Calculation_Functions::flattenArray($sumArgs); $sumArgs = PHPExcel_Calculation_Functions::flattenArray($sumArgs);
if (count($sumArgs) == 0) { if (empty($sumArgs)) {
$sumArgs = $aArgs; $sumArgs = $aArgs;
} }
$condition = PHPExcel_Calculation_Functions::_ifCondition($condition); $condition = PHPExcel_Calculation_Functions::_ifCondition($condition);
@ -2364,7 +2364,7 @@ class PHPExcel_Calculation_Statistical {
$aArgs = PHPExcel_Calculation_Functions::flattenArray($aArgs); $aArgs = PHPExcel_Calculation_Functions::flattenArray($aArgs);
$sumArgs = PHPExcel_Calculation_Functions::flattenArray($sumArgs); $sumArgs = PHPExcel_Calculation_Functions::flattenArray($sumArgs);
if (count($sumArgs) == 0) { if (empty($sumArgs)) {
$sumArgs = $aArgs; $sumArgs = $aArgs;
} }
$condition = PHPExcel_Calculation_Functions::_ifCondition($condition); $condition = PHPExcel_Calculation_Functions::_ifCondition($condition);
@ -2446,7 +2446,7 @@ class PHPExcel_Calculation_Statistical {
} }
} }
if (count($mArgs) > 0) { if (!empty($mArgs)) {
return self::_modeCalc($mArgs); return self::_modeCalc($mArgs);
} }
@ -3332,7 +3332,7 @@ class PHPExcel_Calculation_Statistical {
$const = (is_null($const)) ? True : (boolean) PHPExcel_Calculation_Functions::flattenSingleValue($const); $const = (is_null($const)) ? True : (boolean) PHPExcel_Calculation_Functions::flattenSingleValue($const);
$bestFitLinear = trendClass::calculate(trendClass::TREND_LINEAR,$yValues,$xValues,$const); $bestFitLinear = trendClass::calculate(trendClass::TREND_LINEAR,$yValues,$xValues,$const);
if (count($newValues) == 0) { if (empty($newValues)) {
$newValues = $bestFitLinear->getXValues(); $newValues = $bestFitLinear->getXValues();
} }

View File

@ -581,7 +581,7 @@ class PHPExcel_Cell
public static function buildRange($pRange) public static function buildRange($pRange)
{ {
// Verify range // Verify range
if (!is_array($pRange) || count($pRange) == 0 || !is_array($pRange[0])) { if (!is_array($pRange) || empty($pRange) || !is_array($pRange[0])) {
throw new Exception('Range does not contain any information.'); throw new Exception('Range does not contain any information.');
} }

View File

@ -482,7 +482,7 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
break; break;
} }
} }
if (count($thisBorder) > 0) { if (!empty($thisBorder)) {
if (($borderPosition == 'left') || ($borderPosition == 'right') || ($borderPosition == 'top') || ($borderPosition == 'bottom')) { if (($borderPosition == 'left') || ($borderPosition == 'right') || ($borderPosition == 'top') || ($borderPosition == 'bottom')) {
$this->_styles[$styleID]['borders'][$borderPosition] = $thisBorder; $this->_styles[$styleID]['borders'][$borderPosition] = $thisBorder;
} }
@ -767,7 +767,7 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
if (($cellIsSet) && (isset($cell_ss['StyleID']))) { if (($cellIsSet) && (isset($cell_ss['StyleID']))) {
$style = (string) $cell_ss['StyleID']; $style = (string) $cell_ss['StyleID'];
// echo 'Cell style for '.$columnID.$rowID.' is '.$style.'<br />'; // echo 'Cell style for '.$columnID.$rowID.' is '.$style.'<br />';
if ((isset($this->_styles[$style])) && (count($this->_styles[$style]) > 0)) { if ((isset($this->_styles[$style])) && (!empty($this->_styles[$style]))) {
// echo 'Cell '.$columnID.$rowID.'<br />'; // echo 'Cell '.$columnID.$rowID.'<br />';
// print_r($this->_styles[$style]); // print_r($this->_styles[$style]);
// echo '<br />'; // echo '<br />';

View File

@ -1186,7 +1186,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$row = null; $row = null;
$clientData = $shape->xpath('.//x:ClientData'); $clientData = $shape->xpath('.//x:ClientData');
if (is_array($clientData) && count($clientData) > 0) { if (is_array($clientData) && !empty($clientData)) {
$clientData = $clientData[0]; $clientData = $clientData[0];
if ( isset($clientData['ObjectType']) && (string)$clientData['ObjectType'] == 'Note' ) { if ( isset($clientData['ObjectType']) && (string)$clientData['ObjectType'] == 'Note' ) {

View File

@ -949,7 +949,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader
} }
} }
if (count($this->_cellNotes) > 0) { if (!empty($this->_cellNotes)) {
foreach($this->_cellNotes as $note => $noteDetails) { foreach($this->_cellNotes as $note => $noteDetails) {
// echo '<b>Cell annotation ',$note,'</b><br />'; // echo '<b>Cell annotation ',$note,'</b><br />';
// var_dump($noteDetails); // var_dump($noteDetails);
@ -4903,7 +4903,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader
private function _createFormulaFromTokens($tokens, $additionalData) private function _createFormulaFromTokens($tokens, $additionalData)
{ {
// empty formula? // empty formula?
if (count($tokens) == 0) { if (empty($tokens)) {
return ''; return '';
} }

View File

@ -354,7 +354,7 @@ class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader
$columnLetter = PHPExcel_Cell::stringFromColumnIndex($column-1); $columnLetter = PHPExcel_Cell::stringFromColumnIndex($column-1);
$objPHPExcel->getActiveSheet()->getStyle($columnLetter.$row)->applyFromArray($this->_formats[$formatStyle]); $objPHPExcel->getActiveSheet()->getStyle($columnLetter.$row)->applyFromArray($this->_formats[$formatStyle]);
} }
if ((count($styleData) > 0) && ($column > '') && ($row > '')) { if ((!empty($styleData)) && ($column > '') && ($row > '')) {
$columnLetter = PHPExcel_Cell::stringFromColumnIndex($column-1); $columnLetter = PHPExcel_Cell::stringFromColumnIndex($column-1);
$objPHPExcel->getActiveSheet()->getStyle($columnLetter.$row)->applyFromArray($styleData); $objPHPExcel->getActiveSheet()->getStyle($columnLetter.$row)->applyFromArray($styleData);
} }

View File

@ -214,7 +214,7 @@ class PHPExcel_ReferenceHelper
// Update worksheet: column dimensions // Update worksheet: column dimensions
$aColumnDimensions = array_reverse($pSheet->getColumnDimensions(), true); $aColumnDimensions = array_reverse($pSheet->getColumnDimensions(), true);
if (count($aColumnDimensions) > 0) { if (!empty($aColumnDimensions)) {
foreach ($aColumnDimensions as $objColumnDimension) { foreach ($aColumnDimensions as $objColumnDimension) {
$newReference = $this->updateCellReference($objColumnDimension->getColumnIndex() . '1', $pBefore, $pNumCols, $pNumRows); $newReference = $this->updateCellReference($objColumnDimension->getColumnIndex() . '1', $pBefore, $pNumCols, $pNumRows);
list($newReference) = PHPExcel_Cell::coordinateFromString($newReference); list($newReference) = PHPExcel_Cell::coordinateFromString($newReference);
@ -228,7 +228,7 @@ class PHPExcel_ReferenceHelper
// Update worksheet: row dimensions // Update worksheet: row dimensions
$aRowDimensions = array_reverse($pSheet->getRowDimensions(), true); $aRowDimensions = array_reverse($pSheet->getRowDimensions(), true);
if (count($aRowDimensions) > 0) { if (!empty($aRowDimensions)) {
foreach ($aRowDimensions as $objRowDimension) { foreach ($aRowDimensions as $objRowDimension) {
$newReference = $this->updateCellReference('A' . $objRowDimension->getRowIndex(), $pBefore, $pNumCols, $pNumRows); $newReference = $this->updateCellReference('A' . $objRowDimension->getRowIndex(), $pBefore, $pNumCols, $pNumRows);
list(, $newReference) = PHPExcel_Cell::coordinateFromString($newReference); list(, $newReference) = PHPExcel_Cell::coordinateFromString($newReference);
@ -340,7 +340,7 @@ class PHPExcel_ReferenceHelper
// Update workbook: named ranges // Update workbook: named ranges
if (count($pSheet->getParent()->getNamedRanges()) > 0) { if (!empty($pSheet->getParent()->getNamedRanges())) {
foreach ($pSheet->getParent()->getNamedRanges() as $namedRange) { foreach ($pSheet->getParent()->getNamedRanges() as $namedRange) {
if ($namedRange->getWorksheet()->getHashCode() == $pSheet->getHashCode()) { if ($namedRange->getWorksheet()->getHashCode() == $pSheet->getHashCode()) {
$namedRange->setRange( $namedRange->setRange(

View File

@ -202,7 +202,7 @@ class PHPExcel_Shared_OLE_PPS
*/ */
public static function _savePpsSetPnt(&$raList, $to_save, $depth = 0) public static function _savePpsSetPnt(&$raList, $to_save, $depth = 0)
{ {
if ( !is_array($to_save) || (count($to_save) == 0) ) { if ( !is_array($to_save) || (empty($to_save)) ) {
return 0xFFFFFFFF; return 0xFFFFFFFF;
} elseif( count($to_save) == 1 ) { } elseif( count($to_save) == 1 ) {
$cnt = count($raList); $cnt = count($raList);

View File

@ -288,7 +288,7 @@ class PHPExcel_Writer_Excel2007 implements PHPExcel_Writer_IWriter
} }
// Add comment relationship parts // Add comment relationship parts
if (count($this->_spreadSheet->getSheet($i)->getComments()) > 0) { if (!empty($this->_spreadSheet->getSheet($i)->getComments())) {
// VML Comments // VML Comments
$objZip->addFromString('xl/drawings/vmlDrawing' . ($i + 1) . '.vml', $this->getWriterPart('Comments')->writeVMLComments($this->_spreadSheet->getSheet($i))); $objZip->addFromString('xl/drawings/vmlDrawing' . ($i + 1) . '.vml', $this->getWriterPart('Comments')->writeVMLComments($this->_spreadSheet->getSheet($i)));
@ -297,7 +297,7 @@ class PHPExcel_Writer_Excel2007 implements PHPExcel_Writer_IWriter
} }
// Add header/footer relationship parts // Add header/footer relationship parts
if (count($this->_spreadSheet->getSheet($i)->getHeaderFooter()->getImages()) > 0) { if (!empty($this->_spreadSheet->getSheet($i)->getHeaderFooter()->getImages())) {
// VML Drawings // VML Drawings
$objZip->addFromString('xl/drawings/vmlDrawingHF' . ($i + 1) . '.vml', $this->getWriterPart('Drawing')->writeVMLHeaderFooterImages($this->_spreadSheet->getSheet($i))); $objZip->addFromString('xl/drawings/vmlDrawingHF' . ($i + 1) . '.vml', $this->getWriterPart('Drawing')->writeVMLHeaderFooterImages($this->_spreadSheet->getSheet($i)));

View File

@ -99,7 +99,7 @@ class PHPExcel_Writer_Excel2007_ContentTypes extends PHPExcel_Writer_Excel2007_W
); );
$customPropertyList = $pPHPExcel->getProperties()->getCustomProperties(); $customPropertyList = $pPHPExcel->getProperties()->getCustomProperties();
if (count($customPropertyList) > 0) { if (!empty($customPropertyList)) {
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, '/docProps/custom.xml', 'application/vnd.openxmlformats-officedocument.custom-properties+xml' $objWriter, '/docProps/custom.xml', 'application/vnd.openxmlformats-officedocument.custom-properties+xml'
); );
@ -129,7 +129,7 @@ class PHPExcel_Writer_Excel2007_ContentTypes extends PHPExcel_Writer_Excel2007_W
// Comments // Comments
for ($i = 0; $i < $sheetCount; ++$i) { for ($i = 0; $i < $sheetCount; ++$i) {
if (count($pPHPExcel->getSheet($i)->getComments()) > 0) { if (!empty($pPHPExcel->getSheet($i)->getComments())) {
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, '/xl/comments' . ($i + 1) . '.xml', 'application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml' $objWriter, '/xl/comments' . ($i + 1) . '.xml', 'application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml'
); );
@ -165,7 +165,7 @@ class PHPExcel_Writer_Excel2007_ContentTypes extends PHPExcel_Writer_Excel2007_W
$sheetCount = $pPHPExcel->getSheetCount(); $sheetCount = $pPHPExcel->getSheetCount();
for ($i = 0; $i < $sheetCount; ++$i) { for ($i = 0; $i < $sheetCount; ++$i) {
if (count($pPHPExcel->getSheet()->getHeaderFooter()->getImages()) > 0) { if (!empty($pPHPExcel->getSheet()->getHeaderFooter()->getImages())) {
foreach ($pPHPExcel->getSheet()->getHeaderFooter()->getImages() as $image) { foreach ($pPHPExcel->getSheet()->getHeaderFooter()->getImages() as $image) {
if (!isset( $aMediaContentTypes[strtolower($image->getExtension())]) ) { if (!isset( $aMediaContentTypes[strtolower($image->getExtension())]) ) {
$aMediaContentTypes[strtolower($image->getExtension())] = $this->_getImageMimeType( $image->getPath() ); $aMediaContentTypes[strtolower($image->getExtension())] = $this->_getImageMimeType( $image->getPath() );

View File

@ -209,7 +209,7 @@ class PHPExcel_Writer_Excel2007_DocProps extends PHPExcel_Writer_Excel2007_Write
public function writeDocPropsCustom(PHPExcel $pPHPExcel = null) public function writeDocPropsCustom(PHPExcel $pPHPExcel = null)
{ {
$customPropertyList = $pPHPExcel->getProperties()->getCustomProperties(); $customPropertyList = $pPHPExcel->getProperties()->getCustomProperties();
if (count($customPropertyList) == 0) { if (empty($customPropertyList)) {
return; return;
} }

View File

@ -60,7 +60,7 @@ class PHPExcel_Writer_Excel2007_Rels extends PHPExcel_Writer_Excel2007_WriterPar
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
$customPropertyList = $pPHPExcel->getProperties()->getCustomProperties(); $customPropertyList = $pPHPExcel->getProperties()->getCustomProperties();
if (count($customPropertyList) > 0) { if (!empty($customPropertyList)) {
// Relationship docProps/app.xml // Relationship docProps/app.xml
$this->_writeRelationship( $this->_writeRelationship(
$objWriter, $objWriter,
@ -223,7 +223,7 @@ class PHPExcel_Writer_Excel2007_Rels extends PHPExcel_Writer_Excel2007_WriterPar
// Write comments relationship? // Write comments relationship?
$i = 1; $i = 1;
if (count($pWorksheet->getComments()) > 0) { if (!empty($pWorksheet->getComments())) {
$this->_writeRelationship( $this->_writeRelationship(
$objWriter, $objWriter,
'_comments_vml' . $i, '_comments_vml' . $i,
@ -241,7 +241,7 @@ class PHPExcel_Writer_Excel2007_Rels extends PHPExcel_Writer_Excel2007_WriterPar
// Write header/footer relationship? // Write header/footer relationship?
$i = 1; $i = 1;
if (count($pWorksheet->getHeaderFooter()->getImages()) > 0) { if (!empty($pWorksheet->getHeaderFooter()->getImages())) {
$this->_writeRelationship( $this->_writeRelationship(
$objWriter, $objWriter,
'_headerfooter_vml' . $i, '_headerfooter_vml' . $i,

View File

@ -265,7 +265,7 @@ class PHPExcel_Writer_Excel2007_Workbook extends PHPExcel_Writer_Excel2007_Write
$objWriter->startElement('definedNames'); $objWriter->startElement('definedNames');
// Named ranges // Named ranges
if (count($pPHPExcel->getNamedRanges()) > 0) { if (!empty($pPHPExcel->getNamedRanges())) {
// Named ranges // Named ranges
$this->_writeNamedRanges($objWriter, $pPHPExcel); $this->_writeNamedRanges($objWriter, $pPHPExcel);
} }

View File

@ -342,7 +342,7 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ
private function _writeCols(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null) private function _writeCols(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
{ {
// cols // cols
if (count($pSheet->getColumnDimensions()) > 0) { if (!empty($pSheet->getColumnDimensions())) {
$objWriter->startElement('cols'); $objWriter->startElement('cols');
$pSheet->calculateColumnWidths(); $pSheet->calculateColumnWidths();
@ -521,7 +521,7 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ
$dataValidationCollection = $pSheet->getDataValidationCollection(); $dataValidationCollection = $pSheet->getDataValidationCollection();
// Write data validations? // Write data validations?
if (count($dataValidationCollection) > 0) { if (!empty($dataValidationCollection)) {
$objWriter->startElement('dataValidations'); $objWriter->startElement('dataValidations');
$objWriter->writeAttribute('count', count($dataValidationCollection)); $objWriter->writeAttribute('count', count($dataValidationCollection));
@ -590,7 +590,7 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ
$relationId = 1; $relationId = 1;
// Write hyperlinks? // Write hyperlinks?
if (count($hyperlinkCollection) > 0) { if (!empty($hyperlinkCollection)) {
$objWriter->startElement('hyperlinks'); $objWriter->startElement('hyperlinks');
foreach ($hyperlinkCollection as $coordinate => $hyperlink) { foreach ($hyperlinkCollection as $coordinate => $hyperlink) {
@ -624,7 +624,7 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ
*/ */
private function _writeProtectedRanges(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null) private function _writeProtectedRanges(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
{ {
if (count($pSheet->getProtectedCells()) > 0) { if (!empty($pSheet->getProtectedCells())) {
// protectedRanges // protectedRanges
$objWriter->startElement('protectedRanges'); $objWriter->startElement('protectedRanges');
@ -651,7 +651,7 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ
*/ */
private function _writeMergeCells(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null) private function _writeMergeCells(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
{ {
if (count($pSheet->getMergeCells()) > 0) { if (!empty($pSheet->getMergeCells())) {
// mergeCells // mergeCells
$objWriter->startElement('mergeCells'); $objWriter->startElement('mergeCells');
@ -811,7 +811,7 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ
} }
// rowBreaks // rowBreaks
if (count($aRowBreaks) > 0) { if (!empty($aRowBreaks)) {
$objWriter->startElement('rowBreaks'); $objWriter->startElement('rowBreaks');
$objWriter->writeAttribute('count', count($aRowBreaks)); $objWriter->writeAttribute('count', count($aRowBreaks));
$objWriter->writeAttribute('manualBreakCount', count($aRowBreaks)); $objWriter->writeAttribute('manualBreakCount', count($aRowBreaks));
@ -829,7 +829,7 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ
} }
// Second, write column breaks // Second, write column breaks
if (count($aColumnBreaks) > 0) { if (!empty($aColumnBreaks)) {
$objWriter->startElement('colBreaks'); $objWriter->startElement('colBreaks');
$objWriter->writeAttribute('count', count($aColumnBreaks)); $objWriter->writeAttribute('count', count($aColumnBreaks));
$objWriter->writeAttribute('manualBreakCount', count($aColumnBreaks)); $objWriter->writeAttribute('manualBreakCount', count($aColumnBreaks));
@ -1093,7 +1093,7 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ
private function _writeLegacyDrawing(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null) private function _writeLegacyDrawing(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
{ {
// If sheet contains comments, add the relationships // If sheet contains comments, add the relationships
if (count($pSheet->getComments()) > 0) { if (!empty($pSheet->getComments())) {
$objWriter->startElement('legacyDrawing'); $objWriter->startElement('legacyDrawing');
$objWriter->writeAttribute('r:id', 'rId_comments_vml1'); $objWriter->writeAttribute('r:id', 'rId_comments_vml1');
$objWriter->endElement(); $objWriter->endElement();
@ -1110,7 +1110,7 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ
private function _writeLegacyDrawingHF(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null) private function _writeLegacyDrawingHF(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
{ {
// If sheet contains comments, add the relationships // If sheet contains comments, add the relationships
if (count($pSheet->getHeaderFooter()->getImages()) > 0) { if (!empty($pSheet->getHeaderFooter()->getImages())) {
$objWriter->startElement('legacyDrawingHF'); $objWriter->startElement('legacyDrawingHF');
$objWriter->writeAttribute('r:id', 'rId_headerfooter_vml1'); $objWriter->writeAttribute('r:id', 'rId_headerfooter_vml1');
$objWriter->endElement(); $objWriter->endElement();

View File

@ -223,7 +223,7 @@ class PHPExcel_Writer_Excel5 implements PHPExcel_Writer_IWriter
$escher = null; $escher = null;
// check if there are any shapes for this sheet // check if there are any shapes for this sheet
if (count($sheet->getDrawingCollection()) == 0) { if (empty($sheet->getDrawingCollection())) {
continue; continue;
} }
@ -319,7 +319,7 @@ class PHPExcel_Writer_Excel5 implements PHPExcel_Writer_IWriter
// any drawings in this workbook? // any drawings in this workbook?
$found = false; $found = false;
foreach ($this->_phpExcel->getAllSheets() as $sheet) { foreach ($this->_phpExcel->getAllSheets() as $sheet) {
if (count($sheet->getDrawingCollection()) > 0) { if (!empty($sheet->getDrawingCollection())) {
$found = true; $found = true;
break; break;
} }
@ -348,7 +348,7 @@ class PHPExcel_Writer_Excel5 implements PHPExcel_Writer_IWriter
foreach ($this->_phpExcel->getAllsheets() as $sheet) { foreach ($this->_phpExcel->getAllsheets() as $sheet) {
$sheetCountShapes = 0; // count number of shapes (minus group shape), in sheet $sheetCountShapes = 0; // count number of shapes (minus group shape), in sheet
if (count($sheet->getDrawingCollection()) > 0) { if (!empty($sheet->getDrawingCollection())) {
++$countDrawings; ++$countDrawings;
foreach ($sheet->getDrawingCollection() as $drawing) { foreach ($sheet->getDrawingCollection() as $drawing) {

View File

@ -643,7 +643,7 @@ class PHPExcel_Writer_Excel5_Workbook extends PHPExcel_Writer_Excel5_BIFFwriter
$chunk = ''; $chunk = '';
// Named ranges // Named ranges
if (count($this->_phpExcel->getNamedRanges()) > 0) { if (!empty($this->_phpExcel->getNamedRanges())) {
// Loop named ranges // Loop named ranges
$namedRanges = $this->_phpExcel->getNamedRanges(); $namedRanges = $this->_phpExcel->getNamedRanges();
foreach ($namedRanges as $namedRange) { foreach ($namedRanges as $namedRange) {

View File

@ -2104,7 +2104,7 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
} }
//horizontal page breaks //horizontal page breaks
if (count($hbreaks) > 0) { if (!empty($hbreaks)) {
// Sort and filter array of page breaks // Sort and filter array of page breaks
sort($hbreaks, SORT_NUMERIC); sort($hbreaks, SORT_NUMERIC);
@ -2128,7 +2128,7 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
} }
// vertical page breaks // vertical page breaks
if (count($vbreaks) > 0) { if (!empty($vbreaks)) {
// 1000 vertical pagebreaks appears to be an internal Excel 5 limit. // 1000 vertical pagebreaks appears to be an internal Excel 5 limit.
// It is slightly higher in Excel 97/200, approx. 1026 // It is slightly higher in Excel 97/200, approx. 1026
@ -2691,7 +2691,7 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
$dataValidationCollection = $this->_phpSheet->getDataValidationCollection(); $dataValidationCollection = $this->_phpSheet->getDataValidationCollection();
// Write data validations? // Write data validations?
if (count($dataValidationCollection) > 0) { if (!empty($dataValidationCollection)) {
// DATAVALIDATIONS record // DATAVALIDATIONS record
$record = 0x01B2; // Record identifier $record = 0x01B2; // Record identifier