Make XSSF and HSSF consistent in getMergedRegions - return empty list if there are none, rather than an exception. Tests for this.
https://bz.apache.org/bugzilla/show_bug.cgi?id=58350 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1704839 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5e6b975b1c
commit
c93ded0f36
@ -1090,7 +1090,6 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
* this each time.
|
* this each time.
|
||||||
*
|
*
|
||||||
* @return the merged region at the specified index
|
* @return the merged region at the specified index
|
||||||
* @throws IllegalStateException if this worksheet does not contain merged regions
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public CellRangeAddress getMergedRegion(int index) {
|
public CellRangeAddress getMergedRegion(int index) {
|
||||||
@ -1107,15 +1106,14 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
* faster than calling {@link #getMergedRegion(int)} each time.
|
* faster than calling {@link #getMergedRegion(int)} each time.
|
||||||
*
|
*
|
||||||
* @return the list of merged regions
|
* @return the list of merged regions
|
||||||
* @throws IllegalStateException if this worksheet does not contain merged regions
|
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public List<CellRangeAddress> getMergedRegions() {
|
public List<CellRangeAddress> getMergedRegions() {
|
||||||
CTMergeCells ctMergeCells = worksheet.getMergeCells();
|
|
||||||
if(ctMergeCells == null) throw new IllegalStateException("This worksheet does not contain merged regions");
|
|
||||||
|
|
||||||
List<CellRangeAddress> addresses = new ArrayList<CellRangeAddress>();
|
List<CellRangeAddress> addresses = new ArrayList<CellRangeAddress>();
|
||||||
|
CTMergeCells ctMergeCells = worksheet.getMergeCells();
|
||||||
|
if(ctMergeCells == null) return addresses;
|
||||||
|
|
||||||
for(CTMergeCell ctMergeCell : ctMergeCells.getMergeCellArray()) {
|
for(CTMergeCell ctMergeCell : ctMergeCells.getMergeCellArray()) {
|
||||||
String ref = ctMergeCell.getRef();
|
String ref = ctMergeCell.getRef();
|
||||||
addresses.add(CellRangeAddress.valueOf(ref));
|
addresses.add(CellRangeAddress.valueOf(ref));
|
||||||
|
@ -1382,4 +1382,11 @@ public final class TestXSSFSheet extends BaseTestSheet {
|
|||||||
XSSFSheet sheet = wb.createSheet();
|
XSSFSheet sheet = wb.createSheet();
|
||||||
assertNotNull(sheet.createComment());
|
assertNotNull(sheet.createComment());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNoMergedRegionsIsEmptyList() {
|
||||||
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
|
XSSFSheet sheet = wb.createSheet();
|
||||||
|
assertTrue(sheet.getMergedRegions().isEmpty());
|
||||||
|
}
|
||||||
}
|
}
|
@ -658,6 +658,13 @@ public final class TestHSSFSheet extends BaseTestSheet {
|
|||||||
assertTrue(sheet3.getColumnWidth(0) <= maxWithRow1And2);
|
assertTrue(sheet3.getColumnWidth(0) <= maxWithRow1And2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNoMergedRegionsIsEmptyList() {
|
||||||
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
|
HSSFSheet s = wb.createSheet("Sheet1");
|
||||||
|
assertTrue(s.getMergedRegions().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void autoSizeDate() throws Exception {
|
public void autoSizeDate() throws Exception {
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
|
Loading…
Reference in New Issue
Block a user