diff options
Diffstat (limited to 'src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java')
-rw-r--r-- | src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java | 217 |
1 files changed, 158 insertions, 59 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java index 0e9e573b45..7b4494661d 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java @@ -23,66 +23,165 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName; * XSSF Implementation of a Named Range */ public class XSSFName implements Name { - private XSSFWorkbook workbook; - private CTDefinedName ctName; - - protected XSSFName(XSSFWorkbook workbook) { - this.workbook = workbook; - this.ctName = CTDefinedName.Factory.newInstance(); - } - protected XSSFName(CTDefinedName name, XSSFWorkbook workbook) { - this.workbook = workbook; - this.ctName = name; - } - - public boolean isFunctionName() { - // TODO Figure out how HSSF does this, and do the same! - return ctName.getFunction(); // maybe this works - verify - } - /** - * Returns the underlying named range object - */ - protected CTDefinedName getCTName() { - return ctName; - } - - public String getNameName() { - return ctName.getName(); - } - public void setNameName(String nameName) { - ctName.setName(nameName); - } + /** + * The following built-in names are defined in this SpreadsheetML + * specification: + * Built-in names reserved by SpreadsheetML begin with "_xlnm.". End users shall not use + * this string for custom names in the user interface. + */ - public String getReference() { - return ctName.getStringValue(); - } - public void setReference(String ref) { - ctName.setStringValue(ref); - } - - public String getSheetName() { - if(ctName.isSetLocalSheetId()) { - // Given as explicit sheet id - long sheetId = ctName.getLocalSheetId(); - if(sheetId >= 0) { - return workbook.getSheetName((int)sheetId); - } - } else { - // Is it embeded in the reference itself? - int excl = getReference().indexOf('!'); - if(excl > -1) { - return getReference().substring(0, excl); - } - } - - // Not given at all - return null; - } + /** + * this defined name specifies the workbook's print area + */ + public final static String BUILTIN_PRINT_AREA = "_xlnm.Print_Area"; - public String getComment() { - return ctName.getComment(); - } - public void setComment(String comment) { - ctName.setComment(comment); + /** + * this defined name specifies the row(s) or column(s) to repeat + * at the top of each printed page. + */ + public final static String BUILTIN_PRINT_TITLE = "_xlnm.Print_Titles"; + + //Filter & Advanced Filter + + /** + * this defined name refers to a range containing the criteria values + * to be used in applying an advanced filter to a range of data + */ + public final static String BUILTIN_CRITERIA = "_xlnm.Criteria:"; + + + /** + * this defined name refers to the range containing the filtered + * output values resulting from applying an advanced filter criteria to a source + * range + */ + public final static String BUILTIN_EXTRACT = "_xlnm.Extract:"; + + /** + * can be one of the following + * a. this defined name refers to a range to which an advanced filter has been + * applied. This represents the source data range, unfiltered. + * b. This defined name refers to a range to which an AutoFilter has been + * applied + */ + public final static String BUILTIN_FILTER_DB = "_xlnm._FilterDatabase:"; + + + //Miscellaneous + + /** + * the defined name refers to a consolidation area + */ + public final static String BUILTIN_CONSOLIDATE_AREA = "_xlnm.Consolidate_Area"; + + /** + * the range specified in the defined name is from a database data source + */ + public final static String BUILTIN_DATABASE = "_xlnm.Database"; + + /** + * the defined name refers to a sheet title. + */ + public final static String BUILTIN_SHEET_TITLE = "_xlnm.Sheet_Title"; + + private XSSFWorkbook workbook; + private CTDefinedName ctName; + + protected XSSFName(XSSFWorkbook workbook) { + this.workbook = workbook; + this.ctName = CTDefinedName.Factory.newInstance(); + } + protected XSSFName(CTDefinedName name, XSSFWorkbook workbook) { + this.workbook = workbook; + this.ctName = name; + } + + public boolean isFunctionName() { + // TODO Figure out how HSSF does this, and do the same! + return ctName.getFunction(); // maybe this works - verify + } + /** + * Returns the underlying named range object + */ + protected CTDefinedName getCTName() { + return ctName; + } + + public String getNameName() { + return ctName.getName(); + } + public void setNameName(String nameName) { + ctName.setName(nameName); + } + + public String getReference() { + return ctName.getStringValue(); + } + public void setReference(String ref) { + ctName.setStringValue(ref); + } + + public void setLocalSheetId(int sheetId) { + ctName.setLocalSheetId(sheetId); + } + + public int getLocalSheetId() { + return (int)ctName.getLocalSheetId(); + } + + + public void setFunction(boolean value) { + ctName.setFunction(value); + } + + public boolean getFunction() { + return ctName.getFunction(); + } + + public void setFunctionGroupId(int functionGroupId) { + ctName.setFunctionGroupId(functionGroupId); + } + + public int getFunctionGroupId() { + return (int)ctName.getFunctionGroupId(); + } + + public String getSheetName() { + if(ctName.isSetLocalSheetId()) { + // Given as explicit sheet id + long sheetId = ctName.getLocalSheetId(); + if(sheetId >= 0) { + return workbook.getSheetName((int)sheetId); + } + } else { + // Is it embeded in the reference itself? + int excl = getReference().indexOf('!'); + if(excl > -1) { + return getReference().substring(0, excl); + } } + + // Not given at all + return null; + } + + public String getComment() { + return ctName.getComment(); + } + public void setComment(String comment) { + ctName.setComment(comment); + } + + + public int hashCode(){ + return ctName.toString().hashCode(); + } + + public boolean equals(Object o){ + if(!(o instanceof XSSFName)) return false; + XSSFName cf = (XSSFName)o; + return ctName.toString().equals(cf.getCTName().toString()); + } + + } |