aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java6
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java7
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java7
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 {