I'm using Aspose Cells for Java.
I'm operating on an Excel spreadsheet. I'd like to iterate over every cell, and if two cells are touching and share the same style ID, combine them into a separate single range for later processing. As more cells are iterated over, existing ranges could grow.
A range consists of startRow
, endRow
, startCol
, and endCol
properties. If all four properties are equal, it represents a single cell.
For example, I'd expect {(1,1),(1,1)}
and {(2,2),(1,1)}
to combine into {(1,2),(1,1)}
. Meanwhile {(1,1),(1,1)}
and {(2,2),(2,2)}
would not combine because they are diagonal, not adjacent.
I think I could use a variation of an interval tree for this, but I'd have to adapt it for 2D intervals. However, in this case I don't care if two ranges overlap; if two ranges overlap, they are overlapping rectangles, in which case combining them would do nothing for minimizing the number of total ranges.
Here is a crudely drawn idea of the intput/output I expect.
My best guess is that I'd have to iterate outward from every cell and compare the style IDs. As I go over and down from the current cell, check the rest of the cells in that range for the same ID and create new ranges based on that.
Thoughts?