1 19 20 package jxl.read.biff; 21 22 import common.Assert; 23 import common.Logger; 24 25 import jxl.LabelCell; 26 import jxl.CellType; 27 import jxl.StringFormulaCell; 28 import jxl.WorkbookSettings; 29 import jxl.biff.Type; 30 import jxl.biff.IntegerHelper; 31 import jxl.biff.StringHelper; 32 import jxl.biff.FormattingRecords; 33 import jxl.biff.FormulaData; 34 import jxl.biff.WorkbookMethods; 35 import jxl.biff.formula.FormulaParser; 36 import jxl.biff.formula.ExternalSheet; 37 import jxl.biff.formula.FormulaException; 38 39 43 public class SharedStringFormulaRecord extends BaseSharedFormulaRecord 44 implements LabelCell, FormulaData, StringFormulaCell 45 { 46 49 private static Logger logger = Logger.getLogger 50 (SharedStringFormulaRecord.class); 51 52 55 private String value; 56 57 68 public SharedStringFormulaRecord(Record t, 69 File excelFile, 70 FormattingRecords fr, 71 ExternalSheet es, 72 WorkbookMethods nt, 73 SheetImpl si, 74 WorkbookSettings ws) 75 { 76 super(t, fr, es, nt, si, excelFile.getPos()); 77 int pos = excelFile.getPos(); 78 79 int filepos = excelFile.getPos(); 81 82 Record nextRecord = excelFile.next(); 85 int count = 0; 86 while (nextRecord.getType() != Type.STRING && count < 4) 87 { 88 nextRecord = excelFile.next(); 89 count++; 90 } 91 Assert.verify(count < 4, " @ " + pos); 92 93 byte[] stringData = nextRecord.getData(); 94 int chars = IntegerHelper.getInt(stringData[0], stringData[1]); 95 96 boolean unicode = false; 97 int startpos = 3; 98 if (stringData.length == chars + 2) 99 { 100 startpos = 2; 103 unicode = false; 104 } 105 else if (stringData[2] == 0x1) 106 { 107 startpos = 3; 109 unicode = true; 110 } 111 else 112 { 113 startpos = 3; 115 unicode = false; 116 } 117 118 if (!unicode) 119 { 120 value = StringHelper.getString(stringData, chars, startpos, ws); 121 } 122 else 123 { 124 value = StringHelper.getUnicodeString(stringData, chars, startpos); 125 } 126 127 excelFile.setPos(filepos); 130 } 131 132 137 public String getString() 138 { 139 return value; 140 } 141 142 147 public String getContents() 148 { 149 return value; 150 } 151 152 157 public CellType getType() 158 { 159 return CellType.STRING_FORMULA; 160 } 161 162 169 public byte[] getFormulaData() throws FormulaException 170 { 171 if (!getSheet().getWorkbookBof().isBiff8()) 172 { 173 throw new FormulaException(FormulaException.biff8Supported); 174 } 175 176 FormulaParser fp = new FormulaParser 179 (getTokens(), this, 180 getExternalSheet(), getNameTable(), 181 getSheet().getWorkbook().getSettings()); 182 fp.parse(); 183 byte[] rpnTokens = fp.getBytes(); 184 185 byte[] data = new byte[rpnTokens.length + 22]; 186 187 IntegerHelper.getTwoBytes(getRow(), data, 0); 189 IntegerHelper.getTwoBytes(getColumn(), data, 2); 190 IntegerHelper.getTwoBytes(getXFIndex(), data, 4); 191 192 data[6] = 0; 195 data[12] = -1; 196 data[13] = -1; 197 198 System.arraycopy(rpnTokens, 0, data, 22, rpnTokens.length); 200 IntegerHelper.getTwoBytes(rpnTokens.length, data, 20); 201 202 byte[] d = new byte[data.length - 6]; 204 System.arraycopy(data, 6, d, 0, data.length - 6); 205 206 return d; 207 } 208 } 209 210 211 212 213 214 215 216 217 218 | Popular Tags |