1 19 20 package jxl.read.biff; 21 22 import java.text.NumberFormat ; 23 import java.util.ArrayList ; 24 25 import common.Logger; 26 27 import jxl.Cell; 28 import jxl.CellType; 29 import jxl.biff.FormattingRecords; 30 import jxl.biff.IntegerHelper; 31 import jxl.biff.WorkbookMethods; 32 import jxl.biff.formula.ExternalSheet; 33 34 37 class SharedFormulaRecord 38 { 39 42 private static Logger logger = Logger.getLogger(SharedFormulaRecord.class); 43 44 47 private int firstRow; 48 49 52 private int lastRow; 53 54 57 private int firstCol; 58 59 62 private int lastCol; 63 64 67 private BaseSharedFormulaRecord templateFormula; 68 69 72 private ArrayList formulas; 73 74 77 private byte[] tokens; 78 79 82 private ExternalSheet externalSheet; 83 84 87 private SheetImpl sheet; 88 89 90 101 public SharedFormulaRecord(Record t, BaseSharedFormulaRecord fr, 102 ExternalSheet es, WorkbookMethods nt, 103 SheetImpl si) 104 { 105 sheet = si; 106 byte[] data = t.getData(); 107 108 firstRow = IntegerHelper.getInt(data[0], data[1]); 109 lastRow = IntegerHelper.getInt(data[2], data[3]); 110 firstCol = (int) (data[4] & 0xff); 111 lastCol = (int) (data[5] & 0xff); 112 113 formulas = new ArrayList (); 114 115 templateFormula = fr; 116 117 tokens = new byte[data.length - 10]; 118 System.arraycopy(data, 10, tokens, 0, tokens.length); 119 } 120 121 128 public boolean add(BaseSharedFormulaRecord fr) 129 { 130 if (fr.getRow() >= firstRow && fr.getRow() <= lastRow && 131 fr.getColumn() >= firstCol && fr.getColumn() <= lastCol) 132 { 133 formulas.add(fr); 134 return true; 135 } 136 137 return false; 138 } 139 140 148 Cell[] getFormulas(FormattingRecords fr, boolean nf) 149 { 150 Cell[] sfs = new Cell[formulas.size() + 1]; 151 152 if (templateFormula == null) 155 { 156 logger.warn("Shared formula template formula is null"); 157 return new Cell[0]; 158 } 159 160 templateFormula.setTokens(tokens); 161 NumberFormat templateNumberFormat = null; 162 163 if (templateFormula.getType() == CellType.NUMBER_FORMULA) 165 { 166 SharedNumberFormulaRecord snfr = (SharedNumberFormulaRecord) 167 templateFormula; 168 templateNumberFormat = snfr.getNumberFormat(); 169 170 if (fr.isDate(templateFormula.getXFIndex())) 171 { 172 templateFormula = new SharedDateFormulaRecord(snfr, fr, nf, sheet, 173 snfr.getFilePos()); 174 templateFormula.setTokens(snfr.getTokens()); 175 } 176 } 177 178 sfs[0] = templateFormula; 179 180 BaseSharedFormulaRecord f = null; 181 182 for (int i = 0; i < formulas.size(); i++) 183 { 184 f = (BaseSharedFormulaRecord) formulas.get(i); 185 186 if (f.getType() == CellType.NUMBER_FORMULA) 188 { 189 SharedNumberFormulaRecord snfr = (SharedNumberFormulaRecord) f; 190 191 if (fr.isDate(f.getXFIndex())) 192 { 193 f = new SharedDateFormulaRecord(snfr, fr, nf, sheet, 194 snfr.getFilePos()); 195 } 196 else 197 { 198 snfr.setNumberFormat(templateNumberFormat); 199 } 200 } 201 202 f.setTokens(tokens); 203 sfs[i + 1] = f; 204 } 205 206 return sfs; 207 } 208 209 214 BaseSharedFormulaRecord getTemplateFormula() 215 { 216 return templateFormula; 217 } 218 } 219 220 221 222 223 224 225 226 | Popular Tags |