diff options
author | David North <dnorth@apache.org> | 2015-09-23 12:53:13 +0000 |
---|---|---|
committer | David North <dnorth@apache.org> | 2015-09-23 12:53:13 +0000 |
commit | 11f188778460fa0d051134d667bed26da2eba8c1 (patch) | |
tree | b4fd2af0cb0fa02c5a85272895585d46b004d5a3 /src | |
parent | 303cf2a8ed40040e2668ca71416448a09358424b (diff) | |
download | poi-11f188778460fa0d051134d667bed26da2eba8c1.tar.gz poi-11f188778460fa0d051134d667bed26da2eba8c1.zip |
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
Diffstat (limited to 'src')
3 files changed, 16 insertions, 4 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java index 4156433bd4..728fedf86a 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -1090,7 +1090,6 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { * this each time. * * @return the merged region at the specified index - * @throws IllegalStateException if this worksheet does not contain merged regions */ @Override public CellRangeAddress getMergedRegion(int index) { @@ -1107,15 +1106,14 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { * faster than calling {@link #getMergedRegion(int)} each time. * * @return the list of merged regions - * @throws IllegalStateException if this worksheet does not contain merged regions */ @SuppressWarnings("deprecation") @Override public List<CellRangeAddress> getMergedRegions() { + List<CellRangeAddress> addresses = new ArrayList<CellRangeAddress>(); CTMergeCells ctMergeCells = worksheet.getMergeCells(); - if(ctMergeCells == null) throw new IllegalStateException("This worksheet does not contain merged regions"); + if(ctMergeCells == null) return addresses; - List<CellRangeAddress> addresses = new ArrayList<CellRangeAddress>(); for(CTMergeCell ctMergeCell : ctMergeCells.getMergeCellArray()) { String ref = ctMergeCell.getRef(); addresses.add(CellRangeAddress.valueOf(ref)); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java index 8e77b2c499..aed4465620 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java @@ -1382,4 +1382,11 @@ public final class TestXSSFSheet extends BaseTestSheet { XSSFSheet sheet = wb.createSheet(); assertNotNull(sheet.createComment()); } + + @Test + public void testNoMergedRegionsIsEmptyList() { + XSSFWorkbook wb = new XSSFWorkbook(); + XSSFSheet sheet = wb.createSheet(); + assertTrue(sheet.getMergedRegions().isEmpty()); + } }
\ No newline at end of file diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java index 4b7d8491be..723bf0d3e9 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java @@ -657,6 +657,13 @@ public final class TestHSSFSheet extends BaseTestSheet { assertTrue(sheet3.getColumnWidth(0) >= minWithRow1And2); assertTrue(sheet3.getColumnWidth(0) <= maxWithRow1And2); } + + @Test + public void testNoMergedRegionsIsEmptyList() { + HSSFWorkbook wb = new HSSFWorkbook(); + HSSFSheet s = wb.createSheet("Sheet1"); + assertTrue(s.getMergedRegions().isEmpty()); + } @Test public void autoSizeDate() throws Exception { |