POI读取excel文件,去除null值

package com.util;java

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.util.StringUtils;spring


/**
 * 读取上传Excel数据
 * @author 
 *
 */
public class ReadPlansInfoExcel {  
    static XSSFRow row;
    @SuppressWarnings({ "deprecation" })
    public ArrayList<Data_excel> Read(String username,File file) throws Exception{
        XSSFWorkbook workbook = null;
        FileInputStream fis = null;
        ArrayList<Data_excel> arrlist=new ArrayList<Data_excel>();
        Date date = new Date();
        Timestamp timestamp  = new Timestamp(date.getTime());
        SimpleDateFormat sdf =  new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss " );
        SimpleDateFormat sd  =  new SimpleDateFormat( "yyyy-MM-dd" );
        try {
            fis = new FileInputStream(file);
            try {
                workbook = new XSSFWorkbook(fis);
                XSSFSheet spreadsheet = workbook.getSheetAt(0);
                Iterator < Row > rowIterator = spreadsheet.iterator();
                int totalRowNum = spreadsheet.getLastRowNum()+1;//获得总行数
                int totalListNum=spreadsheet.getRow(1).getPhysicalNumberOfCells();//获得总列数            
                Data_excel infos =null;
                for (int i = 0 ; i < totalRowNum ; i++) {
                    infos = new Data_excel();
                    row = (XSSFRow) rowIterator.next();
                    
                    //Iterator < Cell > cellIterator = row.cellIterator();
                    XSSFRow xssfRow = spreadsheet.getRow(i);
                    if(i > 0){//第一行不读取列,第一行是名称
                        for (int j = 0 ; j < totalListNum ; j++)  
                        {
//                            infos.setCreateTime(timestamp.toString());//建立时间
//                            infos.setCreateUser(username);//获取登录状态的用户名
//                            infos.setLogTime(sd.format(timestamp));//插入时间
                            
                            XSSFCell cell = xssfRow.getCell(j);
                            if(cell ==null){
                                continue;
                            }
                            
                            //读取每一列的属性值,cell.getStringCellValue() 
                            //Cell cell = cellIterator.next();
                            String value = new String();
                            switch (cell.getCellType()) 
                            {
                            case Cell.CELL_TYPE_NUMERIC://获取整型的值
                                DecimalFormat df = new DecimalFormat("0");  
                                value = df.format(cell.getNumericCellValue());
                                break;
                            case Cell.CELL_TYPE_STRING: //字符串类型的值
                                value = cell.getStringCellValue().trim();
                                break;
                            case Cell.CELL_TYPE_BLANK: //空值
//                                value=null;
                                value="";
                                break;
                            case Cell.CELL_TYPE_BOOLEAN:
                                value= String.valueOf(cell.getBooleanCellValue()).trim();
                            }
                            if(j ==0){sql

                                infos.setCustomer(value);//(Integer.parseInt(value.trim()));// 生产顺序
                                
                            }else if(j==1){
                                infos.setCode(value);   //编码
                                System.out.println(infos);
                            }else if(j ==2 ){
                                infos.setFName(value); //设备编号
                            }else if(j==3){
                                infos.setFitemid(Integer.parseInt(value.trim()));//生产日期
                            }
                        }
//                        System.out.println("customer:"+infos.getCustomer());
                        boolean cus=infos.getCustomer()!=null && !infos.getCustomer().equals("");
                        boolean co =infos.getCode()!=null && !infos.getCode().equals("");
                        if(cus || co){
                            
                            arrlist.add(infos);
                        }
                            
                        
                        
                    }
                }
                fis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }apache

        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
        }
        return arrlist;
    }
  
}  xss