Reading merged cells in PHPExcel

Topics: User Forum
Nov 23, 2014 at 11:47 AM
I am trying to read a spreadsheet that contains merged cells. For instance the cells a1 through a5 are merged with b1 through b5. Ok I can work out that those cells are merged but on row 3 the cells a3 and a4 are merged with b3 and b4 but c3 through c5 are not merged. What I cant see how to do is to tell that the first two rows are not merged with a3,b3,a4 and b3 as they would all appear in the list of merged cells. Is there some way to determine the boundaries of a group of merged cells ?
Nov 23, 2014 at 2:33 PM
Edited Nov 23, 2014 at 2:35 PM
The worksheet object has a method called getMergeCells() that will return an array of all the merged cell blocks in that worksheet.... you can identify if a cell is part of a merge group by calling the cell objects isInRange() method against each of those merged cell entries in turn until a match is found, or you reach the end of the array without a valid match
Nov 24, 2014 at 9:54 AM
Mark, Thanks for the reply. I was aware of getMergeCells and isInRange but they do not seem to address the issue I was wrestling with. In the spreadsheet I am reading there are several rows with merged cells. To simplify things lets consider just the a column. The cells a1, a2, a3, a4 are all merged but a1 and a2 are merged with each other and have one content and a3 and a4 are also merged together and have a different content. The getMergedCells function will return a list containing a1,a2,a3,a4 as they are all merged but what it doesn't tell me is that the a1 and a2 are not merged with a3 and a4.