What does the `index` parameter mean in the Apache POI` getMergedRegion` sheet?

What does index mean in getMergedRegion ?

Apache The HSSFSheet documentation does not explicitly describe what the index parameter means.

+6
source share
2 answers

From a freely available source, downloaded here http://poi.apache.org/download.html , we have ...

 /** * @return the merged region at the specified index */ public CellRangeAddress getMergedRegion(int index) { return _sheet.getMergedRegionAt(index); } 

When we go to getMergedRegionAt , we find

 public CellRangeAddress getMergedRegionAt(int index) { //safety checks MergedCellsTable mrt = getMergedRecords(); if (index >= mrt.getNumberOfMergedRegions()) { return null; } return mrt.get(index); } 

Here we see that there is a MergedCellsTable , this indicates that each worksheet has a data structure that maintains a list of merged cells in the worksheet.

When viewing the code, the index refers to a specific MergedRegion , whose CellRangeAddress is required in the context of the presence of many regions.

You can write this as a document error or send a patch to improve JavaDoc.

+2
source

To answer this question, we first define a MergedRegion .

A MergedRegion is essentially a group of cells grouped together that can act as a single cell. This is created using CellAdress , which can span a number or rows or columns.

A HSSFSheet may contain a series of these MergedRegions specified by getNumMergedRegions .

The index refers to a MergedRegion in an HSSFSheet object in a Sheet that supports a MergedCellsTable , which is essentially an ArrayList .

+2
source

All Articles