当前位置: 代码迷 >> Java面试 >> 求分享自各儿写的代码
  详细解决方案

求分享自各儿写的代码

热度:70   发布时间:2016-04-17 19:05:46.0
求分享自己写的代码
写的比较经典的

------解决方案--------------------
判断全角空行,非常经典了
public int getRowCount(HSSFSheet childSheet){
int iBlank=0;
String strBlank = "^[\\u3000\\s\\t\\n\\x0B\\f\\r]*$";
HSSFRow row=null;
HSSFCell cell=null;
System.out.println("POI行数"+childSheet.getLastRowNum());
for(int j=3;j<=childSheet.getLastRowNum();j++){ //行循环 排除前三行
row=childSheet.getRow(j);
iBlank=0;
if(null!=row){
for(int k=0;k<row.getLastCellNum();k++){ //列循环
cell=row.getCell(k);
if(null!=cell){
if(cell.getCellType()==HSSFCell.CELL_TYPE_BLANK){
iBlank=iBlank+1;}else{
if(cell.toString().matches(strBlank)){
iBlank=iBlank+1;
}else{}
}
}
else{
iBlank=iBlank+1;
}
}
//System.out.println((j+1)+"行"+iBlank);
}//null!=row
if(iBlank==row.getLastCellNum()){
System.out.println("找到"+(j+1)+"行为全角空行了"+row.getLastCellNum());
this.setCountRow((j-1));
break;
}
}
if(this.getCountRow()<3){this.setCountRow(childSheet.getLastRowNum());}
return this.getCountRow();
}
  相关解决方案