Bugzilla 46660 - added 'hidden' property to Workbook

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@744253 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2009-02-13 21:46:44 +00:00
parent 475cd9bd70
commit f9e3784671
6 changed files with 73 additions and 94 deletions

View File

@ -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>

View File

@ -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>

View File

@ -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.

View File

@ -411,6 +411,16 @@ 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>
@ -418,9 +428,9 @@ public interface Workbook {
* ({@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);
}

View File

@ -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;

View File

@ -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();