Replies: 7 comments 5 replies
-
How to identify if a cell spans vertically across several rows.... that means that it's a merge cell. The Cell methods To read cell styling information, you want to use the Cell's |
Beta Was this translation helpful? Give feedback.
-
Thanks. I've tried to check the mentioned (and others) range functions in a merged cell, but they all return false or none. What can be wrong? |
Beta Was this translation helpful? Give feedback.
-
I don't know if it's the fact that you're trying to use two different variables ( If I simplify your code to foreach ($worksheet->getRowIterator(367, 485) as $row) {
$cellIterator = $row->getCellIterator('A', 'N');
$cellIterator->setIterateOnlyExistingCells(false);
// Search the right column
foreach ($cellIterator as $cell) {
var_dump("Cell {$cell->getCoordinate()}; Is in Merge Range: ". ($cell->isInMergeRange()?"true":"F"). ", Is top-left cell in merge range: ". ($cell->isMergeRangeValueCell()?"true":"F"));
}
} then that identifies every cell that is in a merge range, and whether it is the top-left cell of that merge range (containing the actual value) correctly |
Beta Was this translation helpful? Give feedback.
-
Ok. First, I forgot to show readValue():
It's just a shsortcut (for me) to get the value of a cell. Then, the issue is to check using an "if", not dumping the value, so the need to debug via dump rises when the expected results don't happen. But I realize that there was a bug in the logic, so I don't need to iterate on all cells, but non-empty ones. Now, the piece of code where the logic has changed (taking the very next non-empty cell as the relevant column and assign to $colTitle):
The dump before (before being commented) always shows "F". |
Beta Was this translation helpful? Give feedback.
-
I have to say that I've done a workaround instead of using the isInMergeRange() function. Should I file a bug about it? |
Beta Was this translation helpful? Give feedback.
-
foreach ($worksheet->getRowIterator(367, 485) as $row) {
$cellIterator = $row->getCellIterator('A', 'N');
$cellIterator->setIterateOnlyExistingCells(false);
$rowIndex = $row->getRowIndex();
$end = false;
if (!empty($worksheet->getCell('A'. $rowIndex)->getValue())) {
if ($worksheet->getCell('A'. $rowIndex)->getValue() == 'Leyenda') {
$end = true;
break;
}
}
// Search the right column
$cellA = $worksheet->getCell('A'.$rowIndex);
var_dump("Cell {$cellA->getCoordinate()}; Is in Merge Range: ". ($cellA->isInMergeRange()?"true":"F"). ", Is top-left cell in merge range: ". ($cellA->isMergeRangeValueCell()?"true":"F"));
if ($cellA->isInMergeRange()) {
var_dump("Cell A{$rowIndex} is in merge range");
foreach ($cellIterator as $cell) {
if ($cell->isInMergeRange()) {
$colTitle = $cell->getColumn();
break;
}
}
}
} returns
which is exactly what I expect to see from your sample worksheet. In your case, you're getting a false value from dump("Cell {$cellA->getCoordinate()}; Is in Merge Range: ". ($cellA->isInMergeRange()?"true":"F"). ", Is top-left cell in merge range: ". ($cellA->isMergeRangeValueCell()?"true":"F")); then of course the code won't enter the |
Beta Was this translation helpful? Give feedback.
-
Thanks for your time and effort. |
Beta Was this translation helpful? Give feedback.
-
Hi. I'm in an scenario where I need to "just" read several hundreds of large, caothic and excel spreadsheets (I mean, editing is not an option), extract some repeating data according to some criteria and return something. I've already identified and solved many criteria, but I miss a way to manage other issues I'm not sure how to get to them. I've taken a look at the samples and haven't been able to find what I need. So, I need help about how to check some features (no charts, text only). These are:
At this moment, I think that if I get the way to handle these issue, I'll get at least most of the missing data. I hope that is enough.
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions