String docFileURL = (UEngineUtil.isNotEmpty(getPath()) ? getPath() : defaultValue.getTemplateFilePath());
if(docFileURL==null)
throw new UEngineException(" document file is empty.");
ProcessDefinition definition = (instance !=null ? instance.getProcessDefinition() : new ProcessDefinition(){
public StringBuffer evaluateContent(ProcessInstance instance, String expression) {
return new StringBuffer("");
}
});
docFileURL = (instance != null ? definition.evaluateContent(instance, docFileURL).toString() : docFileURL);
InputStream is = new URL(docFileURL).openStream();
Workbook workbook = Workbook.getWorkbook(is);
String tempFName = defaultValue.getSavingFileName(instance);
WritableWorkbook copy = Workbook.createWorkbook(new File(tempFName), workbook);
WritableSheet sheets[] = copy.getSheets();
//System.out.println(" ExcelSheetActivity:getWIHAddress: start parsing file");
for(int i=0; i<sheets.length; i++){
WritableSheet sheet = sheets[i];
for(int row = 0; row < sheet.getRows(); row++){
boolean newRowInserted=false;
for(int col = 0; col < sheet.getColumns(); col++){
WritableCell cell = sheet.getWritableCell(col,row);
if (cell.getType() == CellType.LABEL)
{
Label l = (Label) cell;
String expression = l.getString();
if(expression.startsWith("<%=+")){
//System.out.println("expression:"+expression);
if(!newRowInserted){
newRowInserted = true;
sheet.insertRow(row);
}
//l.setString(expression);
/*
WritableCell existingCell = sheet.getWritableCell(col,row);
Label ecl = (Label) existingCell;
ecl.setString(
EMailActivity.parseContent(expression, this, instance).toString()
);*/
jxl.format.CellFormat style = l.getCellFormat();
WritableCell label = new Label(col,row, definition.evaluateContent(instance, expression).toString(), style);
sheet.addCell(label);
}else
if(expression.indexOf("<%=") > -1 || expression.indexOf("<%=*") > -1){ //if the expression contains any value need to evaluate.
//System.out.println("expression:"+expression);
l.setString(
definition.evaluateContent( instance, expression).toString()
);
//System.out.println("evaluated:"+l.getString());
}else
if(expression.startsWith("<%->")){
l.setString("");
}else
if(expression.startsWith("<%<-")){
WritableCell leftCell = sheet.getWritableCell(col-1,row);
Label lcl = (Label) leftCell;
lcl.setString(
definition.evaluateContent(instance, expression).toString()
);
l.setString("");
}
}