62,616
社区成员
发帖
与我相关
我的任务
分享
InputStream is= new FileInputStream(patch);
HSSFWorkbook hsfw=new HSSFWorkbook(is);
for(int i=0;i<hsfw.getNumberOfSheets();i++){
HSSFSheet hsfs=hsfw.getSheetAt(i);
for(int r=1;r<=hsfs.getLastRowNum();r++){
HSSFRow hsfr=hsfs.getRow(r);
if(null==hsfr){
break;
}
Customer customer=new Customer();
String[] cellvalue=new String[hsfr.getLastCellNum()];
for(int c=0;c<hsfr.getLastCellNum();c++){
HSSFCell hsfc=hsfr.getCell(c);
switch (hsfc.getCellType()) {
case Cell.CELL_TYPE_STRING:
cellvalue[c]=hsfc.getStringCellValue();
break;
case Cell.CELL_TYPE_NUMERIC:
cellvalue[c]=String.valueOf((int)hsfc.getNumericCellValue());
break;
case Cell.CELL_TYPE_BOOLEAN:
cellvalue[c]=String.valueOf(hsfc.getBooleanCellValue());
break;
case Cell.CELL_TYPE_FORMULA:
cellvalue[c]=String.valueOf(hsfc.getCellFormula());
break;
case Cell.CELL_TYPE_BLANK:
cellvalue[c]="";
break;
default:
break;
}
}
public static boolean isBlankRow(HSSFRow row){
if(row == null) return true;
boolean result = true;
for(int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++){
HSSFCell cell = row.getCell(i, HSSFRow.RETURN_BLANK_AS_NULL);
String value = "";
if(cell != null){
switch (cell.getCellType()) {
case Cell.CELL_TYPE_STRING:
value = cell.getStringCellValue();
break;
case Cell.CELL_TYPE_NUMERIC:
value = String.valueOf((int) cell.getNumericCellValue());
break;
case Cell.CELL_TYPE_BOOLEAN:
value = String.valueOf(cell.getBooleanCellValue());
break;
case Cell.CELL_TYPE_FORMULA:
value = String.valueOf(cell.getCellFormula());
break;
//case Cell.CELL_TYPE_BLANK:
// break;
default:
break;
}
if(!value.trim().equals("")){
result = false;
break;
}
}
}
return result;
}
for (int r = 0; r <= hsfs.getLastRowNum(); r++) {//这里的基数应该是0,最好改成hsfs.getFirstRowNum()
...
if (null == hsfr || isBlankRow(hsfr)) {//这里判断为空或只有空格的row忽略
continue;
}
...
if(hsfc == null) continue;//cell也应该判断null
switch (hsfc.getCellType()) {
...