mirror of https://github.com/apache/poi.git
Merged revisions 696501 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk ........ r696501 | josh | 2008-09-17 15:35:09 -0700 (Wed, 17 Sep 2008) | 1 line Small tweak to NamePtg and Ref3DPtg ........ git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@696831 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
33fc701580
commit
235eb62f53
|
@ -319,7 +319,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 '"
|
||||
|
@ -388,7 +388,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 {
|
||||
if(book instanceof HSSFWorkbook) {
|
||||
nameToken = ((HSSFWorkbook)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();
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
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;
|
||||
|
||||
|
@ -31,33 +30,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, 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 */
|
||||
|
@ -75,9 +55,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){
|
||||
|
|
|
@ -48,7 +48,7 @@ public class HSSFName implements Name {
|
|||
* @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