读取合并的单元格PhPExcel(Read merged cells PhPExcel)

编程入门 行业动态 更新时间:2024-10-28 08:24:34
读取合并的单元格PhPExcel(Read merged cells PhPExcel)

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

最满意答案

我不明白你在这里要做什么,因为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

更多推荐

本文发布于:2023-04-28 03:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329859.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单元格   PhPExcel   Read   merged   cells

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!