我正在尝试在phpexcel中读取一个合并的单元格,我的问题是该单元格合并在A:B:C:D:E:F(不能与他们想要的东西争论)
$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总是转储null。
我试过$cell->getColumn()== 'A'因为单元格从A开始,但也转储为null。
我将不胜感激任何帮助。
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 codealways 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.
最满意答案
我不明白你在这里要做什么,因为getColumn()只返回一个像A或B这样A列地址,而且从来没有像'A:B:C:D:E:F'
使用迭代现有单元格可能是明智的
$cellIterator->setIterateOnlyExistingCells(true);但是有一些函数可以帮助你合并单元格:
$cell->isInMergeRange()将返回布尔值true / false,指示该单元格是否是合并范围的一部分
和
$cell->isMergeRangeValueCell()可用于测试合并范围内的单元格是否是该范围的左上角(主要)单元格,并将返回布尔值true / false,指示它是否包含该范围的实际数据值/类型等...请注意,如果单元格不属于任何合并范围,则返回false
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
更多推荐
发布评论