简体   繁体   English

读取合并的单元格PhPExcel

[英]Read merged cells PhPExcel

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 ) 我正在尝试在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

always dumps null. 总是转储null。

I've tried $cell->getColumn()== 'A' since that the cell starts at A, but dumps null as well. 我试过$cell->getColumn()== 'A'因为单元格从A开始,但也转储为null。

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' 我不明白你在这里要做什么,因为getColumn()只会返回一个像AB这样A列地址,而不会像'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 将返回布尔值true / false,指示该单元格是否是合并范围的一部分

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 可用于测试合并范围内的单元格是否是该范围的左上角(主要)单元格,并将返回布尔值true / false,指示它是否包含该范围的实际数据值/类型等...请注意,如果单元格不是任何合并范围的一部分,它将返回false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM