2002-01-30 21:22:28 -05:00
|
|
|
/* ====================================================================
|
2004-08-23 04:52:54 -04:00
|
|
|
Copyright 2003-2004 Apache Software Foundation
|
2004-04-09 09:05:39 -04:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
==================================================================== */
|
2002-01-30 21:22:28 -05:00
|
|
|
|
|
|
|
package org.apache.poi.hssf.record.formula;
|
|
|
|
|
|
|
|
import org.apache.poi.util.LittleEndian;
|
2003-08-31 02:16:57 -04:00
|
|
|
import org.apache.poi.hssf.model.Workbook;
|
|
|
|
import org.apache.poi.hssf.record.NameRecord;
|
2002-01-30 21:22:28 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author andy
|
2002-09-04 20:26:28 -04:00
|
|
|
* @author Jason Height (jheight at chariot dot net dot au)
|
2002-01-30 21:22:28 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
public class NamePtg
|
|
|
|
extends Ptg
|
|
|
|
{
|
|
|
|
public final static short sid = 0x23;
|
2003-07-27 15:15:16 -04:00
|
|
|
private final static int SIZE = 5;
|
|
|
|
private short field_1_label_index;
|
|
|
|
private short field_2_zero; // reserved must be 0
|
|
|
|
boolean xtra=false;
|
2002-01-30 21:22:28 -05:00
|
|
|
|
2002-09-04 20:26:28 -04:00
|
|
|
|
|
|
|
private NamePtg() {
|
|
|
|
//Required for clone methods
|
|
|
|
}
|
|
|
|
|
2002-01-30 21:22:28 -05:00
|
|
|
/** Creates new NamePtg */
|
|
|
|
|
2003-08-31 02:16:57 -04:00
|
|
|
public NamePtg(String name, Workbook book)
|
2002-01-30 21:22:28 -05:00
|
|
|
{
|
2003-08-31 02:16:57 -04:00
|
|
|
final short n = (short) (book.getNumNames() + 1);
|
|
|
|
NameRecord rec;
|
|
|
|
for (short i = 1; i < n; i++) {
|
|
|
|
rec = book.getNameRecord(i - 1);
|
|
|
|
if (name.equals(rec.getNameText())) {
|
|
|
|
field_1_label_index = i;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rec = new NameRecord();
|
|
|
|
rec.setNameText(name);
|
|
|
|
rec.setNameTextLength((byte) name.length());
|
|
|
|
book.addName(rec);
|
|
|
|
field_1_label_index = n;
|
2002-01-30 21:22:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Creates new NamePtg */
|
|
|
|
|
|
|
|
public NamePtg(byte [] data, int offset)
|
|
|
|
{
|
|
|
|
offset++;
|
2003-07-27 15:15:16 -04:00
|
|
|
//field_1_ixti = LittleEndian.getShort(data, offset);
|
|
|
|
field_1_label_index = LittleEndian.getShort(data, offset );
|
|
|
|
field_2_zero = LittleEndian.getShort(data, offset + 2);
|
|
|
|
//if (data[offset+6]==0) xtra=true;
|
2002-01-30 21:22:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public void writeBytes(byte [] array, int offset)
|
|
|
|
{
|
2003-07-27 15:15:16 -04:00
|
|
|
array[offset+0]= (byte) (sid + ptgClass);
|
|
|
|
LittleEndian.putShort(array,offset+1,field_1_label_index);
|
|
|
|
LittleEndian.putShort(array,offset+3, field_2_zero);
|
2002-01-30 21:22:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getSize()
|
|
|
|
{
|
|
|
|
return SIZE;
|
|
|
|
}
|
|
|
|
|
2003-08-31 02:16:57 -04:00
|
|
|
public String toFormulaString(Workbook book)
|
2002-01-30 21:22:28 -05:00
|
|
|
{
|
2003-08-31 02:16:57 -04:00
|
|
|
NameRecord rec = book.getNameRecord(field_1_label_index - 1);
|
|
|
|
return rec.getNameText();
|
2002-01-30 21:22:28 -05:00
|
|
|
}
|
2002-05-27 17:00:12 -04:00
|
|
|
|
2003-08-31 02:16:57 -04:00
|
|
|
public byte getDefaultOperandClass() {return Ptg.CLASS_REF;}
|
2002-09-04 20:26:28 -04:00
|
|
|
|
|
|
|
public Object clone() {
|
|
|
|
NamePtg ptg = new NamePtg();
|
2003-07-27 15:15:16 -04:00
|
|
|
ptg.field_1_label_index = field_1_label_index;
|
|
|
|
ptg.field_2_zero = field_2_zero;
|
2002-09-04 20:26:28 -04:00
|
|
|
return ptg;
|
|
|
|
}
|
2002-01-30 21:22:28 -05:00
|
|
|
}
|