/** * Manufactures individual cell formulas out the whole shared formula * debacle * * @param fr the formatting records * @param nf flag indicating whether this uses the 1904 date system * @return an array of formulas to be added to the sheet */ public Cell[] getFormulas(FormattingRecords fr, bool nf) { Cell[] sfs = new Cell[formulas.Count + 1]; // This can happen if there are many identical formulas in the // sheet and excel has not sliced and diced them exclusively if (templateFormula == null) { //logger.warn("Shared formula template formula is null"); return(new Cell[0]); } templateFormula.setTokens(tokens); NumberFormat templateNumberFormat = null; // See if the template formula evaluates to date if (templateFormula.getType() == CellType.NUMBER_FORMULA) { SharedNumberFormulaRecord snfr = (SharedNumberFormulaRecord) templateFormula; templateNumberFormat = snfr.getNumberFormat(); if (fr.isDate(templateFormula.getXFIndex())) { templateFormula = new SharedDateFormulaRecord(snfr, fr, nf, sheet, snfr.getFilePos()); templateFormula.setTokens(snfr.getTokens()); } } sfs[0] = templateFormula; BaseSharedFormulaRecord f = null; for (int i = 0; i < formulas.Count; i++) { f = (BaseSharedFormulaRecord)formulas[i]; // See if the formula evaluates to date if (f.getType() == CellType.NUMBER_FORMULA) { SharedNumberFormulaRecord snfr = (SharedNumberFormulaRecord)f; if (fr.isDate(f.getXFIndex())) { f = new SharedDateFormulaRecord(snfr, fr, nf, sheet, snfr.getFilePos()); } else { ; // snfr.setNumberFormat(templateNumberFormat); } } f.setTokens(tokens); sfs[i + 1] = f; } return(sfs); }
/** * Constructs this number formula * * @param nfr the number formula records * @param fr the formatting records * @param nf flag indicating whether this uses the 1904 date system * @param si the sheet * @param pos the position */ public SharedDateFormulaRecord(SharedNumberFormulaRecord nfr, FormattingRecords fr, bool nf, SheetImpl si, int pos) : base(nfr.getRecord(), fr, nfr.getExternalSheet(), nfr.getNameTable(), si, pos) { dateRecord = new DateRecord(nfr, nfr.getXFIndex(), fr, nf, si); value = nfr.getValue(); }
/** * Constructs this number formula * * @param nfr the number formula records * @param fr the formatting records * @param nf flag indicating whether this uses the 1904 date system * @param si the sheet * @param pos the position */ public SharedDateFormulaRecord(SharedNumberFormulaRecord nfr, FormattingRecords fr, bool nf, SheetImpl si, int pos) : base(nfr.getRecord(), fr, nfr.getExternalSheet(), nfr.getNameTable(), si, pos) { dateRecord = new DateRecord(nfr,nfr.getXFIndex(),fr,nf,si); value = nfr.getValue(); }
/** * Constructs this object from the raw data. Creates either a * NumberFormulaRecord or a StringFormulaRecord depending on whether * this formula represents a numerical calculation or not * * @param t the raw data * @param excelFile the excel file * @param fr the formatting records * @param es the workbook, which contains the external sheet references * @param nt the name table * @param si the sheet * @param ws the workbook settings */ public FormulaRecord(Record t, File excelFile, FormattingRecords fr, ExternalSheet es, WorkbookMethods nt, SheetImpl si, WorkbookSettings ws) : base(t, fr, si) { byte[] data = getRecord().getData(); shared = false; // Check to see if this forms part of a shared formula int grbit = IntegerHelper.getInt(data[14], data[15]); if ((grbit & 0x08) != 0) { shared = true; if (data[6] == 0 && data[12] == 0xff && data[13] == 0xff) { // It is a shared string formula formula = new SharedStringFormulaRecord(t, excelFile, fr, es, nt, si, ws); } else if (data[6] == 3 && data[12] == 0xff && data[13] == 0xff) { // We have a string which evaluates to null formula = new SharedStringFormulaRecord(t, excelFile, fr, es, nt, si, SharedStringFormulaRecord.EMPTY_STRING); } else if (data[6] == 2 && data[12] == 0xff && data[13] == 0xff) { // The cell is in error int errorCode = data[8]; formula = new SharedErrorFormulaRecord(t, excelFile, errorCode, fr, es, nt, si); } else if (data[6] == 1 && data[12] == 0xff && data[13] == 0xff) { bool value = data[8] == 1 ? true : false; formula = new SharedBooleanFormulaRecord (t, excelFile, value, fr, es, nt, si); } else { // It is a numerical formula double value = DoubleHelper.getIEEEDouble(data, 6); SharedNumberFormulaRecord snfr = new SharedNumberFormulaRecord (t, excelFile, value, fr, es, nt, si); snfr.setNumberFormat(fr.getNumberFormat(getXFIndex())); formula = snfr; } return; } // microsoft and their goddam magic values determine whether this // is a string or a number value if (data[6] == 0 && data[12] == 0xff && data[13] == 0xff) { // we have a string formula = new StringFormulaRecord(t, excelFile, fr, es, nt, si, ws); } else if (data[6] == 1 && data[12] == 0xff && data[13] == 0xff) { // We have a bool formula // multiple values. Thanks to Frank for spotting this formula = new BooleanFormulaRecord(t, fr, es, nt, si); } else if (data[6] == 2 && data[12] == 0xff && data[13] == 0xff) { // The cell is in error formula = new ErrorFormulaRecord(t, fr, es, nt, si); } else if (data[6] == 3 && data[12] == 0xff && data[13] == 0xff) { // we have a string which evaluates to null formula = new StringFormulaRecord(t, fr, es, nt, si); } else { // it is most assuredly a number formula = new NumberFormulaRecord(t, fr, es, nt, si); } }
/** * Constructs this object from the raw data. Creates either a * NumberFormulaRecord or a StringFormulaRecord depending on whether * this formula represents a numerical calculation or not * * @param t the raw data * @param excelFile the excel file * @param fr the formatting records * @param es the workbook, which contains the external sheet references * @param nt the name table * @param si the sheet * @param ws the workbook settings */ public FormulaRecord(Record t, File excelFile, FormattingRecords fr, ExternalSheet es, WorkbookMethods nt, SheetImpl si, WorkbookSettings ws) : base(t,fr,si) { byte[] data = getRecord().getData(); shared = false; // Check to see if this forms part of a shared formula int grbit = IntegerHelper.getInt(data[14],data[15]); if ((grbit & 0x08) != 0) { shared = true; if (data[6] == 0 && data[12] == 0xff && data[13] == 0xff) { // It is a shared string formula formula = new SharedStringFormulaRecord(t,excelFile,fr,es,nt,si,ws); } else if (data[6] == 3 && data[12] == 0xff && data[13] == 0xff) { // We have a string which evaluates to null formula = new SharedStringFormulaRecord(t,excelFile,fr,es,nt,si,SharedStringFormulaRecord.EMPTY_STRING); } else if (data[6] == 2 && data[12] == 0xff && data[13] == 0xff) { // The cell is in error int errorCode = data[8]; formula = new SharedErrorFormulaRecord(t,excelFile,errorCode, fr,es,nt,si); } else if (data[6] == 1 && data[12] == 0xff && data[13] == 0xff) { bool value = data[8] == 1 ? true : false; formula = new SharedBooleanFormulaRecord (t,excelFile,value,fr,es,nt,si); } else { // It is a numerical formula double value = DoubleHelper.getIEEEDouble(data,6); SharedNumberFormulaRecord snfr = new SharedNumberFormulaRecord (t,excelFile,value,fr,es,nt,si); snfr.setNumberFormat(fr.getNumberFormat(getXFIndex())); formula = snfr; } return; } // microsoft and their goddam magic values determine whether this // is a string or a number value if (data[6] == 0 && data[12] == 0xff && data[13] == 0xff) { // we have a string formula = new StringFormulaRecord(t,excelFile,fr,es,nt,si,ws); } else if (data[6] == 1 && data[12] == 0xff && data[13] == 0xff) { // We have a bool formula // multiple values. Thanks to Frank for spotting this formula = new BooleanFormulaRecord(t,fr,es,nt,si); } else if (data[6] == 2 && data[12] == 0xff && data[13] == 0xff) { // The cell is in error formula = new ErrorFormulaRecord(t,fr,es,nt,si); } else if (data[6] == 3 && data[12] == 0xff && data[13] == 0xff) { // we have a string which evaluates to null formula = new StringFormulaRecord(t,fr,es,nt,si); } else { // it is most assuredly a number formula = new NumberFormulaRecord(t,fr,es,nt,si); } }