bean.set("saveName", targetFile.getName());
/**!
* 2.对指定文件生成表格并进行存储
*/
// OperResult convertResult = DocumentConverter.convert2HTMLTableStringWithOpenOffice(targetFile);
OperResult convertResult = DocumentConverter.convert2HTMLTableStringWithPOI(targetFile);
if(convertResult.isSUCCEED()){
/**!
* 进行存档
*/
if(convertResult.getData()!=null){
try {
if(id==null){
ReportTemplate rt = new ReportTemplate();
BeanUtils.populate(rt, properties);
rt.setId(MyUUIDGen.getUUID());
rt.setCode(convertResult.getData().toString());
rt.setFileName(targetFile.getName());
rt.setTimeStamp(new Timestamp(new Date().getTime()));
if(rt.getName()==null){
rt.setName(originName);
}
reportTemplateDAO.merge(rt);
ObjectListConvert2DynaBeanList.convert(bean, rt);
bean.set("code", "");
bean.set("status", true);
}else{
ReportTemplate rt = reportTemplateDAO.findById(id);
if(rt==null){
rt = new ReportTemplate();
BeanUtils.populate(rt, properties);
rt.setId(MyUUIDGen.getUUID());
rt.setCode(convertResult.getData().toString());
rt.setFileName(targetFile.getName());
rt.setTimeStamp(new Timestamp(new Date().getTime()));
if(rt.getName()==null){
rt.setName(originName);
}
reportTemplateDAO.merge(rt);
ObjectListConvert2DynaBeanList.convert(bean, rt);
bean.set("code", "");
bean.set("status", true);
}else{
BeanUtils.populate(rt, properties);
Set<Cell> cells = rt.getCells();
// List<Cell> cells = cellDAO.findByProperty("reportTemplate.id", "id");
if(cells.size()>0){
HTMLTableManipulator htm = new HTMLTableManipulator(convertResult.getData().toString());
for(Cell cell:cells){
if("olap".equalsIgnoreCase(cell.getQueryType())){
htm.setCellValue(cell.getId().getSheetNum().intValue(), cell.getId().getRowNum().intValue(), cell.getId().getColNum().intValue(), "*");
}else{
htm.setCellValue(cell.getId().getSheetNum().intValue(), cell.getId().getRowNum().intValue(), cell.getId().getColNum().intValue(), "#");
}
}
rt.setCode(htm.getResult());
}else{
rt.setCode(convertResult.getData().toString());
}
rt.setFileName(targetFile.getName());
rt.setTimeStamp(new Timestamp(new Date().getTime()));
if(rt.getName()==null){
rt.setName(originName);
}
reportTemplateDAO.merge(rt);
ObjectListConvert2DynaBeanList.convert(bean, rt);
bean.set("code", "");
bean.set("status", true);
}
}
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
targetFile.delete();
bean.set("message", e.getMessage());
bean.set("status", false);
} catch (Exception e) {
// TODO Auto-generated catch block
targetFile.delete();
bean.set("message", e.getMessage());
bean.set("status", false);
}
}else{
targetFile.delete();
bean.set("message", XLS_CONVERT_NULL_STRING);
bean.set("status", false);
}
}else{
/**!
* 转换失败,删除目标文件,跳出
*/
targetFile.delete();
bean.set("message", convertResult.getInfoMSG());
bean.set("status", false);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();