Eclipse warnings, code formatting, missing @Overrides, Javadoc, missing close(), ...

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1696794 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2015-08-20 14:28:39 +00:00
parent 8e738cac68
commit 39163eccff
4 changed files with 175 additions and 56 deletions

View File

@ -197,8 +197,8 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* Given a POI POIFSFileSystem object, read in its Workbook along * Given a POI POIFSFileSystem object, read in its Workbook along
* with all related nodes, and populate the high and low level models. * with all related nodes, and populate the high and low level models.
* <p>This calls {@link #HSSFWorkbook(POIFSFileSystem, boolean)} with * <p>This calls {@link #HSSFWorkbook(POIFSFileSystem, boolean)} with
* preserve nodes set to true. * preserve nodes set to true.
* *
* @see #HSSFWorkbook(POIFSFileSystem, boolean) * @see #HSSFWorkbook(POIFSFileSystem, boolean)
* @see org.apache.poi.poifs.filesystem.POIFSFileSystem * @see org.apache.poi.poifs.filesystem.POIFSFileSystem
* @exception IOException if the stream cannot be read * @exception IOException if the stream cannot be read
@ -210,8 +210,8 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* Given a POI POIFSFileSystem object, read in its Workbook along * Given a POI POIFSFileSystem object, read in its Workbook along
* with all related nodes, and populate the high and low level models. * with all related nodes, and populate the high and low level models.
* <p>This calls {@link #HSSFWorkbook(POIFSFileSystem, boolean)} with * <p>This calls {@link #HSSFWorkbook(POIFSFileSystem, boolean)} with
* preserve nodes set to true. * preserve nodes set to true.
* *
* @see #HSSFWorkbook(POIFSFileSystem, boolean) * @see #HSSFWorkbook(POIFSFileSystem, boolean)
* @see org.apache.poi.poifs.filesystem.POIFSFileSystem * @see org.apache.poi.poifs.filesystem.POIFSFileSystem
* @exception IOException if the stream cannot be read * @exception IOException if the stream cannot be read
@ -221,7 +221,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
} }
/** /**
* Given a POI POIFSFileSystem object, read in its Workbook and populate * Given a POI POIFSFileSystem object, read in its Workbook and populate
* the high and low level models. If you're reading in a workbook... start here! * the high and low level models. If you're reading in a workbook... start here!
* *
* @param fs the POI filesystem that contains the Workbook stream. * @param fs the POI filesystem that contains the Workbook stream.
@ -259,7 +259,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
// continue - to try other options // continue - to try other options
} }
} }
// check for an encrypted .xlsx file - they get OLE2 wrapped // check for an encrypted .xlsx file - they get OLE2 wrapped
try { try {
directory.getEntry(Decryptor.DEFAULT_POIFS_ENTRY); directory.getEntry(Decryptor.DEFAULT_POIFS_ENTRY);
@ -363,10 +363,10 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
} }
/** /**
* Companion to HSSFWorkbook(POIFSFileSystem), this constructs the * Companion to HSSFWorkbook(POIFSFileSystem), this constructs the
* POI filesystem around your {@link InputStream}, including all nodes. * POI filesystem around your {@link InputStream}, including all nodes.
* <p>This calls {@link #HSSFWorkbook(InputStream, boolean)} with * <p>This calls {@link #HSSFWorkbook(InputStream, boolean)} with
* preserve nodes set to true. * preserve nodes set to true.
* *
* @see #HSSFWorkbook(InputStream, boolean) * @see #HSSFWorkbook(InputStream, boolean)
* @see #HSSFWorkbook(POIFSFileSystem) * @see #HSSFWorkbook(POIFSFileSystem)
@ -378,7 +378,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
} }
/** /**
* Companion to HSSFWorkbook(POIFSFileSystem), this constructs the * Companion to HSSFWorkbook(POIFSFileSystem), this constructs the
* POI filesystem around your {@link InputStream}. * POI filesystem around your {@link InputStream}.
* *
* @param s the POI filesystem that contains the Workbook stream. * @param s the POI filesystem that contains the Workbook stream.
@ -389,6 +389,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @see #HSSFWorkbook(POIFSFileSystem) * @see #HSSFWorkbook(POIFSFileSystem)
* @exception IOException if the stream cannot be read * @exception IOException if the stream cannot be read
*/ */
@SuppressWarnings("resource") // NPOIFSFileSystem always closes the stream
public HSSFWorkbook(InputStream s, boolean preserveNodes) public HSSFWorkbook(InputStream s, boolean preserveNodes)
throws IOException throws IOException
{ {
@ -457,6 +458,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* The default is to return blank and null cells. * The default is to return blank and null cells.
* {@link MissingCellPolicy} * {@link MissingCellPolicy}
*/ */
@Override
public MissingCellPolicy getMissingCellPolicy() { public MissingCellPolicy getMissingCellPolicy() {
return missingCellPolicy; return missingCellPolicy;
} }
@ -471,6 +473,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* iterators, only on when fetching Cells * iterators, only on when fetching Cells
* by their column index. * by their column index.
*/ */
@Override
public void setMissingCellPolicy(MissingCellPolicy missingCellPolicy) { public void setMissingCellPolicy(MissingCellPolicy missingCellPolicy) {
this.missingCellPolicy = missingCellPolicy; this.missingCellPolicy = missingCellPolicy;
} }
@ -482,6 +485,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @param pos the position that we want to insert the sheet into (0 based) * @param pos the position that we want to insert the sheet into (0 based)
*/ */
@Override
public void setSheetOrder(String sheetname, int pos ) { public void setSheetOrder(String sheetname, int pos ) {
int oldSheetIndex = getSheetIndex(sheetname); int oldSheetIndex = getSheetIndex(sheetname);
_sheets.add(pos,_sheets.remove(oldSheetIndex)); _sheets.add(pos,_sheets.remove(oldSheetIndex));
@ -527,6 +531,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* Selects a single sheet. This may be different to * Selects a single sheet. This may be different to
* the 'active' sheet (which is the sheet with focus). * the 'active' sheet (which is the sheet with focus).
*/ */
@Override
public void setSelectedTab(int index) { public void setSelectedTab(int index) {
validateSheetIndex(index); validateSheetIndex(index);
@ -568,6 +573,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* which is currently displayed when the workbook is viewed in Excel. * which is currently displayed when the workbook is viewed in Excel.
* 'Selected' sheet(s) is a distinct concept. * 'Selected' sheet(s) is a distinct concept.
*/ */
@Override
public void setActiveSheet(int index) { public void setActiveSheet(int index) {
validateSheetIndex(index); validateSheetIndex(index);
@ -585,6 +591,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* in the tabs (at the bottom). * in the tabs (at the bottom).
* @see org.apache.poi.hssf.usermodel.HSSFSheet#setSelected(boolean) * @see org.apache.poi.hssf.usermodel.HSSFSheet#setSelected(boolean)
*/ */
@Override
public int getActiveSheetIndex() { public int getActiveSheetIndex() {
return workbook.getWindowOne().getActiveSheetIndex(); return workbook.getWindowOne().getActiveSheetIndex();
} }
@ -603,6 +610,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* in excel. * in excel.
* @param index * @param index
*/ */
@Override
public void setFirstVisibleTab(int index) { public void setFirstVisibleTab(int index) {
workbook.getWindowOne().setFirstVisibleTab(index); workbook.getWindowOne().setFirstVisibleTab(index);
} }
@ -618,6 +626,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
/** /**
* sets the first tab that is displayed in the list of tabs in excel. * sets the first tab that is displayed in the list of tabs in excel.
*/ */
@Override
public int getFirstVisibleTab() { public int getFirstVisibleTab() {
return workbook.getWindowOne().getFirstVisibleTab(); return workbook.getWindowOne().getFirstVisibleTab();
} }
@ -639,6 +648,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @see #createSheet(String) * @see #createSheet(String)
* @see org.apache.poi.ss.util.WorkbookUtil#createSafeSheetName(String nameProposal) * @see org.apache.poi.ss.util.WorkbookUtil#createSafeSheetName(String nameProposal)
*/ */
@Override
public void setSheetName(int sheetIx, String name) { public void setSheetName(int sheetIx, String name) {
if (name == null) { if (name == null) {
throw new IllegalArgumentException("sheetName must not be null"); throw new IllegalArgumentException("sheetName must not be null");
@ -654,35 +664,42 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
/** /**
* @return Sheet name for the specified index * @return Sheet name for the specified index
*/ */
@Override
public String getSheetName(int sheetIndex) { public String getSheetName(int sheetIndex) {
validateSheetIndex(sheetIndex); validateSheetIndex(sheetIndex);
return workbook.getSheetName(sheetIndex); return workbook.getSheetName(sheetIndex);
} }
@Override
public boolean isHidden() { public boolean isHidden() {
return workbook.getWindowOne().getHidden(); return workbook.getWindowOne().getHidden();
} }
@Override
public void setHidden(boolean hiddenFlag) { public void setHidden(boolean hiddenFlag) {
workbook.getWindowOne().setHidden(hiddenFlag); workbook.getWindowOne().setHidden(hiddenFlag);
} }
@Override
public boolean isSheetHidden(int sheetIx) { public boolean isSheetHidden(int sheetIx) {
validateSheetIndex(sheetIx); validateSheetIndex(sheetIx);
return workbook.isSheetHidden(sheetIx); return workbook.isSheetHidden(sheetIx);
} }
@Override
public boolean isSheetVeryHidden(int sheetIx) { public boolean isSheetVeryHidden(int sheetIx) {
validateSheetIndex(sheetIx); validateSheetIndex(sheetIx);
return workbook.isSheetVeryHidden(sheetIx); return workbook.isSheetVeryHidden(sheetIx);
} }
@Override
public void setSheetHidden(int sheetIx, boolean hidden) { public void setSheetHidden(int sheetIx, boolean hidden) {
validateSheetIndex(sheetIx); validateSheetIndex(sheetIx);
workbook.setSheetHidden(sheetIx, hidden); workbook.setSheetHidden(sheetIx, hidden);
} }
@Override
public void setSheetHidden(int sheetIx, int hidden) { public void setSheetHidden(int sheetIx, int hidden) {
validateSheetIndex(sheetIx); validateSheetIndex(sheetIx);
WorkbookUtil.validateSheetState(hidden); WorkbookUtil.validateSheetState(hidden);
@ -693,6 +710,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @param name the sheet name * @param name the sheet name
* @return index of the sheet (0 based) * @return index of the sheet (0 based)
*/ */
@Override
public int getSheetIndex(String name){ public int getSheetIndex(String name){
return workbook.getSheetIndex(name); return workbook.getSheetIndex(name);
} }
@ -701,6 +719,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @param sheet the sheet to look up * @param sheet the sheet to look up
* @return index of the sheet (0 based). <tt>-1</tt> if not found * @return index of the sheet (0 based). <tt>-1</tt> if not found
*/ */
@Override
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++) { for(int i=0; i<_sheets.size(); i++) {
if(_sheets.get(i) == sheet) { if(_sheets.get(i) == sheet) {
@ -753,6 +772,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @return HSSFSheet representing the new sheet. * @return HSSFSheet representing the new sheet.
*/ */
@Override
public HSSFSheet createSheet() public HSSFSheet createSheet()
{ {
HSSFSheet sheet = new HSSFSheet(this); HSSFSheet sheet = new HSSFSheet(this);
@ -771,6 +791,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @return HSSFSheet representing the cloned sheet. * @return HSSFSheet representing the cloned sheet.
*/ */
@Override
public HSSFSheet cloneSheet(int sheetIndex) { public HSSFSheet cloneSheet(int sheetIndex) {
validateSheetIndex(sheetIndex); validateSheetIndex(sheetIndex);
HSSFSheet srcSheet = _sheets.get(sheetIndex); HSSFSheet srcSheet = _sheets.get(sheetIndex);
@ -871,6 +892,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* or workbook already contains a sheet with this name * or workbook already contains a sheet with this name
* @see org.apache.poi.ss.util.WorkbookUtil#createSafeSheetName(String nameProposal) * @see org.apache.poi.ss.util.WorkbookUtil#createSafeSheetName(String nameProposal)
*/ */
@Override
public HSSFSheet createSheet(String sheetname) public HSSFSheet createSheet(String sheetname)
{ {
if (sheetname == null) { if (sheetname == null) {
@ -895,6 +917,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @return number of sheets * @return number of sheets
*/ */
@Override
public int getNumberOfSheets() public int getNumberOfSheets()
{ {
return _sheets.size(); return _sheets.size();
@ -922,6 +945,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @return HSSFSheet at the provided index * @return HSSFSheet at the provided index
*/ */
@Override
public HSSFSheet getSheetAt(int index) public HSSFSheet getSheetAt(int index)
{ {
validateSheetIndex(index); validateSheetIndex(index);
@ -934,6 +958,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @return HSSFSheet with the name provided or <code>null</code> if it does not exist * @return HSSFSheet with the name provided or <code>null</code> if it does not exist
*/ */
@Override
public HSSFSheet getSheet(String name) public HSSFSheet getSheet(String name)
{ {
HSSFSheet retval = null; HSSFSheet retval = null;
@ -964,6 +989,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* *
* @param index of the sheet (0-based) * @param index of the sheet (0-based)
*/ */
@Override
public void removeSheetAt(int index) { public void removeSheetAt(int index) {
validateSheetIndex(index); validateSheetIndex(index);
boolean wasSelected = getSheetAt(index).isSelected(); boolean wasSelected = getSheetAt(index).isSelected();
@ -1064,6 +1090,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @deprecated use {@link HSSFSheet#setRepeatingRows(CellRangeAddress)} * @deprecated use {@link HSSFSheet#setRepeatingRows(CellRangeAddress)}
* or {@link HSSFSheet#setRepeatingColumns(CellRangeAddress)} * or {@link HSSFSheet#setRepeatingColumns(CellRangeAddress)}
*/ */
@Override
@Deprecated @Deprecated
public void setRepeatingRowsAndColumns(int sheetIndex, public void setRepeatingRowsAndColumns(int sheetIndex,
int startColumn, int endColumn, int startColumn, int endColumn,
@ -1126,6 +1153,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @return new font object * @return new font object
*/ */
@Override
public HSSFFont createFont() public HSSFFont createFont()
{ {
/*FontRecord font =*/ workbook.createNewFont(); /*FontRecord font =*/ workbook.createNewFont();
@ -1147,6 +1175,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
/** /**
* Finds a font that matches the one with the supplied attributes * Finds a font that matches the one with the supplied attributes
*/ */
@Override
public HSSFFont findFont(short boldWeight, short color, short fontHeight, public HSSFFont findFont(short boldWeight, short color, short fontHeight,
String name, boolean italic, boolean strikeout, String name, boolean italic, boolean strikeout,
short typeOffset, byte underline) short typeOffset, byte underline)
@ -1177,6 +1206,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @return number of fonts * @return number of fonts
*/ */
@Override
public short getNumberOfFonts() public short getNumberOfFonts()
{ {
return (short) workbook.getNumberOfFontRecords(); return (short) workbook.getNumberOfFontRecords();
@ -1187,6 +1217,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @param idx index number * @param idx index number
* @return HSSFFont at the index * @return HSSFFont at the index
*/ */
@Override
public HSSFFont getFontAt(short idx) { public HSSFFont getFontAt(short idx) {
if(fonts == null) fonts = new Hashtable<Short, HSSFFont>(); if(fonts == null) fonts = new Hashtable<Short, HSSFFont>();
@ -1220,9 +1251,9 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* You can define up to 4000 unique styles in a .xls workbook. * You can define up to 4000 unique styles in a .xls workbook.
* *
* @return the new Cell Style object * @return the new Cell Style object
* @throws IllegalStateException if the maximum number of cell styles exceeded the limit * @throws IllegalStateException if the number of cell styles exceeded the limit for this type of Workbook.
*/ */
@Override
public HSSFCellStyle createCellStyle() public HSSFCellStyle createCellStyle()
{ {
if(workbook.getNumExFormats() == MAX_STYLES) { if(workbook.getNumExFormats() == MAX_STYLES) {
@ -1241,6 +1272,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @return count of cell styles * @return count of cell styles
*/ */
@Override
public short getNumCellStyles() public short getNumCellStyles()
{ {
return (short) workbook.getNumExFormats(); return (short) workbook.getNumExFormats();
@ -1251,6 +1283,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @param idx index within the set of styles * @param idx index within the set of styles
* @return HSSFCellStyle object at the index * @return HSSFCellStyle object at the index
*/ */
@Override
public HSSFCellStyle getCellStyleAt(short idx) public HSSFCellStyle getCellStyleAt(short idx)
{ {
ExtendedFormatRecord xfr = workbook.getExFormatAt(idx); ExtendedFormatRecord xfr = workbook.getExFormatAt(idx);
@ -1258,7 +1291,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
return style; return style;
} }
/** /**
* Closes the underlying {@link NPOIFSFileSystem} from which * Closes the underlying {@link NPOIFSFileSystem} from which
* the Workbook was read, if any. Has no effect on Workbooks * the Workbook was read, if any. Has no effect on Workbooks
@ -1336,10 +1369,11 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
public int getTotalSize() { public int getTotalSize() {
return _totalSize; return _totalSize;
} }
@Override
public void visitRecord(Record r) { public void visitRecord(Record r) {
_list.add(r); _list.add(r);
_totalSize+=r.getRecordSize(); _totalSize+=r.getRecordSize();
} }
public int serialize(int offset, byte[] data) { public int serialize(int offset, byte[] data) {
int result = 0; int result = 0;
@ -1432,11 +1466,13 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
return workbook; return workbook;
} }
@Override
public int getNumberOfNames(){ public int getNumberOfNames(){
int result = names.size(); int result = names.size();
return result; return result;
} }
@Override
public HSSFName getName(String name) { public HSSFName getName(String name) {
int nameIndex = getNameIndex(name); int nameIndex = getNameIndex(name);
if (nameIndex < 0) { if (nameIndex < 0) {
@ -1445,6 +1481,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
return names.get(nameIndex); return names.get(nameIndex);
} }
@Override
public HSSFName getNameAt(int nameIndex) { public HSSFName getNameAt(int nameIndex) {
int nNames = names.size(); int nNames = names.size();
if (nNames < 1) { if (nNames < 1) {
@ -1478,6 +1515,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @param sheetIndex Zero-based sheet index (0 Represents the first sheet to keep consistent with java) * @param sheetIndex Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
* @param reference Valid name Reference for the Print Area * @param reference Valid name Reference for the Print Area
*/ */
@Override
public void setPrintArea(int sheetIndex, String reference) public void setPrintArea(int sheetIndex, String reference)
{ {
NameRecord name = workbook.getSpecificBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1); NameRecord name = workbook.getSpecificBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
@ -1509,6 +1547,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @param startRow Row to begin the printarea * @param startRow Row to begin the printarea
* @param endRow Row to end the printarea * @param endRow Row to end the printarea
*/ */
@Override
public void setPrintArea(int sheetIndex, int startColumn, int endColumn, public void setPrintArea(int sheetIndex, int startColumn, int endColumn,
int startRow, int endRow) { int startRow, int endRow) {
@ -1528,6 +1567,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @param sheetIndex Zero-based sheet index (0 Represents the first sheet to keep consistent with java) * @param sheetIndex Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
* @return String Null if no print area has been defined * @return String Null if no print area has been defined
*/ */
@Override
public String getPrintArea(int sheetIndex) { public String getPrintArea(int sheetIndex) {
NameRecord name = workbook.getSpecificBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1); NameRecord name = workbook.getSpecificBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
//adding one here because 0 indicates a global named region; doesn't make sense for print areas //adding one here because 0 indicates a global named region; doesn't make sense for print areas
@ -1542,6 +1582,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* Delete the printarea for the sheet specified * Delete the printarea for the sheet specified
* @param sheetIndex Zero-based sheet index (0 = First Sheet) * @param sheetIndex Zero-based sheet index (0 = First Sheet)
*/ */
@Override
public void removePrintArea(int sheetIndex) { public void removePrintArea(int sheetIndex) {
getWorkbook().removeBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1); getWorkbook().removeBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
} }
@ -1549,6 +1590,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
/** creates a new named range and add it to the model /** creates a new named range and add it to the model
* @return named range high level * @return named range high level
*/ */
@Override
public HSSFName createName(){ public HSSFName createName(){
NameRecord nameRecord = workbook.createName(); NameRecord nameRecord = workbook.createName();
@ -1559,6 +1601,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
return newName; return newName;
} }
@Override
public int getNameIndex(String name) { public int getNameIndex(String name) {
for (int k = 0; k < names.size(); k++) { for (int k = 0; k < names.size(); k++) {
@ -1591,6 +1634,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
} }
@Override
public void removeName(int index){ public void removeName(int index){
names.remove(index); names.remove(index);
workbook.removeName(index); workbook.removeName(index);
@ -1602,6 +1646,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @see org.apache.poi.hssf.record.FormatRecord * @see org.apache.poi.hssf.record.FormatRecord
* @see org.apache.poi.hssf.record.Record * @see org.apache.poi.hssf.record.Record
*/ */
@Override
public HSSFDataFormat createDataFormat() { public HSSFDataFormat createDataFormat() {
if (formatter == null) if (formatter == null)
formatter = new HSSFDataFormat(workbook); formatter = new HSSFDataFormat(workbook);
@ -1609,6 +1654,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
} }
@Override
public void removeName(String name) { public void removeName(String name) {
int index = getNameIndex(name); int index = getNameIndex(name);
removeName(index); removeName(index);
@ -1698,6 +1744,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* *
* @return the index to this picture (1 based). * @return the index to this picture (1 based).
*/ */
@Override
public int addPicture(byte[] pictureData, int format) public int addPicture(byte[] pictureData, int format)
{ {
initDrawings(); initDrawings();
@ -1759,7 +1806,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
blipRecord.setOptions(HSSFPictureData.MSOBI_DIB); blipRecord.setOptions(HSSFPictureData.MSOBI_DIB);
break; break;
} }
EscherBSERecord r = new EscherBSERecord(); EscherBSERecord r = new EscherBSERecord();
r.setRecordId( EscherBSERecord.RECORD_ID ); r.setRecordId( EscherBSERecord.RECORD_ID );
r.setOptions( (short) ( 0x0002 | ( format << 4 ) ) ); r.setOptions( (short) ( 0x0002 | ( format << 4 ) ) );
@ -1771,7 +1818,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
r.setRef( 0 ); r.setRef( 0 );
r.setOffset( 0 ); r.setOffset( 0 );
r.setBlipRecord( blipRecord ); r.setBlipRecord( blipRecord );
return workbook.addBSERecord( r ); return workbook.addBSERecord( r );
} }
@ -1780,6 +1827,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* *
* @return the list of pictures (a list of {@link HSSFPictureData} objects.) * @return the list of pictures (a list of {@link HSSFPictureData} objects.)
*/ */
@Override
public List<HSSFPictureData> getAllPictures() public List<HSSFPictureData> getAllPictures()
{ {
// The drawing group record always exists at the top level, so we won't need to do this recursively. // The drawing group record always exists at the top level, so we won't need to do this recursively.
@ -1836,7 +1884,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
// ... to be continued // ... to be continued
return olemap; return olemap;
} }
public int addOlePackage(POIFSFileSystem poiData, String label, String fileName, String command) public int addOlePackage(POIFSFileSystem poiData, String label, String fileName, String command)
throws IOException { throws IOException {
DirectoryNode root = poiData.getRoot(); DirectoryNode root = poiData.getRoot();
@ -1847,12 +1895,12 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
break; break;
} }
} }
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
poiData.writeFilesystem(bos); poiData.writeFilesystem(bos);
return addOlePackage(bos.toByteArray(), label, fileName, command); return addOlePackage(bos.toByteArray(), label, fileName, command);
} }
public int addOlePackage(byte[] oleData, String label, String fileName, String command) public int addOlePackage(byte[] oleData, String label, String fileName, String command)
throws IOException { throws IOException {
// check if we were created by POIFS otherwise create a new dummy POIFS for storing the package data // check if we were created by POIFS otherwise create a new dummy POIFS for storing the package data
@ -1860,7 +1908,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
directory = new NPOIFSFileSystem().getRoot(); directory = new NPOIFSFileSystem().getRoot();
preserveNodes = true; preserveNodes = true;
} }
// get free MBD-Node // get free MBD-Node
int storageId = 0; int storageId = 0;
DirectoryEntry oleDir = null; DirectoryEntry oleDir = null;
@ -1871,34 +1919,35 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
oleDir.setStorageClsid(ClassID.OLE10_PACKAGE); oleDir.setStorageClsid(ClassID.OLE10_PACKAGE);
} }
} while (oleDir == null); } while (oleDir == null);
// the following data was taken from an example libre office document // the following data was taken from an example libre office document
// beside this "\u0001Ole" record there were several other records, e.g. CompObj, // beside this "\u0001Ole" record there were several other records, e.g. CompObj,
// OlePresXXX, but it seems, that they aren't neccessary // OlePresXXX, but it seems, that they aren't neccessary
byte oleBytes[] = { 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; byte oleBytes[] = { 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
oleDir.createDocument("\u0001Ole", new ByteArrayInputStream(oleBytes)); oleDir.createDocument("\u0001Ole", new ByteArrayInputStream(oleBytes));
Ole10Native oleNative = new Ole10Native(label, fileName, command, oleData); Ole10Native oleNative = new Ole10Native(label, fileName, command, oleData);
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
oleNative.writeOut(bos); oleNative.writeOut(bos);
oleDir.createDocument(Ole10Native.OLE10_NATIVE, new ByteArrayInputStream(bos.toByteArray())); oleDir.createDocument(Ole10Native.OLE10_NATIVE, new ByteArrayInputStream(bos.toByteArray()));
return storageId; return storageId;
} }
/** /**
* Adds the LinkTable records required to allow formulas referencing * Adds the LinkTable records required to allow formulas referencing
* the specified external workbook to be added to this one. Allows * the specified external workbook to be added to this one. Allows
* formulas such as "[MyOtherWorkbook]Sheet3!$A$5" to be added to the * formulas such as "[MyOtherWorkbook]Sheet3!$A$5" to be added to the
* file, for workbooks not already referenced. * file, for workbooks not already referenced.
* *
* @param name The name the workbook will be referenced as in formulas * @param name The name the workbook will be referenced as in formulas
* @param workbook The open workbook to fetch the link required information from * @param workbook The open workbook to fetch the link required information from
*/ */
@Override
public int linkExternalWorkbook(String name, Workbook workbook) { public int linkExternalWorkbook(String name, Workbook workbook) {
return this.workbook.linkExternalWorkbook(name, workbook); return this.workbook.linkExternalWorkbook(name, workbook);
} }
/** /**
* Is the workbook protected with a password (not encrypted)? * Is the workbook protected with a password (not encrypted)?
*/ */
@ -1967,6 +2016,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
} }
} }
} }
@Override
public HSSFCreationHelper getCreationHelper() { public HSSFCreationHelper getCreationHelper() {
return new HSSFCreationHelper(this); return new HSSFCreationHelper(this);
} }
@ -1987,6 +2037,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* *
* @param toopack the toolpack to register * @param toopack the toolpack to register
*/ */
@Override
public void addToolPack(UDFFinder toopack){ public void addToolPack(UDFFinder toopack){
AggregatingUDFFinder udfs = (AggregatingUDFFinder)_udfFinder; AggregatingUDFFinder udfs = (AggregatingUDFFinder)_udfFinder;
udfs.add(toopack); udfs.add(toopack);
@ -2009,6 +2060,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* workbook values when the workbook is opened * workbook values when the workbook is opened
* @since 3.8 * @since 3.8
*/ */
@Override
public void setForceFormulaRecalculation(boolean value){ public void setForceFormulaRecalculation(boolean value){
InternalWorkbook iwb = getWorkbook(); InternalWorkbook iwb = getWorkbook();
RecalcIdRecord recalc = iwb.getRecalcId(); RecalcIdRecord recalc = iwb.getRecalcId();
@ -2020,6 +2072,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* *
* @since 3.8 * @since 3.8
*/ */
@Override
public boolean getForceFormulaRecalculation(){ public boolean getForceFormulaRecalculation(){
InternalWorkbook iwb = getWorkbook(); InternalWorkbook iwb = getWorkbook();
RecalcIdRecord recalc = (RecalcIdRecord)iwb.findFirstRecordBySid(RecalcIdRecord.sid); RecalcIdRecord recalc = (RecalcIdRecord)iwb.findFirstRecordBySid(RecalcIdRecord.sid);

View File

@ -54,7 +54,7 @@ public interface Workbook extends Closeable {
/** /**
* Indicates the sheet is visible. * Indicates the sheet is visible.
* *
* @see #setSheetHidden(int, int) * @see #setSheetHidden(int, int)
*/ */
public static final int SHEET_STATE_VISIBLE = 0; public static final int SHEET_STATE_VISIBLE = 0;
@ -286,10 +286,11 @@ public interface Workbook extends Closeable {
* @param endColumn 0 based end of repeating columns. * @param endColumn 0 based end of repeating columns.
* @param startRow 0 based start of repeating rows. * @param startRow 0 based start of repeating rows.
* @param endRow 0 based end of repeating rows. * @param endRow 0 based end of repeating rows.
* *
* @deprecated use {@link Sheet#setRepeatingRows(CellRangeAddress)} * @deprecated use {@link Sheet#setRepeatingRows(CellRangeAddress)}
* or {@link Sheet#setRepeatingColumns(CellRangeAddress)} * or {@link Sheet#setRepeatingColumns(CellRangeAddress)}
*/ */
@Deprecated
void setRepeatingRowsAndColumns(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow); void setRepeatingRowsAndColumns(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow);
/** /**
@ -325,6 +326,7 @@ public interface Workbook extends Closeable {
* Create a new Cell style and add it to the workbook's style table * Create a new Cell style and add it to the workbook's style table
* *
* @return the new Cell Style object * @return the new Cell Style object
* @throws IllegalStateException if the number of cell styles exceeded the limit for this type of Workbook.
*/ */
CellStyle createCellStyle(); CellStyle createCellStyle();
@ -357,8 +359,9 @@ public interface Workbook extends Closeable {
* Workbook should no longer be used. * Workbook should no longer be used.
* <p>This will have no effect newly created Workbooks. * <p>This will have no effect newly created Workbooks.
*/ */
@Override
void close() throws IOException; void close() throws IOException;
/** /**
* @return the total number of defined names in this workbook * @return the total number of defined names in this workbook
*/ */
@ -414,7 +417,7 @@ public interface Workbook extends Closeable {
* to be added to the file, some linking information must first * to be added to the file, some linking information must first
* be recorded. Once a given external workbook has been linked, * be recorded. Once a given external workbook has been linked,
* then formulas using it can added. Each workbook needs linking * then formulas using it can added. Each workbook needs linking
* only once. * only once.
* <p>This linking only applies for writing formulas. To link things * <p>This linking only applies for writing formulas. To link things
* for evaluation, see {@link FormulaEvaluator#setupReferencedWorkbooks(java.util.Map)} * for evaluation, see {@link FormulaEvaluator#setupReferencedWorkbooks(java.util.Map)}
* *
@ -422,7 +425,7 @@ public interface Workbook extends Closeable {
* @param workbook The open workbook to fetch the link required information from * @param workbook The open workbook to fetch the link required information from
*/ */
int linkExternalWorkbook(String name, Workbook workbook); int linkExternalWorkbook(String name, Workbook workbook);
/** /**
* Sets the printarea for the sheet provided * Sets the printarea for the sheet provided
* <p> * <p>
@ -557,7 +560,7 @@ public interface Workbook extends Closeable {
/** /**
* Hide or unhide a sheet. * Hide or unhide a sheet.
* *
* <ul> * <ul>
* <li>0 - visible. </li> * <li>0 - visible. </li>
* <li>1 - hidden. </li> * <li>1 - hidden. </li>

View File

@ -131,10 +131,11 @@ public class XSSFCellStyle implements CellStyle {
* XSSFWorkbook if you like. This allows you to * XSSFWorkbook if you like. This allows you to
* copy styles from one XSSFWorkbook to another. * copy styles from one XSSFWorkbook to another.
*/ */
@Override
public void cloneStyleFrom(CellStyle source) { public void cloneStyleFrom(CellStyle source) {
if(source instanceof XSSFCellStyle) { if(source instanceof XSSFCellStyle) {
XSSFCellStyle src = (XSSFCellStyle)source; XSSFCellStyle src = (XSSFCellStyle)source;
// Is it on our Workbook? // Is it on our Workbook?
if(src._stylesSource == _stylesSource) { if(src._stylesSource == _stylesSource) {
// Nice and easy // Nice and easy
@ -149,30 +150,30 @@ public class XSSFCellStyle implements CellStyle {
_cellXf.unsetAlignment(); _cellXf.unsetAlignment();
if(_cellXf.isSetExtLst()) if(_cellXf.isSetExtLst())
_cellXf.unsetExtLst(); _cellXf.unsetExtLst();
// Create a new Xf with the same contents // Create a new Xf with the same contents
_cellXf = CTXf.Factory.parse( _cellXf = CTXf.Factory.parse(
src.getCoreXf().toString() src.getCoreXf().toString()
); );
// bug 56295: ensure that the fills is available and set correctly // bug 56295: ensure that the fills is available and set correctly
CTFill fill = CTFill.Factory.parse( CTFill fill = CTFill.Factory.parse(
src.getCTFill().toString() src.getCTFill().toString()
); );
addFill(fill); addFill(fill);
// Swap it over // Swap it over
_stylesSource.replaceCellXfAt(_cellXfId, _cellXf); _stylesSource.replaceCellXfAt(_cellXfId, _cellXf);
} catch(XmlException e) { } catch(XmlException e) {
throw new POIXMLException(e); throw new POIXMLException(e);
} }
// Copy the format // Copy the format
String fmt = src.getDataFormatString(); String fmt = src.getDataFormatString();
setDataFormat( setDataFormat(
(new XSSFDataFormat(_stylesSource)).getFormat(fmt) (new XSSFDataFormat(_stylesSource)).getFormat(fmt)
); );
// Copy the font // Copy the font
try { try {
CTFont ctFont = CTFont.Factory.parse( CTFont ctFont = CTFont.Factory.parse(
@ -185,7 +186,7 @@ public class XSSFCellStyle implements CellStyle {
throw new POIXMLException(e); throw new POIXMLException(e);
} }
} }
// Clear out cached details // Clear out cached details
_font = null; _font = null;
_cellAlignment = null; _cellAlignment = null;
@ -213,6 +214,7 @@ public class XSSFCellStyle implements CellStyle {
* @see org.apache.poi.ss.usermodel.CellStyle#ALIGN_JUSTIFY * @see org.apache.poi.ss.usermodel.CellStyle#ALIGN_JUSTIFY
* @see org.apache.poi.ss.usermodel.CellStyle#ALIGN_CENTER_SELECTION * @see org.apache.poi.ss.usermodel.CellStyle#ALIGN_CENTER_SELECTION
*/ */
@Override
public short getAlignment() { public short getAlignment() {
return (short)(getAlignmentEnum().ordinal()); return (short)(getAlignmentEnum().ordinal());
} }
@ -250,6 +252,7 @@ public class XSSFCellStyle implements CellStyle {
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
*/ */
@Override
public short getBorderBottom() { public short getBorderBottom() {
if(!_cellXf.getApplyBorder()) return BORDER_NONE; if(!_cellXf.getApplyBorder()) return BORDER_NONE;
@ -289,6 +292,7 @@ public class XSSFCellStyle implements CellStyle {
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
*/ */
@Override
public short getBorderLeft() { public short getBorderLeft() {
if(!_cellXf.getApplyBorder()) return BORDER_NONE; if(!_cellXf.getApplyBorder()) return BORDER_NONE;
@ -327,6 +331,7 @@ public class XSSFCellStyle implements CellStyle {
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
*/ */
@Override
public short getBorderRight() { public short getBorderRight() {
if(!_cellXf.getApplyBorder()) return BORDER_NONE; if(!_cellXf.getApplyBorder()) return BORDER_NONE;
@ -365,6 +370,7 @@ public class XSSFCellStyle implements CellStyle {
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
*/ */
@Override
public short getBorderTop() { public short getBorderTop() {
if(!_cellXf.getApplyBorder()) return BORDER_NONE; if(!_cellXf.getApplyBorder()) return BORDER_NONE;
@ -391,6 +397,7 @@ public class XSSFCellStyle implements CellStyle {
* @return the index of the color definition, default value is {@link org.apache.poi.ss.usermodel.IndexedColors#AUTOMATIC} * @return the index of the color definition, default value is {@link org.apache.poi.ss.usermodel.IndexedColors#AUTOMATIC}
* @see org.apache.poi.ss.usermodel.IndexedColors * @see org.apache.poi.ss.usermodel.IndexedColors
*/ */
@Override
public short getBottomBorderColor() { public short getBottomBorderColor() {
XSSFColor clr = getBottomBorderXSSFColor(); XSSFColor clr = getBottomBorderXSSFColor();
return clr == null ? IndexedColors.BLACK.getIndex() : clr.getIndexed(); return clr == null ? IndexedColors.BLACK.getIndex() : clr.getIndexed();
@ -415,6 +422,7 @@ public class XSSFCellStyle implements CellStyle {
* *
* @return the index of the number format * @return the index of the number format
*/ */
@Override
public short getDataFormat() { public short getDataFormat() {
return (short)_cellXf.getNumFmtId(); return (short)_cellXf.getNumFmtId();
} }
@ -425,6 +433,7 @@ public class XSSFCellStyle implements CellStyle {
* *
* @return the number format string * @return the number format string
*/ */
@Override
public String getDataFormatString() { public String getDataFormatString() {
int idx = getDataFormat(); int idx = getDataFormat();
return new XSSFDataFormat(_stylesSource).getFormat((short)idx); return new XSSFDataFormat(_stylesSource).getFormat((short)idx);
@ -439,11 +448,13 @@ public class XSSFCellStyle implements CellStyle {
* @return fill color, default value is {@link org.apache.poi.ss.usermodel.IndexedColors#AUTOMATIC} * @return fill color, default value is {@link org.apache.poi.ss.usermodel.IndexedColors#AUTOMATIC}
* @see org.apache.poi.ss.usermodel.IndexedColors * @see org.apache.poi.ss.usermodel.IndexedColors
*/ */
@Override
public short getFillBackgroundColor() { public short getFillBackgroundColor() {
XSSFColor clr = getFillBackgroundXSSFColor(); XSSFColor clr = getFillBackgroundXSSFColor();
return clr == null ? IndexedColors.AUTOMATIC.getIndex() : clr.getIndexed(); return clr == null ? IndexedColors.AUTOMATIC.getIndex() : clr.getIndexed();
} }
@Override
public XSSFColor getFillBackgroundColorColor() { public XSSFColor getFillBackgroundColorColor() {
return getFillBackgroundXSSFColor(); return getFillBackgroundXSSFColor();
} }
@ -480,15 +491,17 @@ public class XSSFCellStyle implements CellStyle {
* @see IndexedColors * @see IndexedColors
* @return fill color, default value is {@link org.apache.poi.ss.usermodel.IndexedColors#AUTOMATIC} * @return fill color, default value is {@link org.apache.poi.ss.usermodel.IndexedColors#AUTOMATIC}
*/ */
@Override
public short getFillForegroundColor() { public short getFillForegroundColor() {
XSSFColor clr = getFillForegroundXSSFColor(); XSSFColor clr = getFillForegroundXSSFColor();
return clr == null ? IndexedColors.AUTOMATIC.getIndex() : clr.getIndexed(); return clr == null ? IndexedColors.AUTOMATIC.getIndex() : clr.getIndexed();
} }
@Override
public XSSFColor getFillForegroundColorColor() { public XSSFColor getFillForegroundColorColor() {
return getFillForegroundXSSFColor(); return getFillForegroundXSSFColor();
} }
/** /**
* Get the foreground fill color. * Get the foreground fill color.
* *
@ -530,6 +543,7 @@ public class XSSFCellStyle implements CellStyle {
* @see org.apache.poi.ss.usermodel.CellStyle#SQUARES * @see org.apache.poi.ss.usermodel.CellStyle#SQUARES
* @see org.apache.poi.ss.usermodel.CellStyle#DIAMONDS * @see org.apache.poi.ss.usermodel.CellStyle#DIAMONDS
*/ */
@Override
public short getFillPattern() { public short getFillPattern() {
// bug 56295: handle missing applyFill attribute as "true" because Excel does as well // bug 56295: handle missing applyFill attribute as "true" because Excel does as well
if(_cellXf.isSetApplyFill() && !_cellXf.getApplyFill()) return 0; if(_cellXf.isSetApplyFill() && !_cellXf.getApplyFill()) return 0;
@ -569,6 +583,7 @@ public class XSSFCellStyle implements CellStyle {
* @return short - font index * @return short - font index
* @see org.apache.poi.xssf.usermodel.XSSFWorkbook#getFontAt(short) * @see org.apache.poi.xssf.usermodel.XSSFWorkbook#getFontAt(short)
*/ */
@Override
public short getFontIndex() { public short getFontIndex() {
return (short) getFontId(); return (short) getFontId();
} }
@ -578,6 +593,7 @@ public class XSSFCellStyle implements CellStyle {
* *
* @return boolean - whether the cell using this style is hidden * @return boolean - whether the cell using this style is hidden
*/ */
@Override
public boolean getHidden() { public boolean getHidden() {
if (!_cellXf.isSetProtection() || !_cellXf.getProtection().isSetHidden()) { if (!_cellXf.isSetProtection() || !_cellXf.getProtection().isSetHidden()) {
return false; return false;
@ -590,6 +606,7 @@ public class XSSFCellStyle implements CellStyle {
* *
* @return indent - number of spaces * @return indent - number of spaces
*/ */
@Override
public short getIndention() { public short getIndention() {
CTCellAlignment align = _cellXf.getAlignment(); CTCellAlignment align = _cellXf.getAlignment();
return (short)(align == null ? 0 : align.getIndent()); return (short)(align == null ? 0 : align.getIndent());
@ -600,9 +617,18 @@ public class XSSFCellStyle implements CellStyle {
* *
* @return unique index number of the underlying record this style represents * @return unique index number of the underlying record this style represents
*/ */
@Override
public short getIndex() { public short getIndex() {
return (short)this._cellXfId; return (short)this._cellXfId;
} }
/**
* Workaround for places where we need to support more than 32767 cell styles, ideally
* the main getIndex() and others would return int, not short, but that would affect some
* public APIs
*
* @return
*/
protected int getUIndex() { protected int getUIndex() {
return this._cellXfId; return this._cellXfId;
} }
@ -613,6 +639,7 @@ public class XSSFCellStyle implements CellStyle {
* @return the index of the color definition, default value is {@link org.apache.poi.ss.usermodel.IndexedColors#BLACK} * @return the index of the color definition, default value is {@link org.apache.poi.ss.usermodel.IndexedColors#BLACK}
* @see org.apache.poi.ss.usermodel.IndexedColors * @see org.apache.poi.ss.usermodel.IndexedColors
*/ */
@Override
public short getLeftBorderColor() { public short getLeftBorderColor() {
XSSFColor clr = getLeftBorderXSSFColor(); XSSFColor clr = getLeftBorderXSSFColor();
return clr == null ? IndexedColors.BLACK.getIndex() : clr.getIndexed(); return clr == null ? IndexedColors.BLACK.getIndex() : clr.getIndexed();
@ -638,6 +665,7 @@ public class XSSFCellStyle implements CellStyle {
* *
* @return whether the cell using this style are locked * @return whether the cell using this style are locked
*/ */
@Override
public boolean getLocked() { public boolean getLocked() {
if (!_cellXf.isSetProtection() || !_cellXf.getProtection().isSetLocked()) { if (!_cellXf.isSetProtection() || !_cellXf.getProtection().isSetLocked()) {
return true; return true;
@ -651,6 +679,7 @@ public class XSSFCellStyle implements CellStyle {
* @return the index of the color definition, default value is {@link org.apache.poi.ss.usermodel.IndexedColors#BLACK} * @return the index of the color definition, default value is {@link org.apache.poi.ss.usermodel.IndexedColors#BLACK}
* @see org.apache.poi.ss.usermodel.IndexedColors * @see org.apache.poi.ss.usermodel.IndexedColors
*/ */
@Override
public short getRightBorderColor() { public short getRightBorderColor() {
XSSFColor clr = getRightBorderXSSFColor(); XSSFColor clr = getRightBorderXSSFColor();
return clr == null ? IndexedColors.BLACK.getIndex() : clr.getIndexed(); return clr == null ? IndexedColors.BLACK.getIndex() : clr.getIndexed();
@ -683,22 +712,25 @@ public class XSSFCellStyle implements CellStyle {
* *
* @return rotation degrees (between 0 and 180 degrees) * @return rotation degrees (between 0 and 180 degrees)
*/ */
@Override
public short getRotation() { public short getRotation() {
CTCellAlignment align = _cellXf.getAlignment(); CTCellAlignment align = _cellXf.getAlignment();
return (short)(align == null ? 0 : align.getTextRotation()); return (short)(align == null ? 0 : align.getTextRotation());
} }
@Override
public boolean getShrinkToFit() { public boolean getShrinkToFit() {
CTCellAlignment align = _cellXf.getAlignment(); CTCellAlignment align = _cellXf.getAlignment();
return align != null && align.getShrinkToFit(); return align != null && align.getShrinkToFit();
} }
/** /**
* Get the color to use for the top border * Get the color to use for the top border
* *
* @return the index of the color definition, default value is {@link org.apache.poi.ss.usermodel.IndexedColors#BLACK} * @return the index of the color definition, default value is {@link org.apache.poi.ss.usermodel.IndexedColors#BLACK}
* @see org.apache.poi.ss.usermodel.IndexedColors * @see org.apache.poi.ss.usermodel.IndexedColors
*/ */
@Override
public short getTopBorderColor() { public short getTopBorderColor() {
XSSFColor clr = getTopBorderXSSFColor(); XSSFColor clr = getTopBorderXSSFColor();
return clr == null ? IndexedColors.BLACK.getIndex() : clr.getIndexed(); return clr == null ? IndexedColors.BLACK.getIndex() : clr.getIndexed();
@ -727,6 +759,7 @@ public class XSSFCellStyle implements CellStyle {
* @see org.apache.poi.ss.usermodel.CellStyle#VERTICAL_BOTTOM * @see org.apache.poi.ss.usermodel.CellStyle#VERTICAL_BOTTOM
* @see org.apache.poi.ss.usermodel.CellStyle#VERTICAL_JUSTIFY * @see org.apache.poi.ss.usermodel.CellStyle#VERTICAL_JUSTIFY
*/ */
@Override
public short getVerticalAlignment() { public short getVerticalAlignment() {
return (short) (getVerticalAlignmentEnum().ordinal()); return (short) (getVerticalAlignmentEnum().ordinal());
} }
@ -750,6 +783,7 @@ public class XSSFCellStyle implements CellStyle {
* *
* @return a boolean value indicating if the text in a cell should be line-wrapped within the cell. * @return a boolean value indicating if the text in a cell should be line-wrapped within the cell.
*/ */
@Override
public boolean getWrapText() { public boolean getWrapText() {
CTCellAlignment align = _cellXf.getAlignment(); CTCellAlignment align = _cellXf.getAlignment();
return align != null && align.getWrapText(); return align != null && align.getWrapText();
@ -767,6 +801,7 @@ public class XSSFCellStyle implements CellStyle {
* @see org.apache.poi.ss.usermodel.CellStyle#ALIGN_JUSTIFY * @see org.apache.poi.ss.usermodel.CellStyle#ALIGN_JUSTIFY
* @see org.apache.poi.ss.usermodel.CellStyle#ALIGN_CENTER_SELECTION * @see org.apache.poi.ss.usermodel.CellStyle#ALIGN_CENTER_SELECTION
*/ */
@Override
public void setAlignment(short align) { public void setAlignment(short align) {
getCellAlignment().setHorizontal(HorizontalAlignment.values()[align]); getCellAlignment().setHorizontal(HorizontalAlignment.values()[align]);
} }
@ -800,6 +835,7 @@ public class XSSFCellStyle implements CellStyle {
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
*/ */
@Override
public void setBorderBottom(short border) { public void setBorderBottom(short border) {
CTBorder ct = getCTBorder(); CTBorder ct = getCTBorder();
CTBorderPr pr = ct.isSetBottom() ? ct.getBottom() : ct.addNewBottom(); CTBorderPr pr = ct.isSetBottom() ? ct.getBottom() : ct.addNewBottom();
@ -840,6 +876,7 @@ public class XSSFCellStyle implements CellStyle {
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
*/ */
@Override
public void setBorderLeft(short border) { public void setBorderLeft(short border) {
CTBorder ct = getCTBorder(); CTBorder ct = getCTBorder();
CTBorderPr pr = ct.isSetLeft() ? ct.getLeft() : ct.addNewLeft(); CTBorderPr pr = ct.isSetLeft() ? ct.getLeft() : ct.addNewLeft();
@ -880,7 +917,8 @@ public class XSSFCellStyle implements CellStyle {
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
*/ */
public void setBorderRight(short border) { @Override
public void setBorderRight(short border) {
CTBorder ct = getCTBorder(); CTBorder ct = getCTBorder();
CTBorderPr pr = ct.isSetRight() ? ct.getRight() : ct.addNewRight(); CTBorderPr pr = ct.isSetRight() ? ct.getRight() : ct.addNewRight();
if(border == BORDER_NONE) ct.unsetRight(); if(border == BORDER_NONE) ct.unsetRight();
@ -920,7 +958,8 @@ public class XSSFCellStyle implements CellStyle {
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
*/ */
public void setBorderTop(short border) { @Override
public void setBorderTop(short border) {
CTBorder ct = getCTBorder(); CTBorder ct = getCTBorder();
CTBorderPr pr = ct.isSetTop() ? ct.getTop() : ct.addNewTop(); CTBorderPr pr = ct.isSetTop() ? ct.getTop() : ct.addNewTop();
if(border == BORDER_NONE) ct.unsetTop(); if(border == BORDER_NONE) ct.unsetTop();
@ -946,6 +985,7 @@ public class XSSFCellStyle implements CellStyle {
* @param color the index of the color definition * @param color the index of the color definition
* @see org.apache.poi.ss.usermodel.IndexedColors * @see org.apache.poi.ss.usermodel.IndexedColors
*/ */
@Override
public void setBottomBorderColor(short color) { public void setBottomBorderColor(short color) {
XSSFColor clr = new XSSFColor(); XSSFColor clr = new XSSFColor();
clr.setIndexed(color); clr.setIndexed(color);
@ -976,6 +1016,7 @@ public class XSSFCellStyle implements CellStyle {
* *
* @param fmt the index of a data format * @param fmt the index of a data format
*/ */
@Override
public void setDataFormat(short fmt) { public void setDataFormat(short fmt) {
// XSSF supports >32,767 formats // XSSF supports >32,767 formats
setDataFormat(fmt&0xffff); setDataFormat(fmt&0xffff);
@ -1054,6 +1095,7 @@ public class XSSFCellStyle implements CellStyle {
* @param bg - the color to use * @param bg - the color to use
* @see org.apache.poi.ss.usermodel.IndexedColors * @see org.apache.poi.ss.usermodel.IndexedColors
*/ */
@Override
public void setFillBackgroundColor(short bg) { public void setFillBackgroundColor(short bg) {
XSSFColor clr = new XSSFColor(); XSSFColor clr = new XSSFColor();
clr.setIndexed(bg); clr.setIndexed(bg);
@ -1088,6 +1130,7 @@ public class XSSFCellStyle implements CellStyle {
* @param fg the color to use * @param fg the color to use
* @see org.apache.poi.ss.usermodel.IndexedColors * @see org.apache.poi.ss.usermodel.IndexedColors
*/ */
@Override
public void setFillForegroundColor(short fg) { public void setFillForegroundColor(short fg) {
XSSFColor clr = new XSSFColor(); XSSFColor clr = new XSSFColor();
clr.setIndexed(fg); clr.setIndexed(fg);
@ -1153,7 +1196,8 @@ public class XSSFCellStyle implements CellStyle {
* @see #setFillForegroundColor(short) * @see #setFillForegroundColor(short)
* @param fp fill pattern (set to {@link org.apache.poi.ss.usermodel.CellStyle#SOLID_FOREGROUND} to fill w/foreground color) * @param fp fill pattern (set to {@link org.apache.poi.ss.usermodel.CellStyle#SOLID_FOREGROUND} to fill w/foreground color)
*/ */
public void setFillPattern(short fp) { @Override
public void setFillPattern(short fp) {
CTFill ct = getCTFill(); CTFill ct = getCTFill();
CTPatternFill ptrn = ct.isSetPatternFill() ? ct.getPatternFill() : ct.addNewPatternFill(); CTPatternFill ptrn = ct.isSetPatternFill() ? ct.getPatternFill() : ct.addNewPatternFill();
if(fp == NO_FILL && ptrn.isSetPatternType()) ptrn.unsetPatternType(); if(fp == NO_FILL && ptrn.isSetPatternType()) ptrn.unsetPatternType();
@ -1182,6 +1226,7 @@ public class XSSFCellStyle implements CellStyle {
* @see org.apache.poi.xssf.usermodel.XSSFWorkbook#createFont() * @see org.apache.poi.xssf.usermodel.XSSFWorkbook#createFont()
* @see org.apache.poi.xssf.usermodel.XSSFWorkbook#getFontAt(short) * @see org.apache.poi.xssf.usermodel.XSSFWorkbook#getFontAt(short)
*/ */
@Override
public void setFont(Font font) { public void setFont(Font font) {
if(font != null){ if(font != null){
long index = font.getIndex(); long index = font.getIndex();
@ -1197,6 +1242,7 @@ public class XSSFCellStyle implements CellStyle {
* *
* @param hidden - whether the cell using this style should be hidden * @param hidden - whether the cell using this style should be hidden
*/ */
@Override
public void setHidden(boolean hidden) { public void setHidden(boolean hidden) {
if (!_cellXf.isSetProtection()) { if (!_cellXf.isSetProtection()) {
_cellXf.addNewProtection(); _cellXf.addNewProtection();
@ -1209,6 +1255,7 @@ public class XSSFCellStyle implements CellStyle {
* *
* @param indent - number of spaces * @param indent - number of spaces
*/ */
@Override
public void setIndention(short indent) { public void setIndention(short indent) {
getCellAlignment().setIndent(indent); getCellAlignment().setIndent(indent);
} }
@ -1219,6 +1266,7 @@ public class XSSFCellStyle implements CellStyle {
* @param color the index of the color definition * @param color the index of the color definition
* @see org.apache.poi.ss.usermodel.IndexedColors * @see org.apache.poi.ss.usermodel.IndexedColors
*/ */
@Override
public void setLeftBorderColor(short color) { public void setLeftBorderColor(short color) {
XSSFColor clr = new XSSFColor(); XSSFColor clr = new XSSFColor();
clr.setIndexed(color); clr.setIndexed(color);
@ -1249,6 +1297,7 @@ public class XSSFCellStyle implements CellStyle {
* *
* @param locked - whether the cell using this style should be locked * @param locked - whether the cell using this style should be locked
*/ */
@Override
public void setLocked(boolean locked) { public void setLocked(boolean locked) {
if (!_cellXf.isSetProtection()) { if (!_cellXf.isSetProtection()) {
_cellXf.addNewProtection(); _cellXf.addNewProtection();
@ -1262,6 +1311,7 @@ public class XSSFCellStyle implements CellStyle {
* @param color the index of the color definition * @param color the index of the color definition
* @see org.apache.poi.ss.usermodel.IndexedColors * @see org.apache.poi.ss.usermodel.IndexedColors
*/ */
@Override
public void setRightBorderColor(short color) { public void setRightBorderColor(short color) {
XSSFColor clr = new XSSFColor(); XSSFColor clr = new XSSFColor();
clr.setIndexed(color); clr.setIndexed(color);
@ -1301,6 +1351,7 @@ public class XSSFCellStyle implements CellStyle {
* *
* @param rotation - the rotation degrees (between 0 and 180 degrees) * @param rotation - the rotation degrees (between 0 and 180 degrees)
*/ */
@Override
public void setRotation(short rotation) { public void setRotation(short rotation) {
getCellAlignment().setTextRotation(rotation); getCellAlignment().setTextRotation(rotation);
} }
@ -1312,6 +1363,7 @@ public class XSSFCellStyle implements CellStyle {
* @param color the index of the color definition * @param color the index of the color definition
* @see org.apache.poi.ss.usermodel.IndexedColors * @see org.apache.poi.ss.usermodel.IndexedColors
*/ */
@Override
public void setTopBorderColor(short color) { public void setTopBorderColor(short color) {
XSSFColor clr = new XSSFColor(); XSSFColor clr = new XSSFColor();
clr.setIndexed(color); clr.setIndexed(color);
@ -1347,6 +1399,7 @@ public class XSSFCellStyle implements CellStyle {
* @see org.apache.poi.ss.usermodel.CellStyle#VERTICAL_JUSTIFY * @see org.apache.poi.ss.usermodel.CellStyle#VERTICAL_JUSTIFY
* @see org.apache.poi.ss.usermodel.VerticalAlignment * @see org.apache.poi.ss.usermodel.VerticalAlignment
*/ */
@Override
public void setVerticalAlignment(short align) { public void setVerticalAlignment(short align) {
getCellAlignment().setVertical(VerticalAlignment.values()[align]); getCellAlignment().setVertical(VerticalAlignment.values()[align]);
} }
@ -1369,6 +1422,7 @@ public class XSSFCellStyle implements CellStyle {
* *
* @param wrapped a boolean value indicating if the text in a cell should be line-wrapped within the cell. * @param wrapped a boolean value indicating if the text in a cell should be line-wrapped within the cell.
*/ */
@Override
public void setWrapText(boolean wrapped) { public void setWrapText(boolean wrapped) {
getCellAlignment().setWrapText(wrapped); getCellAlignment().setWrapText(wrapped);
} }
@ -1416,7 +1470,8 @@ public class XSSFCellStyle implements CellStyle {
break; break;
} }
} }
@Override
public void setShrinkToFit(boolean shrinkToFit) { public void setShrinkToFit(boolean shrinkToFit) {
getCellAlignment().setShrinkToFit(shrinkToFit); getCellAlignment().setShrinkToFit(shrinkToFit);
} }
@ -1456,6 +1511,7 @@ public class XSSFCellStyle implements CellStyle {
* *
* @return the hash code value for this style * @return the hash code value for this style
*/ */
@Override
public int hashCode(){ public int hashCode(){
return _cellXf.toString().hashCode(); return _cellXf.toString().hashCode();
} }
@ -1466,6 +1522,7 @@ public class XSSFCellStyle implements CellStyle {
* @param o the style to check * @param o the style to check
* @return true if the supplied style is equal to this style * @return true if the supplied style is equal to this style
*/ */
@Override
public boolean equals(Object o){ public boolean equals(Object o){
if(o == null || !(o instanceof XSSFCellStyle)) return false; if(o == null || !(o instanceof XSSFCellStyle)) return false;
@ -1479,6 +1536,7 @@ public class XSSFCellStyle implements CellStyle {
* *
* @return a copy of this style * @return a copy of this style
*/ */
@Override
public Object clone(){ public Object clone(){
CTXf xf = (CTXf)_cellXf.copy(); CTXf xf = (CTXf)_cellXf.copy();

View File

@ -18,15 +18,16 @@
package org.apache.poi.poifs.filesystem; package org.apache.poi.poifs.filesystem;
import java.io.*; import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.util.*; import java.io.IOException;
import java.util.Iterator;
import junit.framework.*;
import org.apache.poi.poifs.property.DirectoryProperty; import org.apache.poi.poifs.property.DirectoryProperty;
import org.apache.poi.poifs.property.DocumentProperty; import org.apache.poi.poifs.property.DocumentProperty;
import junit.framework.TestCase;
/** /**
* Class to test DirectoryNode functionality * Class to test DirectoryNode functionality
* *
@ -51,7 +52,7 @@ public final class TestDirectoryNode extends TestCase {
// verify that getEntries behaves correctly // verify that getEntries behaves correctly
int count = 0; int count = 0;
Iterator iter = node.getEntries(); Iterator<Entry> iter = node.getEntries();
while (iter.hasNext()) while (iter.hasNext())
{ {
@ -106,7 +107,7 @@ public final class TestDirectoryNode extends TestCase {
// verify that getEntries behaves correctly // verify that getEntries behaves correctly
int count = 0; int count = 0;
Iterator iter = node.getEntries(); Iterator<Entry> iter = node.getEntries();
while (iter.hasNext()) while (iter.hasNext())
{ {
@ -160,7 +161,7 @@ public final class TestDirectoryNode extends TestCase {
// verify cannot delete the root directory // verify cannot delete the root directory
assertFalse(root.delete()); assertFalse(root.delete());
assertTrue(root.isEmpty()); assertTrue(root.isEmpty());
DirectoryEntry dir = fs.createDirectory("myDir"); DirectoryEntry dir = fs.createDirectory("myDir");
assertFalse(root.isEmpty()); assertFalse(root.isEmpty());
@ -169,7 +170,7 @@ public final class TestDirectoryNode extends TestCase {
// verify can delete empty directory // verify can delete empty directory
assertFalse(root.delete()); assertFalse(root.delete());
assertTrue(dir.delete()); assertTrue(dir.delete());
// Now look at a non-empty one // Now look at a non-empty one
dir = fs.createDirectory("NextDir"); dir = fs.createDirectory("NextDir");
DocumentEntry doc = DocumentEntry doc =
@ -181,14 +182,16 @@ public final class TestDirectoryNode extends TestCase {
// verify cannot delete non-empty directory // verify cannot delete non-empty directory
assertFalse(dir.delete()); assertFalse(dir.delete());
// but we can delete it if we remove the document // but we can delete it if we remove the document
assertTrue(doc.delete()); assertTrue(doc.delete());
assertTrue(dir.isEmpty()); assertTrue(dir.isEmpty());
assertTrue(dir.delete()); assertTrue(dir.delete());
// It's really gone! // It's really gone!
assertTrue(root.isEmpty()); assertTrue(root.isEmpty());
fs.close();
} }
/** /**
@ -211,5 +214,7 @@ public final class TestDirectoryNode extends TestCase {
assertTrue(dir.renameTo("FirstDir")); assertTrue(dir.renameTo("FirstDir"));
assertTrue(dir2.renameTo("foo")); assertTrue(dir2.renameTo("foo"));
assertEquals("foo", dir2.getName()); assertEquals("foo", dir2.getName());
fs.close();
} }
} }