* @param bk
* @param formulas
*/
void addFormulas(WorkBookHandle bk, ArrayList formulas) {
// after sheets, now can input formulas
WorkSheetHandle sheet= null;
HashMap sharedFormulas= new HashMap();
for (int j= 0; j < formulas.size(); j++) {
String[] s= (String[]) formulas.get(j);
//formulas: 0=sheetname, 1= cell address, 2=formula including =, 3=shared formula index, 4=array refs, 5=formula type, 6=calculate always flag, 7=format id, 8=cached value
if ((s[0].equals("") || s[1].equals("")) || s.length<8)
continue; // no address or formula - should ever happen?
try {
// for clarity, assign values to most common ops
String addr= s[1];
int[] rc = ExcelTools.getRowColFromString(addr);
String fStr= s[2];
String type= s[5];
String fType= "";
if (s[5].indexOf('/')>0) {
type= s[5].split("/")[0];
fType= s[5].split("/")[1];
}
int fmtid = 0;
try{
fmtid = Integer.valueOf(s[7]).intValue();
}catch(Exception e){;}
Object cachedValue= s[8];
if (type.equals("n"))
try {
cachedValue= Integer.valueOf((String)cachedValue);
} catch (NumberFormatException e) {
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