summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Micich <josh@apache.org>2009-02-13 21:46:44 +0000
committerJosh Micich <josh@apache.org>2009-02-13 21:46:44 +0000
commitf9e37846711ae4fe0d99bd4a77686609f66b1460 (patch)
tree4a5b887996e73786c4dd556ced8f6aaf3b430f31
parent475cd9bd7095952cf182b35a1c4b76877d9c54b7 (diff)
downloadpoi-f9e37846711ae4fe0d99bd4a77686609f66b1460.tar.gz
poi-f9e37846711ae4fe0d99bd4a77686609f66b1460.zip
Bugzilla 46660 - added 'hidden' property to Workbook
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@744253 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/documentation/content/xdocs/changes.xml1
-rw-r--r--src/documentation/content/xdocs/status.xml1
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java70
-rw-r--r--src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java15
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java52
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java28
6 files changed, 73 insertions, 94 deletions
diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml
index 793448a3c7..8728066237 100644
--- a/src/documentation/content/xdocs/changes.xml
+++ b/src/documentation/content/xdocs/changes.xml
@@ -37,6 +37,7 @@
<!-- Don't forget to update status.xml too! -->
<release version="3.5-beta6" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="add">46660 - added Workbook getHidden() and setHidden(boolean)</action>
<action dev="POI-DEVELOPERS" type="fix">46693 - Fixed bugs serialization bugs in records: CHARTFORMAT, SHTPROPS, SXVD and SXVDEX</action>
<action dev="POI-DEVELOPERS" type="fix">46627 - Fixed offset of added images if Pictures stream contains pictures with zero length</action>
</release>
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml
index 7b95e677a0..791ff90291 100644
--- a/src/documentation/content/xdocs/status.xml
+++ b/src/documentation/content/xdocs/status.xml
@@ -34,6 +34,7 @@
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.5-beta6" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="add">46660 - added Workbook getHidden() and setHidden(boolean)</action>
<action dev="POI-DEVELOPERS" type="fix">46693 - Fixed bugs serialization bugs in records: CHARTFORMAT, SHTPROPS, SXVD and SXVDEX</action>
<action dev="POI-DEVELOPERS" type="fix">46627 - Fixed offset of added images if Pictures stream contains pictures with zero length</action>
</release>
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
index bb2a23bf5e..3f6d525edc 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
@@ -537,88 +537,55 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
}
/**
- * get the sheet name
- * @param sheetIx Number
- * @return Sheet name
+ * @return Sheet name for the specified index
*/
- public String getSheetName(int sheetIx)
- {
- validateSheetIndex(sheetIx);
- return workbook.getSheetName(sheetIx);
+ public String getSheetName(int sheetIndex) {
+ validateSheetIndex(sheetIndex);
+ return workbook.getSheetName(sheetIndex);
}
- /**
- * Check whether a sheet is hidden.
- * Note that a sheet could instead be
- * set to be very hidden, which is different
- * ({@link #isSheetVeryHidden(int)})
- * @param sheetIx Number
- * @return True if sheet is hidden
- */
+ public boolean isHidden() {
+ return workbook.getWindowOne().getHidden();
+ }
+
+ public void setHidden(boolean hiddenFlag) {
+ workbook.getWindowOne().setHidden(hiddenFlag);
+ }
+
public boolean isSheetHidden(int sheetIx) {
validateSheetIndex(sheetIx);
return workbook.isSheetHidden(sheetIx);
}
- /**
- * Check whether a sheet is very hidden.
- * This is different from the normal
- * hidden status
- * ({@link #isSheetHidden(int)})
- * @param sheetIx Number
- * @return True if sheet is very hidden
- */
+
public boolean isSheetVeryHidden(int sheetIx) {
validateSheetIndex(sheetIx);
return workbook.isSheetVeryHidden(sheetIx);
}
- /**
- * Hide or unhide a sheet
- *
- * @param sheetIx The sheet index
- * @param hidden True to mark the sheet as hidden, false otherwise
- */
+
public void setSheetHidden(int sheetIx, boolean hidden) {
validateSheetIndex(sheetIx);
workbook.setSheetHidden(sheetIx, hidden);
}
- /**
- * Hide or unhide a sheet.
- * 0 = not hidden
- * 1 = hidden
- * 2 = very hidden.
- *
- * @param sheetIx The sheet number
- * @param hidden 0 for not hidden, 1 for hidden, 2 for very hidden
- */
+
public void setSheetHidden(int sheetIx, int hidden) {
validateSheetIndex(sheetIx);
workbook.setSheetHidden(sheetIx, hidden);
}
- /*
- * get the sheet's index
- * @param name sheet name
- * @return sheet index or -1 if it was not found.
- */
-
/** Returns the index of the sheet by his name
* @param name the sheet name
* @return index of the sheet (0 based)
*/
- public int getSheetIndex(String name)
- {
- int retval = workbook.getSheetIndex(name);
-
- return retval;
+ public int getSheetIndex(String name){
+ return workbook.getSheetIndex(name);
}
/** Returns the index of the given sheet
* @param sheet the sheet to look up
* @return index of the sheet (0 based). <tt>-1</tt> if not found
*/
- public int getSheetIndex(org.apache.poi.ss.usermodel.Sheet sheet)
- {
+ public int getSheetIndex(org.apache.poi.ss.usermodel.Sheet sheet) {
for(int i=0; i<_sheets.size(); i++) {
if(_sheets.get(i) == sheet) {
return i;
@@ -628,7 +595,6 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
}
/**
-<<<<<<< .working
* Returns the external sheet index of the sheet
* with the given internal index, creating one
* if needed.
diff --git a/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java
index 5023825b4b..b33dc5745c 100644
--- a/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java
+++ b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java
@@ -412,15 +412,25 @@ public interface Workbook {
CreationHelper getCreationHelper();
/**
+ * @return <code>false</code> if this workbook is not visible in the GUI
+ */
+ boolean isHidden();
+
+ /**
+ * @param hiddenFlag pass <code>false</code> to make the workbook visible in the GUI
+ */
+ void setHidden(boolean hiddenFlag);
+
+ /**
* Check whether a sheet is hidden.
* <p>
* Note that a sheet could instead be set to be very hidden, which is different
* ({@link #isSheetVeryHidden(int)})
* </p>
* @param sheetIx Number
- * @return True if sheet is hidden
+ * @return <code>true</code> if sheet is hidden
*/
- boolean isSheetHidden(int sheetIx) ;
+ boolean isSheetHidden(int sheetIx);
/**
* Check whether a sheet is very hidden.
@@ -452,5 +462,4 @@ public interface Workbook {
* @param hidden 0 for not hidden, 1 for hidden, 2 for very hidden
*/
void setSheetHidden(int sheetIx, int hidden);
-
}
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
index d3a6a4f605..ce1724aed1 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
@@ -129,7 +129,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
* blank cells when fetching from a row.
* See {@link org.apache.poi.ss.usermodel.Row.MissingCellPolicy}
*/
- private MissingCellPolicy missingCellPolicy = Row.RETURN_NULL_AND_BLANK;
+ private MissingCellPolicy _missingCellPolicy = Row.RETURN_NULL_AND_BLANK;
/**
* array of pictures for this workbook
@@ -514,7 +514,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
if(pictures == null) {
//In OOXML pictures are referred to in sheets,
//dive into sheet's relations, select drawings and their images
- pictures = new ArrayList();
+ pictures = new ArrayList<XSSFPictureData>();
for(XSSFSheet sh : sheets){
for(POIXMLDocumentPart dr : sh.getRelations()){
if(dr instanceof XSSFDrawing){
@@ -788,7 +788,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
* {@link MissingCellPolicy}
*/
public MissingCellPolicy getMissingCellPolicy() {
- return missingCellPolicy;
+ return _missingCellPolicy;
}
/**
* Sets the policy on what to do when
@@ -798,7 +798,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
* {@link MissingCellPolicy}
*/
public void setMissingCellPolicy(MissingCellPolicy missingCellPolicy) {
- this.missingCellPolicy = missingCellPolicy;
+ _missingCellPolicy = missingCellPolicy;
}
/**
@@ -1077,7 +1077,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTWorkbook.type.getName().getNamespaceURI(), "workbook"));
- Map map = new HashMap();
+ Map<String, String> map = new HashMap<String, String>();
map.put(STRelationshipId.type.getName().getNamespaceURI(), "r");
xmlOptions.setSaveSuggestedPrefixes(map);
@@ -1208,59 +1208,33 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
}
return embedds;
}
+
+ public boolean isHidden() {
+ throw new RuntimeException("Not implemented yet");
+ }
+
+ public void setHidden(boolean hiddenFlag) {
+ throw new RuntimeException("Not implemented yet");
+ }
- /**
- * Check whether a sheet is hidden.
- * Note that a sheet could instead be set to be very hidden, which is different
- * ({@link #isSheetVeryHidden(int)})
- * @param sheetIx Number
- * @return True if sheet is hidden
- * @throws IllegalArgumentException if sheetIx is invalid
- */
public boolean isSheetHidden(int sheetIx) {
validateSheetIndex(sheetIx);
CTSheet ctSheet = sheets.get(sheetIx).sheet;
return ctSheet.getState() == STSheetState.HIDDEN;
}
- /**
- * Check whether a sheet is very hidden.
- * This is different from the normal hidden status ({@link #isSheetHidden(int)})
- * @param sheetIx Number
- * @return True if sheet is very hidden
- * @throws IllegalArgumentException if sheetIx is invalid
- */
public boolean isSheetVeryHidden(int sheetIx) {
validateSheetIndex(sheetIx);
CTSheet ctSheet = sheets.get(sheetIx).sheet;
return ctSheet.getState() == STSheetState.VERY_HIDDEN;
}
- /**
- * Hide or unhide a sheet
- *
- * @param sheetIx The sheet index
- * @param hidden True to mark the sheet as hidden, false otherwise
- * @throws IllegalArgumentException if sheetIx is invalid
- */
public void setSheetHidden(int sheetIx, boolean hidden) {
validateSheetIndex(sheetIx);
CTSheet ctSheet = sheets.get(sheetIx).sheet;
ctSheet.setState(hidden ? STSheetState.HIDDEN : STSheetState.VISIBLE);
}
- /**
- * Hide or unhide a sheet.
- * <pre>
- * 0 = not hidden
- * 1 = hidden
- * 2 = very hidden.
- * </pre>
- *
- * @param sheetIx The sheet number
- * @param hidden 0 for not hidden, 1 for hidden, 2 for very hidden
- * @throws IllegalArgumentException if sheetIx is invalid
- */
public void setSheetHidden(int sheetIx, int hidden) {
validateSheetIndex(sheetIx);
CTSheet ctSheet = sheets.get(sheetIx).sheet;
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
index 4dcf3c6f59..692ca86b25 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
@@ -32,6 +32,7 @@ import org.apache.poi.hssf.record.NameRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RecordBase;
import org.apache.poi.hssf.record.RecordFormatException;
+import org.apache.poi.hssf.record.WindowOneRecord;
import org.apache.poi.hssf.record.formula.Area3DPtg;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.TempFile;
@@ -118,6 +119,33 @@ public final class TestHSSFWorkbook extends TestCase {
fail("WindowOneRecord in Workbook is probably not initialized");
}
}
+
+ /**
+ * Tests for {@link HSSFWorkbook#isHidden()} etc
+ */
+ public void testHidden() {
+ HSSFWorkbook wb = new HSSFWorkbook();
+
+ WindowOneRecord w1 = wb.getWorkbook().getWindowOne();
+
+ assertEquals(false, wb.isHidden());
+ assertEquals(false, w1.getHidden());
+
+ wb.setHidden(true);
+ assertEquals(true, wb.isHidden());
+ assertEquals(true, w1.getHidden());
+
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
+ w1 = wb.getWorkbook().getWindowOne();
+
+ wb.setHidden(true);
+ assertEquals(true, wb.isHidden());
+ assertEquals(true, w1.getHidden());
+
+ wb.setHidden(false);
+ assertEquals(false, wb.isHidden());
+ assertEquals(false, w1.getHidden());
+ }
public void testSheetSelection() {
HSSFWorkbook b = new HSSFWorkbook();