cachedValue= new Double((String)cachedValue);
}
else if (type.equals("b"))
cachedValue= Boolean.valueOf((String)cachedValue);
// type e -- input calculation exception?
CellHandle ch= null; // normal case but may be created * as a blank * if part of a merged cell range or dv ...
try{
sheet = bk.getWorkSheet(s[0]);
ch= sheet.getCell(addr); // if exists, grab it;
}catch(Exception ex){;}
if (fStr.equals("null")) { // when would this ever occur?
Logger.logWarn("OOXMLAdapter.parse: invalid formula encountered at " + addr);
}
if (fType.equals("array")) {
/*
* For a multi-cell formula, the r attribute of the top-left cell
* of the range 1 of cells to which that formula applies
shall designate the range of cells to which that formula applies
*/
int[] arrayref= null;
if (s[4]!=null) { // if has the ref attribute means its the PARENT array formula
sheet.getMysheet().addParentArrayRef(s[1], s[4]);
arrayref= ExcelTools.getRangeRowCol(s[4]);
} else
arrayref= rc;
/* must enter array formulas for each cell in range denoted by array ref*/
for (int r= arrayref[0]; r <= arrayref[2]; r++) {
for (int c= arrayref[1]; c<=arrayref[3]; c++) {
try{
ch= sheet.getCell(r, c); // if exists, grab it;
}catch(Exception ex){;}
if(ch==null)
ch= sheetAdd(sheet,"{" + fStr + "}",cachedValue, r,c,fmtid);
else {
ch.setFormatId(fmtid); // if exists may be part of a merged cell range and therefore it's correct format id may NOT have been set; see mergedranges in parseSheetXML below
ch.setFormula("{" + fStr + "}", cachedValue); // set cached value so don't have to recalculate; just sets cached value if formula is already set
}
}
}
} else if (fType.equals("datatable")) {
if(ch==null)
ch = sheetAdd(sheet,fStr,cachedValue,rc[0],rc[1],fmtid);
else {
ch.setFormatId(fmtid); // if exists may be part of a merged cell range and therefore it's correct format id may NOT have been set; see mergedranges in parseSheetXML below
ch.setFormula(fStr, cachedValue); // set cached value so don't have to recalculate; just sets cached value if formula is already set
}
} else if (fType.equals("shared") && !s[3].equals("")) { // meaning that if it's set as shared but doesn't have a shared index, make regular function -- is what excel 2007 does :)
// Shared Formulas: there is the "master" shared formula which defines the formula + the range (=ref) of cells that the formula refers to
// For references to the shared formula, the si index denotes the shared formula it refers to
// one takes the master formula cell, compares with the current cell's address and increments the references in the master shared
// formula accordingly -- algorithm of comparison and movement can be tricky
Integer si = Integer.valueOf(s[3]);
if (!sharedFormulas.containsKey(si)) {
// represents the "master" formula of a shared formula, movement is based upon relationship of subsequent cells to this cell
if(ch==null)
ch = sheetAdd(sheet,fStr,cachedValue, rc[0],rc[1],fmtid);
else {
ch.setFormatId(fmtid); // if exists may be part of a merged cell range and therefore it's correct format id may NOT have been set; see mergedranges in parseSheetXML below
ch.setFormula(fStr, cachedValue); // set cached value so don't have to recalculate; just sets cached value if formula is already set
}
// see if it's a 3d range
int[] range= ExcelTools.getRangeCoords(s[3]);
range[0]-=1; range[2]-=1;
Stack expressionStack= cloneStack(ch.getFormulaHandle().getFormulaRec().getExpression());
sharedFormulas.put(si, new Object[] {expressionStack, rc, range});
} else { // found shared formula- means already created; must get original and "move" based on position of this - the child - shared formula
Object[] o= (Object[])sharedFormulas.get(si);
Stack ss= cloneStack((Stack) o[0]);
int[] rcOrig= ((int[])o[1]);
Formula.incrementSharedFormula(ss, rc[0]-rcOrig[0], rc[1]-rcOrig[1], (int[])o[2]);
if(ch==null) {
ch= sheetAdd(sheet,"=0", null, rc[0],rc[1],fmtid); // add a basic formula; will be "overwritten" by expression, set below
ch.setFormula(ss, cachedValue); // must set child shared formulas via expression rather than via formula string as original formula string must be incremented
} else {
ch.setFormula(ss, cachedValue); // must set child shared formulas via expression rather than via formula string as original formula string must be incremented
ch.setFormatId(fmtid); // if exists may be part of a merged cell range and therefore it's correct format id may NOT have been set; see mergedranges in parseSheetXML below
}
}
} else {// it's a regular function
if(ch==null)
// use parser-aware method
ch= sheetAdd(sheet,fStr,cachedValue,rc[0],rc[1],fmtid);
else {
ch.setFormatId(fmtid); // if exists most likely is part of a merged cell range and therefore it's correct format id may NOT have been set; see mergedranges in parseSheetXML below
ch.setFormula(fStr, cachedValue); // set cached value so don't have to recalculate; just sets cached value if formula is already set
}
}
if (s[6]!=null && ch!=null){ // for formulas such as =TODAY
BiffRec br = ch.getCell();
if(br instanceof Formula)
ch.getFormulaHandle().setCalcAlways(true);
}
} catch (FunctionNotSupportedException e) {
Logger.logErr("OOXMLAdapter.parse: failed setting formula " + s[1] + " to cell " + s[0] + ": " + e.toString());
} catch (Exception e) {
Logger.logErr("OOXMLAdapter.parse: failed setting formula " + s[1] + " to cell " + s[0] + ": " + e.toString());