jxl读取Excel时 读到空单元格的时候就报错

sxf0210 2011-01-20 12:37:46
jxl读取Excel时 读到空单元格的时候就报错
jxl.read.biff.BlankCell

else if(cell.getType()==CellType.EMPTY){
EmptyCell ec = (EmptyCell)cell;
return ec.getContents();
...全文
438 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
扁鵲東南飛 2011-01-20
  • 打赏
  • 举报
回复
你是说判断是否为空的时候报错。还是读取空的时候报错?

如果读取的时候报错,那么这个空的话,就直接不读了。赋值为空就行了。

如果判断为空,那么我感觉是你判断的条件里面有问题。

把 报错的错误信息发出来,看看。
sxf0210 2011-01-20
  • 打赏
  • 举报
回复
急啊 各位大哥
pauljin725 2011-01-20
  • 打赏
  • 举报
回复
[Quote=引用 19 楼 pauljin725:] 的回复:]

引用 18 楼 pauljin725 的回复:
引用 17 楼 pauljin725 的回复:
引用 14 楼 madee123 的回复:
引用 13 楼 madee123 的回复:
引用 8 楼 mahailei 的回复:
鸿哥太牛了

sss
ddddgigkjh

ghh

dsgfd
[/Quote]
[/Quote]
[/Quote]sdfg
sxf0210 2011-01-20
  • 打赏
  • 举报
回复
当 strs 是空的时候就报错
sxf0210 2011-01-20
  • 打赏
  • 举报
回复
for(int x = 0; x<23;x++)
{
String strS = "";
for(int i = 0; i<objSheet.getColumns();i++)
{
objCell = objSheet.getCell(i, x);
int as = objCell.getRow();
int ass = objCell.getColumn();
System.out.println("hang"+as);
System.out.println("lie"+ass);
Object Strs = this.readCell(objCell);
System.out.print("第"+x+"行,第"+i+"列的值==="+Strs+"\n");
}

}
sxf0210 2011-01-20
  • 打赏
  • 举报
回复
public Object readCell(Cell cell){
if(cell.getType()==CellType.NUMBER){
NumberCell nc=(NumberCell)cell;
return nc.getValue();
}else if(cell.getType()==CellType.LABEL){
LabelCell cl = (LabelCell)cell;
return cl.getString();
}else if(cell.getType()==CellType.EMPTY){
EmptyCell ec = (EmptyCell)cell;
return ec.getContents();
}else if(cell.getType()==CellType.DATE){
DateCell dc = (DateCell)cell;
java.text.DateFormat format1 = new java.text.SimpleDateFormat("yyyy-MM-dd");
String s = format1.format(dc.getDate());
return s;
}else if(cell.getType()==CellType.BOOLEAN){
BooleanCell bc = (BooleanCell)cell;
return bc.getValue();
}else if(cell.getType()==CellType.NUMBER_FORMULA){
NumberFormulaCell nfc = (NumberFormulaCell)cell;
DecimalFormat df = new DecimalFormat("#######0.00");
return df.format(nfc.getValue());
}else if(cell.getType()==CellType.DATE_FORMULA){
DateFormulaCell dfc = (DateFormulaCell)cell;
java.text.DateFormat format1 = new java.text.SimpleDateFormat("yyyy-MM-dd");
String s = format1.format(dfc.getDate());
return s;
}else{
return cell.getContents();
}
}
zn85600301 2011-01-20
  • 打赏
  • 举报
回复
都已经判断是空的单元格了你还要取什么内容?
Epiphone 2011-01-20
  • 打赏
  • 举报
回复
加判断

if (cell.getType() == CellType.EMPTY)
{

if(null != 从excel里取出的值)
{
在执行你的操作
}
}

81,090

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧