1 16 17 package org.apache.poi.hssf.record.formula; 18 19 import org.apache.poi.util.LittleEndian; 20 import org.apache.poi.hssf.model.Workbook; 21 import org.apache.poi.hssf.record.NameRecord; 22 23 28 29 public class NamePtg 30 extends Ptg 31 { 32 public final static short sid = 0x23; 33 private final static int SIZE = 5; 34 private short field_1_label_index; 35 private short field_2_zero; boolean xtra=false; 37 38 39 private NamePtg() { 40 } 42 43 44 45 public NamePtg(String name, Workbook book) 46 { 47 final short n = (short) (book.getNumNames() + 1); 48 NameRecord rec; 49 for (short i = 1; i < n; i++) { 50 rec = book.getNameRecord(i - 1); 51 if (name.equals(rec.getNameText())) { 52 field_1_label_index = i; 53 return; 54 } 55 } 56 rec = new NameRecord(); 57 rec.setNameText(name); 58 rec.setNameTextLength((byte) name.length()); 59 book.addName(rec); 60 field_1_label_index = n; 61 } 62 63 64 65 public NamePtg(byte [] data, int offset) 66 { 67 offset++; 68 field_1_label_index = LittleEndian.getShort(data, offset ); 70 field_2_zero = LittleEndian.getShort(data, offset + 2); 71 } 73 74 public void writeBytes(byte [] array, int offset) 75 { 76 array[offset+0]= (byte) (sid + ptgClass); 77 LittleEndian.putShort(array,offset+1,field_1_label_index); 78 LittleEndian.putShort(array,offset+3, field_2_zero); 79 } 80 81 public int getSize() 82 { 83 return SIZE; 84 } 85 86 public String toFormulaString(Workbook book) 87 { 88 NameRecord rec = book.getNameRecord(field_1_label_index - 1); 89 return rec.getNameText(); 90 } 91 92 public byte getDefaultOperandClass() {return Ptg.CLASS_REF;} 93 94 public Object clone() { 95 NamePtg ptg = new NamePtg(); 96 ptg.field_1_label_index = field_1_label_index; 97 ptg.field_2_zero = field_2_zero; 98 return ptg; 99 } 100 } 101 | Popular Tags |