工作簿跳过空白单元格

时间:2018-04-06 12:01:55

标签: java excel

我正在尝试使用Workbook读取excel文件(xls)文件,在读取行期间,如果单元格为空(cellIterator)正在跳过该单元格并将下一个值放入不同的标题。 这是完整的 java 代码,我正在使用 cellIterator

public  Vector<Vector<Cell>> ReadCSV(String filename) {
    Vector cellVectorHolder = new Vector();

    try {
        FileInputStream myInput = new FileInputStream(filename);
        LoginServlet.logger.info("Input:"+myInput);
        Workbook wb = WorkbookFactory.create(myInput);

        Sheet sheet = wb.getSheetAt(0);

        Iterator rowIter = sheet.rowIterator();

        while (rowIter.hasNext()) {
            Row myRow = (Row) rowIter.next();
            Iterator cellIter = myRow.cellIterator();
            Vector cellStoreVector = new Vector();
            while (cellIter.hasNext()) {
                Cell myCell = (Cell) cellIter.next();
                cellStoreVector.addElement(myCell);
            }
            cellVectorHolder.addElement(cellStoreVector);
        }
    } catch (Exception e) {
        e.printStackTrace();

    }
    return cellVectorHolder;
}

0 个答案:

没有答案