I'm trying to read a merged cell in phpexcel, my problem is that the cell is merged on A:B:C:D:E:F ( can't argue with what they want )
$i= 0;
foreach ($worksheet->getRowIterator() as $row) {
if ($i > 10) break ;
$i ++;
$cellIterator = $row->getCellIterator();
foreach ($cellIterator as $cell) {
if($cell->getColumn()== 'A:B:C:D:E:F'){
$specification=$cell->getCalculatedValue();
var_dump($specification);die();
// some other code
always dumps null.
I've tried $cell->getColumn()== 'A'
since that the cell starts at A, but dumps null as well.
I would appreciate any help.
I don't understand exactly what you're trying to do here, because getColumn()
will only ever return a single column address like A
or B
and never anything like 'A:B:C:D:E:F'
It may be sensible to iterate only existing cells using
$cellIterator->setIterateOnlyExistingCells(true);
but there's a couple of functions that may help you with merged cells:
$cell->isInMergeRange()
will return a Boolean true/false, indicating if the cell is part of a merge range
and
$cell->isMergeRangeValueCell()
can be used to test whether a cell within a merge range is the top-left (primary) cell of that range, and will return a Boolean true/false indicating whether it holds the actual data value/type etc for that range... Note that it will return a false if the cell isn't part of any merge range
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With