aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2015-01-02 20:03:28 +0000
committerDominik Stadler <centic@apache.org>2015-01-02 20:03:28 +0000
commit906a9177963862ec7cf5de8eb91105426c5de0e8 (patch)
tree1841253540cc762de7d783f82977cf0d48d7fc65
parent2b83ab670ade75ca3911493fd7d547f7c224cd43 (diff)
downloadpoi-906a9177963862ec7cf5de8eb91105426c5de0e8.tar.gz
poi-906a9177963862ec7cf5de8eb91105426c5de0e8.zip
Bug 46192: Add methods to query outline level for HSSF and XSSF
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1649107 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/java/org/apache/poi/hssf/model/InternalSheet.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java8
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFRow.java3
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java11
-rw-r--r--src/java/org/apache/poi/ss/usermodel/Row.java7
-rw-r--r--src/java/org/apache/poi/ss/usermodel/Sheet.java8
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java2
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java4
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java4
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java8
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/streaming/TestOutlining.java68
11 files changed, 119 insertions, 8 deletions
diff --git a/src/java/org/apache/poi/hssf/model/InternalSheet.java b/src/java/org/apache/poi/hssf/model/InternalSheet.java
index 183ca2c418..9f0701e160 100644
--- a/src/java/org/apache/poi/hssf/model/InternalSheet.java
+++ b/src/java/org/apache/poi/hssf/model/InternalSheet.java
@@ -1667,4 +1667,8 @@ public final class InternalSheet {
temp.toArray(result);
return result;
}
+
+ public int getColumnOutlineLevel(int columnIndex) {
+ return _columnInfos.getOutlineLevel(columnIndex);
+ }
}
diff --git a/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java b/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java
index 6aed70faa1..a66c0005ed 100644
--- a/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java
+++ b/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java
@@ -520,4 +520,12 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate {
}
return result;
}
+ public int getOutlineLevel(int columnIndex) {
+ ColumnInfoRecord ci = findColumnInfo(columnIndex);
+ if (ci != null) {
+ return ci.getOutlineLevel();
+ } else {
+ return 0;
+ }
+ }
}
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java b/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
index 1ef2acfc74..67315f12af 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
@@ -268,9 +268,8 @@ public final class HSSFRow implements Row {
* Returns the rows outline level. Increased as you
* put it into more groups (outlines), reduced as
* you take it out of them.
- * TODO - Should this really be public?
*/
- protected int getOutlineLevel() {
+ public int getOutlineLevel() {
return row.getOutlineLevel();
}
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
index e7ed838ecc..8458152fed 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
@@ -2340,6 +2340,13 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
}
return _workbook.getNameRecord(recIndex);
}
-
-
+
+ /**
+ * Returns the column outline level. Increased as you
+ * put it into more groups (outlines), reduced as
+ * you take it out of them.
+ */
+ public int getColumnOutlineLevel(int columnIndex) {
+ return _sheet.getColumnOutlineLevel(columnIndex);
+ }
}
diff --git a/src/java/org/apache/poi/ss/usermodel/Row.java b/src/java/org/apache/poi/ss/usermodel/Row.java
index 08fb4254df..db9fb3e4fc 100644
--- a/src/java/org/apache/poi/ss/usermodel/Row.java
+++ b/src/java/org/apache/poi/ss/usermodel/Row.java
@@ -234,4 +234,11 @@ public interface Row extends Iterable<Cell> {
public static final MissingCellPolicy RETURN_BLANK_AS_NULL = new MissingCellPolicy();
/** A new, blank cell is created for missing cells. Blank cells are returned as normal */
public static final MissingCellPolicy CREATE_NULL_AS_BLANK = new MissingCellPolicy();
+
+ /**
+ * Returns the rows outline level. Increased as you
+ * put it into more groups (outlines), reduced as
+ * you take it out of them.
+ */
+ public int getOutlineLevel();
}
diff --git a/src/java/org/apache/poi/ss/usermodel/Sheet.java b/src/java/org/apache/poi/ss/usermodel/Sheet.java
index d1bd67416a..987a35efeb 100644
--- a/src/java/org/apache/poi/ss/usermodel/Sheet.java
+++ b/src/java/org/apache/poi/ss/usermodel/Sheet.java
@@ -1053,5 +1053,11 @@ public interface Sheet extends Iterable<Row> {
* columns for the Sheet, or null.
*/
void setRepeatingColumns(CellRangeAddress columnRangeRef);
-
+
+ /**
+ * Returns the column outline level. Increased as you
+ * put it into more groups (outlines), reduced as
+ * you take it out of them.
+ */
+ int getColumnOutlineLevel(int columnIndex);
}
diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java
index 9ace1475a4..cdba00e68a 100644
--- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java
+++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java
@@ -58,7 +58,7 @@ public class SXSSFRow implements Row
return _height!=-1;
}
- int getOutlineLevel(){
+ public int getOutlineLevel(){
return _outlineLevel;
}
void setOutlineLevel(int level){
diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
index 2700e16785..49817e5eab 100644
--- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
+++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
@@ -1477,4 +1477,8 @@ public class SXSSFSheet implements Sheet, Cloneable
boolean dispose() {
return _writer.dispose();
}
+
+ public int getColumnOutlineLevel(int columnIndex) {
+ return _sh.getColumnOutlineLevel(columnIndex);
+ }
}
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java
index 46aa352566..197228d5aa 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java
@@ -513,4 +513,8 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
}
setRowNum(rownum);
}
+
+ public int getOutlineLevel() {
+ return _row.getOutlineLevel();
+ }
}
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 552a091585..2c49ed2595 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
@@ -3821,4 +3821,12 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
}
return tables;
}
+
+ public int getColumnOutlineLevel(int columnIndex) {
+ CTCol col = columnHelper.getColumn(columnIndex, false);
+ if (col == null) {
+ return 0;
+ }
+ return col.getOutlineLevel();
+ }
}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestOutlining.java b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestOutlining.java
index e616402af4..e207347df7 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestOutlining.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestOutlining.java
@@ -19,11 +19,18 @@
package org.apache.poi.xssf.streaming;
+import java.io.IOException;
+
import junit.framework.TestCase;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
public final class TestOutlining extends TestCase {
public void testSetRowGroupCollapsed() throws Exception {
-
SXSSFWorkbook wb2 = new SXSSFWorkbook(100);
wb2.setCompressTempFiles(true);
SXSSFSheet sheet2 = (SXSSFSheet) wb2.createSheet("new sheet");
@@ -45,10 +52,11 @@ public final class TestOutlining extends TestCase {
r = (SXSSFRow) sheet2.getRow(12);
assertNull(r.getHidden());
wb2.dispose();
+
+ wb2.close();
}
public void testSetRowGroupCollapsedError() throws Exception {
-
SXSSFWorkbook wb2 = new SXSSFWorkbook(100);
wb2.setCompressTempFiles(true);
SXSSFSheet sheet2 = (SXSSFSheet) wb2.createSheet("new sheet");
@@ -98,5 +106,61 @@ public final class TestOutlining extends TestCase {
r = (SXSSFRow) sheet2.getRow(12);
assertNull(r.getHidden());
wb2.dispose();
+
+ wb2.close();
}
+
+ public void testOutlineGetters() throws IOException {
+ HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
+ HSSFSheet hssfSheet = hssfWorkbook.createSheet();
+ hssfSheet.createRow(0);
+ hssfSheet.createRow(1);
+ hssfSheet.createRow(2);
+ hssfSheet.createRow(3);
+ hssfSheet.createRow(4);
+ hssfSheet.groupRow(1, 3);
+ hssfSheet.groupRow(2, 3);
+
+ assertEquals(0, hssfSheet.getRow(0).getOutlineLevel());
+ assertEquals(1, hssfSheet.getRow(1).getOutlineLevel());
+ assertEquals(2, hssfSheet.getRow(2).getOutlineLevel());
+ assertEquals(2, hssfSheet.getRow(3).getOutlineLevel());
+ assertEquals(0, hssfSheet.getRow(4).getOutlineLevel());
+ hssfWorkbook.close();
+
+ XSSFWorkbook xssfWorkbook = new XSSFWorkbook();
+ XSSFSheet xssfSheet = xssfWorkbook.createSheet();
+ xssfSheet.createRow(0);
+ xssfSheet.createRow(1);
+ xssfSheet.createRow(2);
+ xssfSheet.createRow(3);
+ xssfSheet.createRow(4);
+ xssfSheet.groupRow(1, 3);
+ xssfSheet.groupRow(2, 3);
+
+ assertEquals(0, xssfSheet.getRow(0).getOutlineLevel());
+ assertEquals(1, xssfSheet.getRow(1).getOutlineLevel());
+ assertEquals(2, xssfSheet.getRow(2).getOutlineLevel());
+ assertEquals(2, xssfSheet.getRow(3).getOutlineLevel());
+ assertEquals(0, xssfSheet.getRow(4).getOutlineLevel());
+ xssfWorkbook.close();
+
+ SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook();
+ Sheet sxssfSheet = sxssfWorkbook.createSheet();
+ sxssfSheet.createRow(0);
+ sxssfSheet.createRow(1);
+ sxssfSheet.createRow(2);
+ sxssfSheet.createRow(3);
+ sxssfSheet.createRow(4);
+ sxssfSheet.groupRow(1, 3);
+ sxssfSheet.groupRow(2, 3);
+
+ assertEquals(0, sxssfSheet.getRow(0).getOutlineLevel());
+ assertEquals(1, sxssfSheet.getRow(1).getOutlineLevel());
+ assertEquals(2, sxssfSheet.getRow(2).getOutlineLevel());
+ assertEquals(2, sxssfSheet.getRow(3).getOutlineLevel());
+ assertEquals(0, sxssfSheet.getRow(4).getOutlineLevel());
+ sxssfWorkbook.dispose();
+ sxssfWorkbook.close();
+ }
}