续:基本问题!数据导出的异常处理!
小弟在做数据导出,要写方法,但在方法里,要做的一个工作是一但有数据出错,要处理,保证其他数据也能导出,出错的数据可以不理或其他的,目标是保证其他数据能正常导出。下面的方法只是把数据写进XLS文件,就是出错了,其他数据也能写到XLS里。但小弟不知道怎样处理,请大家帮帮忙!注意:数据导出时,肯定是有循环体的!也就是下面的方法,其自身有循环,但也回在其他循环体里的。分不够可再加100!两贴加起来可以有170分,请大家帮帮忙!
/*根据属性组把属性和属性值写入XLS*/
public void writeArrtibute(Environment env, Iterator it,int articleid,
jxl.write.WritableWorkbook wwb) throws Exception {
try {
jxl.write.WritableSheet ws = wwb.createSheet("产品属性", 4);
Article article = env.getArticle(articleid);
// Iterator it = getAttrGroupByArticleId(env, articleid).iterator();
int row = 0;
while (it.hasNext()) {
AttrGroup gruop = (AttrGroup) it.next();
for (Iterator it2 = gruop.getAttrDics().values().iterator();
it2.hasNext(); ) {
int coll = 0;
AttrDic attrDic = (AttrDic) it2.next();
int AttrDicType = attrDic.getAttrDicID();
if (AttrDicType != 6) {
jxl.write.Label label0 = new jxl.write.Label(coll++, row,
String.valueOf(articleid));
ws.addCell(label0);
jxl.write.Label label1 = new jxl.write.Label(coll++, row,
attrDic.getOuterName());
ws.addCell(label1);
}
ExtendedField attrField = article.getField(attrDic.getAttrDicID());
Attribute attrb = null;
LongAttribute lattr = null;
if (attrField != null) {
if (AttrDicType != 6) {
attrb = (Attribute) attrField.getValue();
}
else {
//lattr = (LongAttribute) attrField.getValue();
}
}
String sattrb = "";
if (attrb != null) {
switch (AttrDicType) {
case 1:
int intValue = attrb.getIntValue();
sattrb = String.valueOf(intValue);
break;
case 2:
double dbValue = attrb.getDblValue();
sattrb = String.valueOf(dbValue);
break;
case 3:
sattrb = attrb.getStrValue();
break;
}
if (attrDic.getUnit() != null) {
sattrb += attrDic.getUnit();
}
}
// if (lattr != null) {
// sattrb = lattr.getFilePath();
// }
System.out.print("**************" + "<br>");
if (AttrDicType != 6) {
jxl.write.Label label2 = new jxl.write.Label(coll++, row, sattrb);
ws.addCell(label2);
row++;
}
else {
//jxl.write.Label labelCc33_ =new jxl.write.Label(coll_++,row_,sattrb);
//ws3.addCell(labelCc33_);
}
}
}
}
catch (Exception e) {
throw new Exception(
"ExportAttrbuteData writeArrtibute(env,articleid,wwb) Error! " +
e.getMessage());
}
}