Prev Link |
ExcelExplorer Manual |
Next EEData class |
 |
(ExcelExplorer 4.0)
Returns merged cells area.
false EEArea Merged( [boolean $exclude_hidden = false] )
Parameters
- boolean $exclude_hidden
- If hidden columns and rows don't need to be included in the merged cells area set this to TRUE.
Description
This method returns merged cells area (EEArea object) this cell belongs to.
This method can returns FALSE in these cases:
- Cell is not within merged area;
- Whole merged area is hidden and this method called with exclude_hidden = true for any cell within it.
Therefore you should always check returned value for valid object before using its methods.
The optional exclude_hidden parameter used for returning only visible merged area.
 |
A |
B |
C |
D |
E |
| 1 |
|
|
|
|
|
| 2 |
|
merged cells |
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
|
|
|
|
|
 |
A |
B |
D |
E |
| 1 |
|
|
|
|
| 3 |
|
merged cells |
|
| 4 |
|
|
| 5 |
|
|
|
|
|
Fig. 1 |
|
Fig. 2 |
On the first figure sheet contains merged cells area [B2:D4].
On the second one the same sheet and merged cells but with column C and row 2 are hidden.
Note that text "merged cells" stored in the B2 cell only; all other cells is not contains any data and have types EMPTY or BLANK for cells outside merged area and MERGED for cells within it.
Method returns (called for any cell within [B2:D4] area):
- Fig. 1 - returns [B2:D4] area with width and height 3.
The optional parameter exclude_hidden has no effect.
- Fig. 2, exclude_hidden = false - hidden rows and columns are taking into account and returned area will be [B2:D4] with width and height 3.
- Fig. 2, exclude_hidden = true - hidden rows and columns are NOT taking into account and returned area will be [B3:D4] with width and height 2.
Note that in this case merged area started from row 3 - [B3:D4] (see available methods of EEArea like FirstColumn() to obtain area first and last rows and columns of the area).
Width and height values will equals to 2 instead of 3.
- If whole merged area is hidden and this method called with exclude_hidden = true - this method returns FALSE.
1. Print cell types from the defined area in the worksheet from Fig. 2 above with exclude_hidden = false
<?php
$area = $ee->Worksheet(0)->DefinedArea();
if( $area !== false ) {
for( $col = $area->FirstColumn(); $col <= $area->LastColumn(); $col++ ) {
for( $row = $area->FirstRow(); $row <= $area->LastRow(); $row++ ) {
echo 'Cell in column '.$col.', row '.$row.' have type: ';
$cell_type = $ee->Cell(0,$col,$row)->Type();
switch( $cell_type ) {
case EE_CELL_EMPTY:
echo 'EE_CELL_EMPTY'; break;
case EE_CELL_BLANK:
echo 'EE_CELL_BLANK'; break;
case EE_CELL_NUMBER:
echo 'EE_CELL_NUMBER'; break;
case EE_CELL_TEXT:
echo 'EE_CELL_TEXT'; break;
case EE_CELL_LOGICAL:
echo 'EE_CELL_LOGICAL'; break;
case EE_CELL_ERROR:
echo 'EE_CELL_ERROR'; break;
case EE_CELL_MERGED:
echo 'EE_CELL_MERGED'; break;
default:
echo 'UNKNOWN'; break;
}
if( ($cell_type != EE_CELL_EMPTY) && ($cell_type != EE_CELL_BLANK) && ($cell_type != EE_CELL_MERGED) ) {
echo ', value: ';
var_export($ee->Cell(0,$col,$row)->Data()->Plain());
}
$marea = $ee->Cell(0,$col,$row)->Merged();
if( $marea !== false ) {
echo '; merged area: [';
// print column letter
echo chr(65+$marea->FirstColumn());
// print row number starting from 1
echo ($marea->FirstRow()+1);
echo ':';
// print column letter
echo chr(65+$marea->LastColumn());
// print row number starting from 1
echo ($marea->LastRow()+1);
echo '] with width='.$marea->Width().' and height='.$marea->Height();
}
echo "\n";
}
}
}
?>
Will output: Cell in column 1, row 1 have type: EE_CELL_TEXT, value: 'merged cells'; merged area: [B2:D4] with width=3 and height=3
Cell in column 1, row 2 have type: EE_CELL_MERGED; merged area: [B2:D4] with width=3 and height=3
Cell in column 1, row 3 have type: EE_CELL_MERGED; merged area: [B2:D4] with width=3 and height=3
Cell in column 2, row 1 have type: EE_CELL_MERGED; merged area: [B2:D4] with width=3 and height=3
Cell in column 2, row 2 have type: EE_CELL_MERGED; merged area: [B2:D4] with width=3 and height=3
Cell in column 2, row 3 have type: EE_CELL_MERGED; merged area: [B2:D4] with width=3 and height=3
Cell in column 3, row 1 have type: EE_CELL_MERGED; merged area: [B2:D4] with width=3 and height=3
Cell in column 3, row 2 have type: EE_CELL_MERGED; merged area: [B2:D4] with width=3 and height=3
Cell in column 3, row 3 have type: EE_CELL_MERGED; merged area: [B2:D4] with width=3 and height=3
2. Print cell types from the defined area in the worksheet from Fig. 2 above with exclude_hidden = true
<?php
// ...
// The same code as for previous example except this line:
$marea = $ee->Cell(0,$col,$row)->Merged(true);
// ...
?>
Will output: Cell in column 1, row 1 have type: EE_CELL_TEXT, value: 'merged cells'; merged area: [B3:D4] with width=2 and height=2
Cell in column 1, row 2 have type: EE_CELL_MERGED; merged area: [B3:D4] with width=2 and height=2
Cell in column 1, row 3 have type: EE_CELL_MERGED; merged area: [B3:D4] with width=2 and height=2
Cell in column 2, row 1 have type: EE_CELL_MERGED; merged area: [B3:D4] with width=2 and height=2
Cell in column 2, row 2 have type: EE_CELL_MERGED; merged area: [B3:D4] with width=2 and height=2
Cell in column 2, row 3 have type: EE_CELL_MERGED; merged area: [B3:D4] with width=2 and height=2
Cell in column 3, row 1 have type: EE_CELL_MERGED; merged area: [B3:D4] with width=2 and height=2
Cell in column 3, row 2 have type: EE_CELL_MERGED; merged area: [B3:D4] with width=2 and height=2
Cell in column 3, row 3 have type: EE_CELL_MERGED; merged area: [B3:D4] with width=2 and height=2
|