Small tweak to NamePtg and Ref3DPtg
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@696501 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6ff869b74b
commit
59311a17e8
@ -318,7 +318,7 @@ public final class FormulaParser {
|
||||
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 '"
|
||||
@ -389,7 +389,7 @@ public final class FormulaParser {
|
||||
|
||||
// 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 {
|
||||
|
||||
nameToken = book.getNameXPtg(name);
|
||||
|
@ -447,7 +447,7 @@ public final class NameRecord extends Record {
|
||||
/** gets the extern sheet number
|
||||
* @return extern sheet index
|
||||
*/
|
||||
public short getExternSheetNumber(){
|
||||
public int getExternSheetNumber(){
|
||||
if (field_13_name_definition.length < 1) {
|
||||
return 0;
|
||||
}
|
||||
@ -513,7 +513,7 @@ public final class NameRecord extends Record {
|
||||
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();
|
||||
|
@ -31,33 +31,14 @@ public final class NamePtg extends OperandPtg {
|
||||
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, HSSFWorkbook 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(HSSFWorkbook 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;
|
||||
}
|
||||
}
|
||||
|
||||
HSSFName 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 */
|
||||
@ -75,9 +56,9 @@ public final class NamePtg extends OperandPtg {
|
||||
}
|
||||
|
||||
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() {
|
||||
|
@ -44,7 +44,7 @@ public final class Ref3DPtg extends RefPtgBase {
|
||||
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());
|
||||
@ -65,17 +65,17 @@ public final class Ref3DPtg extends RefPtgBase {
|
||||
}
|
||||
|
||||
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){
|
||||
|
@ -47,7 +47,7 @@ public final class HSSFName {
|
||||
* @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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user