日期:2014-05-20  浏览次数:20735 次

求分享自己写的代码
写的比较经典的

------解决方案--------------------
判断全角空行,非常经典了
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();
}