Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Java中跟踪Excel行的空白单元格_Java_Excel - Fatal编程技术网

如何在Java中跟踪Excel行的空白单元格

如何在Java中跟踪Excel行的空白单元格,java,excel,Java,Excel,我从Excel文件中提取数据并将其存储在arraylist中。除了空白单元之外,所有的单元都被正确读取。我想跟踪空白单元格。 例如,我有一个Excel文件,有7列,其中5列充满数据,2个单元格为空,因此将它们存储在arraylist中后,我得到的列表大小是12,而不是14 假设在迭代过程中,只考虑填充数据的单元,忽略空白单元。 这是我的密码 ArrayList arrayList=new ArrayList(); int rownum=0; try{ Fil

我从Excel文件中提取数据并将其存储在arraylist中。除了空白单元之外,所有的单元都被正确读取。我想跟踪空白单元格。

例如,我有一个Excel文件,有7列,其中5列充满数据,2个单元格为空,因此将它们存储在arraylist中后,我得到的列表大小是12,而不是14

假设在迭代过程中,只考虑填充数据的单元,忽略空白单元。 这是我的密码

  ArrayList arrayList=new ArrayList(); 
    int rownum=0;
    try{
        FileInputStream fis=new FileInputStream(new File("D:\\emsAttendancesheet_26-Nov-2013.xls"));
        HSSFWorkbook hssfWorkbook=new HSSFWorkbook(fis);
        HSSFSheet hssfSheet=hssfWorkbook.getSheetAt(0);
        Iterator<Row> rowIterator=hssfSheet.iterator();
        while(rowIterator.hasNext()){
            Row row=rowIterator.next();
            Iterator<Cell> cellIterator=row.iterator();
            while(cellIterator.hasNext()){
                Cell cell=cellIterator.next();
                if(cell.getCellType()==Cell.CELL_TYPE_STRING){
                 System.out.println(cell.getStringCellValue());
                 arrayList.add(cell.getStringCellValue());  
                }
                else if(cell.getCellType()==Cell.CELL_TYPE_NUMERIC){
                    arrayList.add(cell.getNumericCellValue());
                    System.out.println(cell.getNumericCellValue()); 

                }
            }
        }

        System.out.println("Size of List::"+arrayList.size());
     }catch(Exception ex){
         System.out.println("Exception in Exel   creation"+ex.getMessage());            
    }

这里的In Time和Out Time都是空的,所以它不读取空单元格。我要求考虑空单元格。有人能推荐代码吗

要检查空单元格或空白单元格:

       for( int cellCounter = 0 ; cellCounter < maxNumOfCells ; cellCounter ++)
         { 
            HSSFCell cell;

            if( row.getCell(cellCounter ) == null ){
                cell = row.createCell(cellCounter);
            } else {
                cell = row.getCell(cellCounter);
            }
         }
for(int-cellCounter=0;cellCounter
在细胞中循环。从单元格0到最后一个单元格编号。如果发现单元格为空,它将使用空值创建单元格。之后,将单元格添加到列表中,然后遍历列表。

XSSFWorkbook book=newxssfworkbook(fis);
 XSSFWorkbook book = new XSSFWorkbook(fis);
        XSSFSheet sheet = book.getSheetAt(0);
        Iterator<Row> itr = sheet.iterator();
        while(itr.hasNext()){
            Row row = itr.next();
            Iterator<Cell> cellItrator = row.iterator();
            if(row.getRowNum()==0){
                System.out.println(row.getRowNum());
                while(cellItrator.hasNext()){
                    Cell  cell = cellItrator.next();
                    System.out.println("CM Comumns "+ cell.toString());
                    tempList.add(cell.toString());

                    }
                }
            if(row.getRowNum()==1){
                Cell  cell = cellItrator.next();
                for(int i=0;i<tempList.size();i++){
                    int temStr= (int) Math.round(cell.getNumericCellValue());
                    System.out.println("Cell Value  " + temStr);
                        if (temStr==0) {   
                            System.out.println("Null Cell");
                            cell = cellItrator.next();
                        }
                        else {
                                System.out.println("Add Comumns "+cell.getNumericCellValue());
                                cell = cellItrator.next();
                                System.out.println(cell);
                        }
                    }
                }
            }
        }
XSSFSheet sheet=book.getSheetAt(0); 迭代器itr=sheet.Iterator(); while(itr.hasNext()){ 行=itr.next(); 迭代器cellItrator=row.Iterator(); if(row.getRowNum()==0){ System.out.println(row.getRowNum()); while(cellItrator.hasNext()){ Cell=cellItrator.next(); System.out.println(“CM-Comumns”+cell.toString()); add(cell.toString()); } } if(row.getRowNum()==1){ Cell=cellItrator.next(); 对于(int i=0;您是否检查过?)??
 XSSFWorkbook book = new XSSFWorkbook(fis);
        XSSFSheet sheet = book.getSheetAt(0);
        Iterator<Row> itr = sheet.iterator();
        while(itr.hasNext()){
            Row row = itr.next();
            Iterator<Cell> cellItrator = row.iterator();
            if(row.getRowNum()==0){
                System.out.println(row.getRowNum());
                while(cellItrator.hasNext()){
                    Cell  cell = cellItrator.next();
                    System.out.println("CM Comumns "+ cell.toString());
                    tempList.add(cell.toString());

                    }
                }
            if(row.getRowNum()==1){
                Cell  cell = cellItrator.next();
                for(int i=0;i<tempList.size();i++){
                    int temStr= (int) Math.round(cell.getNumericCellValue());
                    System.out.println("Cell Value  " + temStr);
                        if (temStr==0) {   
                            System.out.println("Null Cell");
                            cell = cellItrator.next();
                        }
                        else {
                                System.out.println("Add Comumns "+cell.getNumericCellValue());
                                cell = cellItrator.next();
                                System.out.println(cell);
                        }
                    }
                }
            }
        }