KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > usermodel > HSSFName


1 /* ====================================================================
2    Copyright 2003-2004 Apache Software Foundation
3
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7
8        http://www.apache.org/licenses/LICENSE-2.0
9
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15 ==================================================================== */

16
17 package org.apache.poi.hssf.usermodel;
18
19 import org.apache.poi.hssf.model.Workbook;
20 import org.apache.poi.hssf.record.NameRecord;
21 import org.apache.poi.hssf.util.RangeAddress;
22
23 /**
24  * Title: High Level Represantion of Named Range <P>
25  * REFERENCE: <P>
26  * @author Libin Roman (Vista Portal LDT. Developer)
27  */

28
29 public class HSSFName {
30     private Workbook book;
31     private NameRecord name;
32     
33     /** Creates new HSSFName - called by HSSFWorkbook to create a sheet from
34      * scratch.
35      *
36      * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#createName()
37      * @param name the Name Record
38      * @param book lowlevel Workbook object associated with the sheet.
39      */

40     
41     protected HSSFName(Workbook book, NameRecord name) {
42         this.book = book;
43         this.name = name;
44     }
45     
46     /** Get the sheets name which this named range is referenced to
47      * @return sheet name, which this named range refered to
48      */

49
50     public String JavaDoc getSheetName() {
51         String JavaDoc result ;
52         short indexToExternSheet = name.getExternSheetNumber();
53         
54         result = book.findSheetNameFromExternSheet(indexToExternSheet);
55         
56         return result;
57     }
58     
59     /**
60      * gets the name of the named range
61      * @return named range name
62      */

63
64     public String JavaDoc getNameName(){
65         String JavaDoc result = name.getNameText();
66         
67         return result;
68     }
69     
70     /**
71      * sets the name of the named range
72      * @param nameName named range name to set
73      */

74
75     public void setNameName(String JavaDoc nameName){
76         name.setNameText(nameName);
77         name.setNameTextLength((byte)nameName.length());
78     }
79
80     /**
81      * gets the reference of the named range
82      * @return reference of the named range
83      */

84
85     public String JavaDoc getReference() {
86         String JavaDoc result;
87         result = name.getAreaReference(book);
88
89         return result;
90     }
91
92     
93
94     /**
95      * sets the sheet name which this named range referenced to
96      * @param sheetName the sheet name of the reference
97      */

98
99     private void setSheetName(String JavaDoc sheetName){
100         int sheetNumber = book.getSheetIndex(sheetName);
101
102         short externSheetNumber = book.checkExternSheet(sheetNumber);
103         name.setExternSheetNumber(externSheetNumber);
104 // name.setIndexToSheet(externSheetNumber);
105

106     }
107
108   
109     /**
110      * sets the reference of this named range
111      * @param ref the reference to set
112      */

113
114     public void setReference(String JavaDoc ref){
115
116         RangeAddress ra = new RangeAddress(ref);
117
118         String JavaDoc sheetName = ra.getSheetName();
119
120         if (ra.hasSheetName()) {
121             setSheetName(sheetName);
122         }
123
124         //allow the poi utilities to parse it out
125
name.setAreaReference(ref);
126
127     }
128
129 }
130
Popular Tags