for(int i = 0; i < book.getNumberOfNames(); i++) {
// named range name matching is case insensitive
if(book.getNameAt(i).getNameName().equalsIgnoreCase(name)) {
- return new NamePtg(name, book);
+ return new NamePtg(i);
}
}
throw new FormulaParseException("Specified named range '"
// calls to user-defined functions within the workbook
// get a Name token which points to a defined name record
- nameToken = new NamePtg(name, this.book);
+ nameToken = new NamePtg(nameIndex);
} else {
if(book instanceof HSSFWorkbook) {
nameToken = ((HSSFWorkbook)book).getNameXPtg(name);
/** gets the extern sheet number
* @return extern sheet index
*/
- public short getExternSheetNumber(){
+ public int getExternSheetNumber(){
if (field_13_name_definition.length < 1) {
return 0;
}
oldPtg = field_13_name_definition[0];
}
List temp = new ArrayList();
- short externSheetIndex = 0;
+ int externSheetIndex = 0;
if (oldPtg.getClass() == Area3DPtg.class){
externSheetIndex = ((Area3DPtg) oldPtg).getExternSheetIndex();
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.record.RecordInputStream;
-import org.apache.poi.ss.usermodel.Name;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.util.LittleEndian;
public final static short sid = 0x23;
private final static int SIZE = 5;
/** one-based index to defined name record */
- private short field_1_label_index;
+ private int field_1_label_index;
private short field_2_zero; // reserved must be 0
/**
- * Creates new NamePtg and sets its name index to that of the corresponding defined name record
- * in the workbook. The search for the name record is case insensitive. If it is not found,
- * it gets created.
+ * @param nameIndex zero-based index to name within workbook
*/
- public NamePtg(String name, Workbook book) {
- field_1_label_index = (short)(1+getOrCreateNameRecord(book, name)); // convert to 1-based
- }
- /**
- * @return zero based index of the found or newly created defined name record.
- */
- private static final int getOrCreateNameRecord(Workbook book, String name) {
- // perhaps this logic belongs in Workbook?
- int countNames = book.getNumberOfNames();
- for (int i = 0; i < countNames; i++) {
- if(name.equalsIgnoreCase( book.getNameName(i) )) {
- return i;
- }
- }
-
- Name nameObj = book.createName();
- nameObj.setNameName(name);
-
- return countNames;
+ public NamePtg(int nameIndex) {
+ field_1_label_index = 1+nameIndex; // convert to 1-based
}
/** Creates new NamePtg */
}
public void writeBytes(byte [] array, int offset) {
- array[offset+0]= (byte) (sid + getPtgClass());
- LittleEndian.putShort(array,offset+1,field_1_label_index);
- LittleEndian.putShort(array,offset+3, field_2_zero);
+ LittleEndian.putByte(array, offset + 0, sid + getPtgClass());
+ LittleEndian.putUShort(array, offset + 1, field_1_label_index);
+ LittleEndian.putUShort(array, offset + 3, field_2_zero);
}
public int getSize() {
readCoordinates(in);
}
- public Ref3DPtg(String cellref, short externIdx ) {
+ public Ref3DPtg(String cellref, int externIdx ) {
CellReference c= new CellReference(cellref);
setRow(c.getRow());
setColumn(c.getCol());
}
public void writeBytes(byte [] array, int offset) {
- array[ 0 + offset ] = (byte) (sid + getPtgClass());
- LittleEndian.putShort(array, 1 + offset , getExternSheetIndex());
- writeCoordinates(array, offset+3);
+ LittleEndian.putByte(array, 0 + offset, sid + getPtgClass());
+ LittleEndian.putUShort(array, 1 + offset, getExternSheetIndex());
+ writeCoordinates(array, offset + 3);
}
public int getSize() {
return SIZE;
}
- public short getExternSheetIndex(){
- return (short)field_1_index_extern_sheet;
+ public int getExternSheetIndex(){
+ return field_1_index_extern_sheet;
}
public void setExternSheetIndex(int index){
* @return sheet name, which this named range referred to
*/
public String getSheetName() {
- short indexToExternSheet = _definedNameRec.getExternSheetNumber();
+ int indexToExternSheet = _definedNameRec.getExternSheetNumber();
return _book.getWorkbook().findSheetNameFromExternSheet(indexToExternSheet);
}