return workbook;
}
- /** gets the total number of named ranges in the workboko
- * @return number of named ranges
- */
public int getNumberOfNames(){
int result = names.size();
return result;
}
+
+ public HSSFName getName(String name) {
+ int nameIndex = getNameIndex(name);
+ if (nameIndex < 0) {
+ return null;
+ }
+ return (HSSFName) names.get(nameIndex);
+ }
- /** gets the Named range
- * @param index position of the named range
- * @return named range high level
- */
- public HSSFName getNameAt(int index){
- HSSFName result = (HSSFName) names.get(index);
-
- return result;
+ public HSSFName getNameAt(int nameIndex) {
+ int nNames = names.size();
+ if (nNames < 1) {
+ throw new IllegalStateException("There are no defined names in this workbook");
+ }
+ if (nameIndex < 0 || nameIndex > nNames) {
+ throw new IllegalArgumentException("Specified name index " + nameIndex
+ + " is outside the allowable range (0.." + (nNames-1) + ").");
+ }
+ return (HSSFName) names.get(nameIndex);
}
+
public NameRecord getNameRecord(int nameIndex) {
return getWorkbook().getNameRecord(nameIndex);
}
return newName;
}
- /** gets the named range index by his name
- * <i>Note:</i>Excel named ranges are case-insensitive and
- * this method performs a case-insensitive search.
- *
- * @param name named range name
- * @return named range index
- */
- public int getNameIndex(String name)
- {
- int retval = -1;
+ public int getNameIndex(String name) {
- for (int k = 0; k < names.size(); k++)
- {
+ for (int k = 0; k < names.size(); k++) {
String nameName = getNameName(k);
- if (nameName.equalsIgnoreCase(name))
- {
- retval = k;
- break;
+ if (nameName.equalsIgnoreCase(name)) {
+ return k;
}
}
- return retval;
+ return -1;
}
- /** remove the named range by his index
- * @param index named range index (0 based)
- */
public void removeName(int index){
names.remove(index);
workbook.removeName(index);
return formatter;
}
- /** remove the named range by his name
- * @param name named range name
- */
- public void removeName(String name){
+
+ public void removeName(String name) {
int index = getNameIndex(name);
removeName(index);
-
}
public HSSFPalette getCustomPalette()
void write(OutputStream stream) throws IOException;
/**
- * Gets the total number of named ranges in the workbook
- *
- * @return number of named ranges
+ * @return the total number of defined names in this workbook
*/
int getNumberOfNames();
/**
- * Gets the Named range
- *
- * @param index position of the named range (0-based)
- * @return named range high level
+ * @param name the name of the defined name
+ * @return the defined name with the specified name. <code>null</code> if not found.
*/
- Name getNameAt(int index);
+ Name getName(String name);
+ /**
+ * @param nameIndex position of the named range (0-based)
+ * @return the defined name at the specified index
+ * @throws IllegalArgumentException if the supplied index is invalid
+ */
+ Name getNameAt(int nameIndex);
/**
- * Creates a new named range in this workbook
+ * Creates a new (uninitialised) defined name in this workbook
*
- * @return new named range object
+ * @return new defined name object
*/
Name createName();
/**
- * Gets the named range index by his name
- * <i>Note:</i>Excel named ranges are case-insensitive and
- * this method performs a case-insensitive search.
- *
- * @param name named range name
- * @return named range index
- */
- int getNameIndex(String name);
+ * Gets the defined name index by name<br/>
+ * <i>Note:</i> Excel defined names are case-insensitive and
+ * this method performs a case-insensitive search.
+ *
+ * @param name the name of the defined name
+ * @return zero based index of the defined name. <tt>-1</tt> if not found.
+ */
+ int getNameIndex(String name);
- /**
- * Remove the named range by his index
- *
- * @param index named range index (0 based)
- */
- void removeName(int index);
+ /**
+ * Remove the defined name at the specified index
+ *
+ * @param index named range index (0 based)
+ */
+ void removeName(int index);
/**
- * Remove the named range by his name
+ * Remove a defined name by name
*
- * @param name named range name
+ * @param name the name of the defined name
*/
void removeName(String name);
return font;
}
- /**
- * Create a new named range and add it to the workbook's names table
- *
- * @return named range high level
- */
public XSSFName createName() {
XSSFName name = new XSSFName(CTDefinedName.Factory.newInstance(), this);
namedRanges.add(name);
return stylesSource.getFontAt(idx);
}
- /**
- * Gets the Named range at the given index number
- *
- * @param index position of the named range
- * @return XSSFName at the index
- */
- public XSSFName getNameAt(int index) {
- return namedRanges.get(index);
+ public XSSFName getName(String name) {
+ int nameIndex = getNameIndex(name);
+ if (nameIndex < 0) {
+ return null;
+ }
+ return namedRanges.get(nameIndex);
+ }
+
+ public XSSFName getNameAt(int nameIndex) {
+ int nNames = namedRanges.size();
+ if (nNames < 1) {
+ throw new IllegalStateException("There are no defined names in this workbook");
+ }
+ if (nameIndex < 0 || nameIndex > nNames) {
+ throw new IllegalArgumentException("Specified name index " + nameIndex
+ + " is outside the allowable range (0.." + (nNames-1) + ").");
+ }
+ return namedRanges.get(nameIndex);
}
/**
* @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
*/
- public String getPrintArea(int sheetIndex) {
+ public String getPrintArea(int sheetIndex) {
XSSFName name = getBuiltInName(XSSFName.BUILTIN_PRINT_AREA, sheetIndex);
if (name == null) return null;
//adding one here because 0 indicates a global named region; doesnt make sense for print areas
return getPackagePart().getContentType().equals(XSSFRelation.MACROS_WORKBOOK.getContentType());
}
- /**
- * Removes the name by its index
- *
- * @param nameIndex 0-based index of the name to remove.
- */
public void removeName(int nameIndex) {
namedRanges.remove(nameIndex);
}
- /**
- * Remove the named range by its name
- *
- * @param name named range name
- * @throws IllegalArgumentException if the name was not found
- */
public void removeName(String name) {
for (int i = 0; i < namedRanges.size(); i++) {
XSSFName nm = namedRanges.get(i);
int lastSheetIx = sheets.size() - 1;
if (index < 0 || index > lastSheetIx) {
throw new IllegalArgumentException("Sheet index ("
- + index +") is out of range (0.." + lastSheetIx + ")");
+ + index +") is out of range (0.." + lastSheetIx + ")");
}
}
public void setRepeatingRowsAndColumns(int sheetIndex,
int startColumn, int endColumn,
int startRow, int endRow) {
- // Check arguments
+ // Check arguments
if ((startColumn == -1 && endColumn != -1) || startColumn < -1 || endColumn < -1 || startColumn > endColumn)
throw new IllegalArgumentException("Invalid column range specification");
if ((startRow == -1 && endRow != -1) || startRow < -1 || endRow < -1 || startRow > endRow)
}
public boolean isHidden() {
- throw new RuntimeException("Not implemented yet");
+ throw new RuntimeException("Not implemented yet");
}
public void setHidden(boolean hiddenFlag) {
- throw new RuntimeException("Not implemented yet");
+ throw new RuntimeException("Not implemented yet");
}
public boolean isSheetHidden(int sheetIx) {