Nasreddin
Nasreddin

Reputation: 1647

How to find out the cells that are aligned under a merged cell in excel

I am writing Java code to parse a complex excel using POI library. Part of the spreadsheet looks like this

enter image description here

My understanding is POI does not know the relationship between cells from different rows, i.e. how the cells are aligned in one column. For example in the picture, how do I ask the code to tell there are three cells are in the same column as CD3 while only two cells are under CD4? The number of CD's are not fixed, nor is the number of Density columns under each CD. So there is no way to parse the data by coordinate of the cell.

Upvotes: 0

Views: 98

Answers (1)

andrewdleach
andrewdleach

Reputation: 2466

It is possible to iterate over the number of Merged Regions and then parse as desired. Something like this:

for (int i = 0; i < sheet.getNumberMergedRegions; i++) {
    CellRangeAddress mergedRegion = sheet.getMergedRegion(i);
    //do something with the mergedRegion
}

Upvotes: 1

Related Questions