aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java
diff options
context:
space:
mode:
authorYegor Kozlov <yegor@apache.org>2008-12-04 18:38:00 +0000
committerYegor Kozlov <yegor@apache.org>2008-12-04 18:38:00 +0000
commit0b62c3fba9cd34324a985f503d9dc6a82f9500c5 (patch)
treed38991d0c5e28d654c43b6f465a2429479ec3069 /src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java
parent5f02a46753c8757cb60e29c7421de4c6daae0921 (diff)
downloadpoi-0b62c3fba9cd34324a985f503d9dc6a82f9500c5.tar.gz
poi-0b62c3fba9cd34324a985f503d9dc6a82f9500c5.zip
1. Support sheet-level names2. Fixed XSSFCell to properly handle cell references with column numbers up to XFD3. when pasring formula, HSSFName.setRefersToFormula must set type of operands to Ptg.CLASS_REF, otherwise created named don't appear in the dropdown to the left of formula bar in Excel
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@723392 13f79535-47bb-0310-9956-ffa450edef68
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.java22
1 files changed, 15 insertions, 7 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 1813892ba9..d9761a0014 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java
@@ -170,9 +170,8 @@ public final class XSSFName implements Name {
*/
public void setRefersToFormula(String formulaText) {
XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(workbook);
- Ptg[] ptgs;
try {
- ptgs = FormulaParser.parse(formulaText, fpb, FormulaType.CELL); // TODO - use type NAMEDRANGE
+ Ptg[] ptgs = FormulaParser.parse(formulaText, fpb, FormulaType.NAMEDRANGE);
} catch (RuntimeException e) {
if (e.getClass().getName().startsWith(FormulaParser.class.getName())) {
throw new IllegalArgumentException("Unparsable formula '" + formulaText + "'", e);
@@ -195,11 +194,20 @@ public final class XSSFName implements Name {
/**
* Tell Excel that this name applies to the worksheet with the specified index instead of the entire workbook.
*
- * @param sheetId the sheet index this name applies to, -1 unsets this property making the name workbook-global
+ * @param index the sheet index this name applies to, -1 unsets this property making the name workbook-global
*/
- public void setLocalSheetId(int sheetId) {
- if(sheetId == -1) ctName.unsetLocalSheetId();
- else ctName.setLocalSheetId(sheetId);
+ public void setSheetIndex(int index) {
+ int lastSheetIx = workbook.getNumberOfSheets() - 1;
+ if (index < -1 || index > lastSheetIx) {
+ throw new IllegalArgumentException("Sheet index (" + index +") is out of range" +
+ (lastSheetIx == -1 ? "" : (" (0.." + lastSheetIx + ")")));
+ }
+
+ if(index == -1) {
+ if(ctName.isSetLocalSheetId()) ctName.unsetLocalSheetId();
+ } else {
+ ctName.setLocalSheetId(index);
+ }
}
/**
@@ -207,7 +215,7 @@ public final class XSSFName implements Name {
*
* @return the sheet index this name applies to, -1 if this name applies to the entire workbook
*/
- public int getLocalSheetId() {
+ public int getSheetIndex() {
return ctName.isSetLocalSheetId() ? (int) ctName.getLocalSheetId() : -1;
}